Error when page content shrinks
I'm doing a thing, but I suspect that error is only exposed by that thing directly (if that's not too obtuse).
The error is:
Uncaught TypeError: Cannot read property 'nextSibling' of undefined at nextSignificantNode (paged.polyfill.js:1121) at nodeAfter (paged.polyfill.js:626) at Layout.findEndToken (paged.polyfill.js:1707) at Page.checkUnderflowAfterResize (paged.polyfill.js:2060) at paged.polyfill.js:2032
and it happens for me when I make items on a page smaller.
How am I triggering it?
I have hyperlinks from my text in footnotes. (I've written up the why a bit here.)
renderNode I call a function that does a
fetch to a link shortener. When it resolves it swaps out that node for one that takes up less space. I can go into more detail about how I'm doing that if you like, but I don't think it matters here.
If we number the pages 1–6 from the top left, what's happening here is that the links in the footnotes on p4 are shortened and take up less space. In an ideal world, they'd reflow from p5 and fill up the space, which would probably leave enough space for the article that starts on p6 to start on p5.
Because parts of the doc that filled a page no longer do so, I suspect that something is triggered to reflow things backwards.
This error blocks further execution, so in my case nothing in
afterRendered gets excecuted. (I don't know if it's waiting for the promise to resolve, or if it's just a coincidence that it hasn't got there by the time the error happens.)
In this specific case, the reason for the problem is that the
renderNode handler isn't waiting for the promise to resolve, and it letting it resolve later. I'm sure there's a better way to handle this, but it's not really in the scope of this bug.
I think it might be related to: #207
There are two ways to fix this I guess.
- find out why things don't flow backwards
- I can fix whatever is causing the reflow so that the code isn't called
I'm mainly just writing this up so that I get karma points that I can spend on another day of riding a motorbike in Sydney without getting hit by a truck.