Skip to content

Commit 733c5ae

Browse files
committed
[LiveComponent] Prevent __component property to be serialized when called JSON.stringify()
1 parent ec09cdf commit 733c5ae

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/LiveComponent/assets/dist/live_controller.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3059,7 +3059,10 @@ class LiveControllerDefault extends Controller {
30593059
const id = this.element.id || null;
30603060
this.component = new Component(this.element, this.nameValue, this.propsValue, this.listenersValue, id, LiveControllerDefault.backendFactory(this), new StimulusElementDriver(this));
30613061
this.proxiedComponent = proxifyComponent(this.component);
3062-
this.element.__component = this.proxiedComponent;
3062+
Object.defineProperty(this.element, '__component', {
3063+
value: this.proxiedComponent,
3064+
writable: true,
3065+
});
30633066
if (this.hasDebounceValue) {
30643067
this.component.defaultDebounce = this.debounceValue;
30653068
}

src/LiveComponent/assets/src/live_controller.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,10 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
285285
);
286286
this.proxiedComponent = proxifyComponent(this.component);
287287

288-
// @ts-ignore Adding the dynamic property
289-
this.element.__component = this.proxiedComponent;
288+
Object.defineProperty(this.element, '__component', {
289+
value: this.proxiedComponent,
290+
writable: true,
291+
})
290292

291293
if (this.hasDebounceValue) {
292294
this.component.defaultDebounce = this.debounceValue;

0 commit comments

Comments
 (0)