From 86d355aeca8470caf5e592f581e6757c051fcccd Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 25 Sep 2024 12:05:43 +0200 Subject: [PATCH] Prevent stack overflow via Array.splice when updating big content views FIX: Avoid a stack overflow that could happen when updating a line with a lot of text tokens. Issue https://github.com/codemirror/dev/issues/1445 --- src/contentview.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/contentview.ts b/src/contentview.ts index 12704da..f8f3095 100644 --- a/src/contentview.ts +++ b/src/contentview.ts @@ -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) }