Skip to content

Commit 209e96d

Browse files
committed
refactor: Use ensureStableIds in Button.Base to prevent prototype mutation (#8471)
1 parent 9c86abf commit 209e96d

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

src/button/Base.mjs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,13 @@ class Button extends Component {
229229
/**
230230
* Workaround fix for: https://github.com/neomjs/neo/issues/6659
231231
* Todo: inspect this further (we do not want to add fixed ids for all child nodes)
232-
* Triggered after the id config got changed
233-
* @param {String} value The new value of the id config.
234-
* @param {String} oldValue The old value of the id config.
232+
* Ensures that the root VDOM node and its wrapper (if any) have stable, unique IDs
233+
* derived from the component instance ID.
235234
* @protected
236235
*/
237-
afterSetId(value, oldValue) {
238-
super.afterSetId(value, oldValue);
239-
240-
this.textNode.id = value + '__text'
236+
ensureStableIds() {
237+
super.ensureStableIds();
238+
this.textNode.id = this.id + '__text'
241239
}
242240

243241
/**

test/playwright/unit/button/Base.spec.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,27 @@ test.describe('Neo.button.Base VDOM (Node.js)', () => {
117117

118118
button.destroy();
119119
});
120+
121+
test('Prototype VDOM mutation check', async () => {
122+
// Manually clean prototype to verify the fix or demonstrate the bug
123+
// Note: We need to access the prototype from the class constructor
124+
const protoVdom = Button.prototype._vdom;
125+
if (protoVdom.cn[1].id) {
126+
delete protoVdom.cn[1].id;
127+
}
128+
129+
const button1 = Neo.create(Button, {
130+
appName,
131+
id: 'my-button-1',
132+
text: 'Button 1'
133+
});
134+
135+
// Instance should have it
136+
expect(button1.textNode.id).toBe('my-button-1__text');
137+
138+
// Prototype should NOT have it (this will fail if bug is present)
139+
expect(Button.prototype._vdom.cn[1].id).toBeUndefined();
140+
141+
button1.destroy();
142+
});
120143
});

0 commit comments

Comments
 (0)