LearnNewsExamplesServices
Frontmatter
id8471
titleRefactor afterSetId in src/button/Base.mjs
stateClosed
labels
airefactoringcore
assigneestobiu
createdAtJan 9, 2026, 4:51 PM
updatedAtJan 9, 2026, 5:09 PM
githubUrlhttps://github.com/neomjs/neo/issues/8471
authortobiu
commentsCount1
parentIssue8469
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 9, 2026, 5:09 PM

Refactor afterSetId in src/button/Base.mjs

Closed v11.19.1 airefactoringcore
tobiu
tobiu commented on Jan 9, 2026, 4:51 PM

The current implementation of afterSetId in src/button/Base.mjs mutates the class prototype's _vdom when called during the construction phase (before initConfig clones the VDOM).

Current Code:

afterSetId(value, oldValue) {
    super.afterSetId(value, oldValue);
    this.textNode.id = value + '__text';
}

Proposed Change:

  1. Move the textNode.id assignment to an override of ensureStableIds().
  2. ensureStableIds() is called by Component.Base#mergeConfig after _vdom has been cloned for the instance, ensuring safety.
  3. Remove the manual assignment from afterSetId (or make it conditional, but Component.Base handles ensureStableIds on ID change if configs applied, so overriding ensureStableIds handles both init and update cases).

Goals:

  • Eliminate prototype mutation.
  • Ensure textNode IDs are stable and unique per instance.
  • Add unit tests to verify the fix and prevent regression.
tobiu added the ai label on Jan 9, 2026, 4:51 PM
tobiu added the refactoring label on Jan 9, 2026, 4:51 PM
tobiu added the core label on Jan 9, 2026, 4:51 PM
tobiu referenced in commit 209e96d - "refactor: Use ensureStableIds in Button.Base to prevent prototype mutation (#8471)" on Jan 9, 2026, 5:07 PM
tobiu assigned to @tobiu on Jan 9, 2026, 5:07 PM
tobiu
tobiu Jan 9, 2026, 5:07 PM

Input from Gemini 3 Pro:

✦ Refactored src/button/Base.mjs to use ensureStableIds instead of afterSetId. This prevents _vdom prototype mutation by ensuring the ID injection happens during the mergeConfig phase where a fresh instance clone is guaranteed.

Verified with a new unit test in test/playwright/unit/button/Base.spec.mjs.

tobiu added parent issue #8469 on Jan 9, 2026, 5:09 PM
tobiu closed this issue on Jan 9, 2026, 5:09 PM
tobiu cross-referenced by #8469 on Jan 9, 2026, 5:09 PM