LearnNewsExamplesServices
Frontmatter
id8472
titleImplement Lazy VDOM Cloning in Component Base
stateClosed
labels
bugairefactoringcore
assigneestobiu
createdAtJan 9, 2026, 5:25 PM
updatedAtJan 9, 2026, 5:33 PM
githubUrlhttps://github.com/neomjs/neo/issues/8472
authortobiu
commentsCount1
parentIssue8469
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 9, 2026, 5:33 PM

Implement Lazy VDOM Cloning in Component Base

Closed v11.19.1 bugairefactoringcore
tobiu
tobiu commented on Jan 9, 2026, 5:25 PM

Context: Neo.core.Base assigns an instance ID early in the constructor, triggering afterSetId. In Neo.component.Base, afterSetId calls ensureStableIds, which accesses this.vdom. Since initConfig (and mergeConfig) has not yet run, this.vdom returns the prototype's _vdom reference. Modifying this object (as ensureStableIds does) causes prototype pollution, affecting all subsequent instances of the class.

Goal: Modify the vdom getter in src/component/Base.mjs to implement lazy cloning.

  1. Check if this._vdom is an own property (using Object.hasOwn).
  2. If not, clone the prototype's _vdom onto the instance immediately.
  3. Update mergeConfig to respect this lazy initialization (avoid double cloning if already done).

Verification: Add a regression test in test/playwright/unit/component/Base_PrototypePollution.spec.mjs that verifies:

  1. Creating Instance A.
  2. Creating Instance B.
  3. Ensuring Instance B's VDOM does not contain Instance A's ID.
tobiu added the bug label on Jan 9, 2026, 5:25 PM
tobiu added the ai label on Jan 9, 2026, 5:25 PM
tobiu added the refactoring label on Jan 9, 2026, 5:25 PM
tobiu added the core label on Jan 9, 2026, 5:25 PM
tobiu added parent issue #8469 on Jan 9, 2026, 5:26 PM
tobiu referenced in commit 64cdb76 - "fix: implement lazy VDOM cloning in Component.Base to prevent prototype pollution (#8472)" on Jan 9, 2026, 5:32 PM
tobiu assigned to @tobiu on Jan 9, 2026, 5:32 PM
tobiu
tobiu Jan 9, 2026, 5:32 PM

Input from Gemini 3 Pro:

✦ I have implemented the lazy VDOM cloning mechanism in src/component/Base.mjs.

Changes:

  • Modified the vdom getter to check for Object.hasOwn(this, '_vdom'). If missing, it immediately clones the prototype's _vdom to the instance.
  • This ensures that any early access to this.vdom (e.g., in afterSetId before initConfig) operates on a safe instance copy, preventing prototype pollution.

Verification:

  • Added a new regression test: test/playwright/unit/component/Base_PrototypePollution.spec.mjs.
  • The test explicitly reproduces the "early access" pattern and verifies that subsequent instances do not inherit the mutated VDOM ID.
  • Ran existing VDOM tests (AutoId.spec.mjs and button/Base.spec.mjs) to ensure no regressions. All passed.

Commit: 64cdb7694 (#8472)

tobiu closed this issue on Jan 9, 2026, 5:33 PM
tobiu cross-referenced by #8474 on Jan 9, 2026, 5:42 PM