Skip to content

Commit e04f8f0

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

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/LiveComponent/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 2.23.0
44

55
- Allow configuring the secret used to compute fingerprints and checksums.
6+
- Prevent `__component` property to be serialized when called `JSON.stringify()`
67

78
## 2.22.0
89

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)