Skip to content

Commit

Permalink
Prevent stack overflow via Array.splice when updating big content views
Browse files Browse the repository at this point in the history
FIX: Avoid a stack overflow that could happen when updating a line with a
lot of text tokens.

Issue codemirror/dev#1445
  • Loading branch information
marijnh committed Sep 25, 2024
1 parent 79b8812 commit 86d355a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/contentview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ export abstract class ContentView {
let child = this.children[i]
if (child.parent == this && children.indexOf(child) < 0) child.destroy()
}
this.children.splice(from, to - from, ...children)
if (children.length < 250) this.children.splice(from, to - from, ...children)
else this.children = ([] as ContentView[]).concat(this.children.slice(0, from), children, this.children.slice(to))
for (let i = 0; i < children.length; i++) children[i].setParent(this)
}

Expand Down

0 comments on commit 86d355a

Please sign in to comment.