Regression #1717
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I've created a minimal test case that shows what I believe is a CodeMirror View bug which appeared after v6.38.8 (the big rewrite). The result, copied from the JavaScript console:
The repro has two adjacent block-replace decorations,
[0,1]and[1,2], over the doc"\n\n". On the initial render everything is fine. TheupdateDocBlockdispatch changes only the first widget's contents, so CodeMirror does an incremental rebuild of just the changed decoration range[0,1]and preserves the rest. This update produces the error.To build the attached files:
esbuild src/bug.html src/CodeChatEditor.mts src/css/CodeChatEditor.css --bundle --outdir=./static/bundled --sourcemap --format=esm --loader:.html=copy. From the output ofstatic/bundled, runnpx http-server .then openhttp://127.0.0.1:8080/bug.html.Here's Claude's analysis:
Root cause
The error is a regression in
@codemirror/view6.39+ (the upgrade~6.38.8→^6.43.1in commita6e4abe). It's a bug in the new tile-based content-view rebuilder, not a misuse in the CodeChat code — the decoration set is valid.What happens
The repro has two adjacent block-replace decorations,
[0,1]and[1,2], over the doc"\n\n". On the initial render everything is fine. TheupdateDocBlockdispatch changes only the first widget's contents, so CodeMirror does an incremental rebuild of just the changed decoration range[0,1]and preserves the rest.Instrumenting CodeMirror's rebuilder captured the exact sequence:
When
emit(0,1)runsRangeSet.spansover the changed range, the span iterator fires thepointcallback a second time for the adjacent block decoration[1,2], reporting it as a zero-length point (from==to==1) because its start side sits exactly on the right boundary of the emitted range.emitbuilds a block-widget tile withlength = to - from = 0.The resulting tile tree is corrupted:
The second block widget loses its length, so the tile tree's cumulative length stops at 1. Nothing covers document position 2, so
coordsAtPos(2)→docView.coordsAt(2)→DocTile.resolveBlock(2)finds no tile and throwsError: No tile at position 2(index.js:1929).Trigger conditions (all required)
updateDocBlockedit to the first block).coordsAtPosat the position past the second block, which now has no tile.I don't think that pile of AI-generated code can really be called a minimal reproduction (I got the actual reproduction down to 30 lines), but sure it does demonstrate the bug. Attached patch should help.
Thanks for your quick work on this. I really appreciate it!