Skip to content

Commit

Permalink
[LiveComponent] Prevent __component property to be serialized when …
Browse files Browse the repository at this point in the history
…called `JSON.stringify()`
  • Loading branch information
Kocal committed Jan 31, 2025
1 parent ec09cdf commit e04f8f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/LiveComponent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2.23.0

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

## 2.22.0

Expand Down
5 changes: 4 additions & 1 deletion src/LiveComponent/assets/dist/live_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3059,7 +3059,10 @@ class LiveControllerDefault extends Controller {
const id = this.element.id || null;
this.component = new Component(this.element, this.nameValue, this.propsValue, this.listenersValue, id, LiveControllerDefault.backendFactory(this), new StimulusElementDriver(this));
this.proxiedComponent = proxifyComponent(this.component);
this.element.__component = this.proxiedComponent;
Object.defineProperty(this.element, '__component', {
value: this.proxiedComponent,
writable: true,
});
if (this.hasDebounceValue) {
this.component.defaultDebounce = this.debounceValue;
}
Expand Down
6 changes: 4 additions & 2 deletions src/LiveComponent/assets/src/live_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@ export default class LiveControllerDefault extends Controller<HTMLElement> imple
);
this.proxiedComponent = proxifyComponent(this.component);

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

if (this.hasDebounceValue) {
this.component.defaultDebounce = this.debounceValue;
Expand Down

0 comments on commit e04f8f0

Please sign in to comment.