diff --git a/packages/editor/src/extensions/virtualization/viewport-plugin.ts b/packages/editor/src/extensions/virtualization/viewport-plugin.ts index 944d29023..190f4f76d 100644 --- a/packages/editor/src/extensions/virtualization/viewport-plugin.ts +++ b/packages/editor/src/extensions/virtualization/viewport-plugin.ts @@ -109,9 +109,7 @@ export function virtualizationPlugin(): Plugin { let observer: IntersectionObserver | null = null; let frame = 0; const intersecting = new Set(); - - const scrollParent = findScrollParent(editorView.dom); - if (scrollParent) scrollParent.style.overflowAnchor = "none"; + let scrollParent: HTMLElement | null = null; const flush = () => { frame = 0; @@ -153,6 +151,13 @@ export function virtualizationPlugin(): Plugin { const observe = () => { observer?.disconnect(); + // Resolve the scroll container lazily: at view-init the document may be + // empty (no overflow yet), so it must be re-resolved once content grows. + const resolved = findScrollParent(editorView.dom); + if (resolved && resolved !== scrollParent) { + resolved.style.overflowAnchor = "none"; + scrollParent = resolved; + } observer = new IntersectionObserver(onIntersect, { root: scrollParent, // one viewport of overscan in each direction