Skip to content

Commit 4ffb314

Browse files
committed
Don't reassign widget object lengths during display updates
Since they may still be referenced by the tile pointer FIX: Fix a data structure corruption that could cause crashes during viewport changes. Closes codemirror/dev#1652
1 parent ad4fc89 commit 4ffb314

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/buildtile.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,13 @@ class TileCache {
327327
: tile.widget.constructor == widget.constructor && widget.updateDOM(tile.dom, this.view))) {
328328
widgets.splice(i, 1)
329329
if (i < this.index[0]) this.index[0]--
330-
this.reused.set(tile, Reused.Full)
331-
tile.length = length
332-
tile.flags = (tile.flags & ~(TileFlag.Widget | TileFlag.BreakAfter)) | flags
333-
return tile
330+
if (tile.length == length && (tile.flags & (TileFlag.Widget | TileFlag.BreakAfter)) == flags) {
331+
this.reused.set(tile, Reused.Full)
332+
return tile
333+
} else {
334+
this.reused.set(tile, Reused.DOM)
335+
return new WidgetTile(tile.dom, length, widget, (tile.flags & ~(TileFlag.Widget | TileFlag.BreakAfter)) | flags)
336+
}
334337
}
335338
}
336339
}

0 commit comments

Comments
 (0)