LearnNewsExamplesServices
Frontmatter
id8138
titleSupport saveScrollPosition in DomApiRenderer
stateClosed
labels
enhancementaicore
assigneestobiu
createdAtDec 17, 2025, 3:19 PM
updatedAtDec 19, 2025, 10:56 AM
githubUrlhttps://github.com/neomjs/neo/issues/8138
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtDec 19, 2025, 10:56 AM

Support saveScrollPosition in DomApiRenderer

Closed v11.17.0 enhancementaicore
tobiu
tobiu commented on Dec 17, 2025, 3:19 PM

Context

Ticket #8137 introduced scrollTop and scrollLeft as top-level properties on Neo.vdom.VNode to enable preserving scroll state. These properties are currently applied in Neo.main.DeltaUpdates for the updateNode action.

Problem

The insertNode action, which utilizes Neo.main.render.DomApiRenderer when Neo.config.useDomApiRenderer is true, does not currently respect these properties. As a result, when a component is re-mounted (e.g. moved in the DOM or restored from a cached state), its previous scroll position is lost.

Goal

Update Neo.main.render.DomApiRenderer to check for and apply scrollTop and scrollLeft properties from the vnode to the created DOM element.

Implementation Details

  • Modify src/main/render/DomApiRenderer.mjs:
    • In createDomTree, after creating the DOM element, check if vnode.scrollTop or vnode.scrollLeft are present.
    • If so, apply them to the domNode.
tobiu added the enhancement label on Dec 17, 2025, 3:19 PM
tobiu added the ai label on Dec 17, 2025, 3:19 PM
tobiu added the core label on Dec 17, 2025, 3:19 PM
tobiu assigned to @tobiu on Dec 17, 2025, 3:20 PM
tobiu
tobiu Dec 17, 2025, 3:39 PM

Input from Gemini 2.5:

✦ I have implemented the requested changes in src/main/render/DomApiRenderer.mjs.

Key Implementation Detail: I introduced a Post-Mount Queue pattern. Standard browser behavior prevents setting scrollTop or scrollLeft on detached DOM nodes (nodes not yet inserted into the document) because they lack a layout box and overflow context.

To solve this, the createDomTree method now:

  1. Collects any nodes with scrollTop or scrollLeft properties into a postMountUpdates queue during the recursive build phase.
  2. Inserts the fully built tree into the live DOM.
  3. Immediately iterates through the queue to apply the scroll values now that the nodes have a valid rendering context.

This ensures that scroll positions are correctly restored when components are re-mounted or moved.

tobiu referenced in commit bae9034 - "feat: Support saveScrollPosition in DomApiRenderer #8138" on Dec 17, 2025, 3:48 PM
tobiu cross-referenced by #8139 on Dec 17, 2025, 3:55 PM
tobiu closed this issue on Dec 19, 2025, 10:56 AM