From fee22857951ee89c9108639fd30c2b0d69d22644 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Tue, 25 Aug 2026 11:47:19 +0500 Subject: [PATCH] editor: cleanup comments --- .../src/extensions/virtualization/index.ts | 1 - .../extensions/virtualization/node-views.ts | 9 -------- .../virtualization/viewport-plugin.ts | 23 ------------------- 3 files changed, 33 deletions(-) diff --git a/packages/editor/src/extensions/virtualization/index.ts b/packages/editor/src/extensions/virtualization/index.ts index b353f7641..eec9f391b 100644 --- a/packages/editor/src/extensions/virtualization/index.ts +++ b/packages/editor/src/extensions/virtualization/index.ts @@ -98,7 +98,6 @@ export function installVirtualization(editor: Editor): void { string, unknown >; - // already installed on this instance if (Object.prototype.hasOwnProperty.call(manager, "nodeViews")) return; const proto = Object.getPrototypeOf(editor.extensionManager); diff --git a/packages/editor/src/extensions/virtualization/node-views.ts b/packages/editor/src/extensions/virtualization/node-views.ts index e9b2bc584..8eddbd936 100644 --- a/packages/editor/src/extensions/virtualization/node-views.ts +++ b/packages/editor/src/extensions/virtualization/node-views.ts @@ -75,11 +75,9 @@ function createPlaceholder( return { dom, - // children are never rendered contentDOM: null, update(updatedNode: ProsemirrorNode, decorations: readonly Decoration[]) { if (updatedNode.type !== node.type) return false; - // switch to the real node once it enters the viewport if (isMaterialized(decorations)) return false; node = updatedNode; dom.style.height = `${heightMap.heightFor(updatedNode)}px`; @@ -102,7 +100,6 @@ function createMaterializedDefault( ): NodeView { const spec = node.type.spec.toDOM?.(node); if (!spec) { - // leaf-like or spec-less node: fall back to an empty box const dom = document.createElement("div"); return { dom }; } @@ -117,9 +114,7 @@ function createMaterializedDefault( contentDOM, update(updatedNode: ProsemirrorNode, decorations: readonly Decoration[]) { if (updatedNode.type !== node.type) return false; - // scrolled out of view -> rebuild as a placeholder if (!isMaterialized(decorations)) return false; - // attribute/mark change -> let ProseMirror rebuild the DOM if (!node.sameMarkup(updatedNode)) return false; node = updatedNode; record(); @@ -183,12 +178,8 @@ export function withVirtualization( const topLevel = isTopLevel(view, getPos as () => number | undefined); const materialize = isMaterialized(decorations); - // Only page documents past the size threshold. Smaller notes — the - // overwhelming majority — render fully and are unaffected by any of this. const belowThreshold = view.state.doc.childCount <= thresholdBlocks; - // Nested instances (inside callouts, tables, list items) are never - // virtualized — only the outermost blocks are paged. if (!topLevel || belowThreshold) { return inner ? inner(node, view, getPos, decorations, innerDecorations) diff --git a/packages/editor/src/extensions/virtualization/viewport-plugin.ts b/packages/editor/src/extensions/virtualization/viewport-plugin.ts index bbe2171e6..f0989183e 100644 --- a/packages/editor/src/extensions/virtualization/viewport-plugin.ts +++ b/packages/editor/src/extensions/virtualization/viewport-plugin.ts @@ -72,8 +72,6 @@ export function virtualizationPlugin(): Plugin { const visible = pluginState?.visible ?? new Set(); const doc = state.doc; - // Top-level index of the selection so we can always keep the block the - // caret is in (and its neighbours) rendered. const selectionIndex = state.selection.$from.index(0); const decorations: Decoration[] = []; @@ -116,11 +114,6 @@ export function virtualizationPlugin(): Plugin { const current = virtualizationKey.getState(editorView.state)?.visible; const next = new Set(intersecting); if (current && sameSet(current, next)) return; - // This transaction only records which blocks are on-screen; it changes - // no content. It carries no steps (docChanged is false), and we mark it - // preventUpdate + addToHistory:false as belt-and-suspenders so it can - // never trigger a save, never enter the undo history, and never touch - // user data — virtualization is a pure view concern. editorView.dispatch( editorView.state.tr .setMeta(virtualizationKey, { visible: next }) @@ -149,18 +142,10 @@ export function virtualizationPlugin(): Plugin { const observed = new Set(); const ensureObserver = () => { - // 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) { - // Keep the browser's scroll anchoring ON: when an off-screen - // placeholder above the viewport materializes to its real height, the - // browser compensates scrollTop so the visible content stays put - // instead of jumping. resolved.style.overflowAnchor = "auto"; scrollParent = resolved; - // The observer's root is fixed at construction, so it must be rebuilt - // when the scroll container changes. observer?.disconnect(); observer = null; observed.clear(); @@ -168,17 +153,12 @@ export function virtualizationPlugin(): Plugin { if (!observer) { observer = new IntersectionObserver(onIntersect, { root: scrollParent, - // one viewport of overscan in each direction rootMargin: "100% 0px 100% 0px", threshold: 0 }); } }; - // Keep a single observer alive and only add/remove the blocks that - // actually changed. Disconnecting and re-observing every block on each - // materialization resets all intersection state; during a scroll that - // never converges and leaves visible blocks stuck as blank placeholders. const syncObserved = () => { ensureObserver(); if (!observer) return; @@ -209,9 +189,6 @@ export function virtualizationPlugin(): Plugin { return { update() { - // Materialize/dematerialize swaps the top-level DOM elements without - // changing the document, so re-sync whenever the child element set - // changes identity — but only the delta, not the whole observer. if (childrenChanged()) syncObserved(); }, destroy() {