Long document stops parsing halfway

Seems to be a new bug introduced sometimes in 0.19.

Repro steps:

  • Open this page: CodeMirror Huge Doc Demo
  • Wait.
  • Scroll down and notice that parsing stopped halfway and never picks back up, even after scrolling past the stopping point.
  • Check performance snapshot and notice there’s nothing running.
  • Clicking something or typing a character revives it.

Waiting 30 seconds should also make it move forward (if the editor is focused). This is by design—the editor tries to avoid uselessly draining your battery to parse a large document if you’re not actively interacting with it. Is this a concrete issue for you, or just something you noticed?

In my case, I’m hearing that our beta testers are seeing un-parsed documents on occasions, which is being reported as a bug with the editor. One semi-consistent repro is to load a medium sized document, make a parsing-impacting change early on in the document, then scroll down to the end. Half the time the user would see the entire page completely unparsed, and it won’t get parsed until another interaction happens.

If there’s a knob somewhere that can specify parameters of this feature that would be great! I think for me, the desired granularity would be to continuously run until the content in view is fully parsed.

What language mode are you using? A stream-parser based one or a Lezer parser?

We’re still using a stream-parser based mode. I haven’t gotten time yet to rewrite our CM5 mode with the new Lezer paradigm just yet, as we’re also still using CM5 on the desktop app, so we’ll have to keep supporting/updating the CM5 mode regardless.

Spent a few hours trying to reproduce the issue and testing various cases. It seems that it happens pretty rarely when attempting to repro.

I think it only happens for specific timing situations - in my test, I always type a letter early in the document which changes the parsing context, then scroll down to the bottom. Depending on the timing, most of the time, parsing catches up as I scroll (which seems to be the intended behavior). Only in rare occasions, the parsing logic seems to be completely stopped until a blur & re-focus happens. It also doesn’t seem to happen as much when scrolling using the scroll wheel, compared to scrolling by dragging the scrollbar.

It’s probably some kind of race condition, but I’m at a loss for more details. I’ve repro’d on a ~16kb and another ~80kb document.