-
-
Notifications
You must be signed in to change notification settings - Fork 447
Description
Describe the issue
I am running into the same issue as described in both #1588 and #952: a codemirror that is hidden initially makes Firefox throw this:
Uncaught (in promise) TypeError: can't access property "length", string is undefined
lineInner http://localhost:8000/node_modules/@codemirror/state/dist/index.js:144
lineAt http://localhost:8000/node_modules/@codemirror/state/dist/index.js:13
.
In Firefox the DocView#measureTextSize() method is returning a charWidth of 0. which is later thrown into this: Math.max(5, contentWidth / charWidth), where contentWidth is a some changing number. so contentWidth / 0 => Infinity => larger than 5, so Infinity is passed into Oracle#refresh, setting a lineLength of Infinity. Later on heightForLine is called, doing let lines = 1 + Math.max(0, Math.ceil((length - this.lineLength) / Math.max(1, this.lineLength - 5)));.
Unwrapping we get this: 1 + Math.max(0, Math.ceil((length - Infinity) / Math.max(1, Infinity))), so -Infinity / Infinity => NaN. So heightForLine is NaN.
This results in calling HeightMap#setHeight() with NaN. Causing later to throw.
I am on the latest version of @codemirror/view, and the changes from codemirror/view@014076a are definitely there.
Frustratingly, when I am on a breakpoint inside callback given to the this.view.ignore function inside measureTextSize and I call clientRectsFor(dummy.firstChild)[0].width, It's a sensible amount, like 260.1000061035156 . A true heisenbug.
I am trying to make a more minimal repro, but this seems to be very timing-related. Also not triggering all the time. The only consistency I am seeing is that if the fallback computation for the rect is hitting in measureTextSize, we will always error out later. Funnily enough, measureTextSize returns a lineHeight that makes total sense (22.4 in my case), and the textHeight is also fine. It's just charWidth that is wrong at 0.
In our case the codemirror is wrapped in a details element. The codemirror mounting element is inserted into the DOM at a later point: when our own webcomponent inserts it on connectedCallback. If I make sure the details is open when loading the page, I can no longer repro the bug.
I would propose to make this a bit more forgiving by translating the 0 in charWidth to something sensible.
I am trying to make a repro, but that's proving to be really hard.
Browser and platform
Firefox 145.0.2
Reproduction link
No response