Skip to content

[LiveComponent] Prevent __component property to be serialized when called JSON.stringify() #2537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/LiveComponent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

5 changes: 4 additions & 1 deletion src/LiveComponent/assets/dist/live_controller.js
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 4 additions & 2 deletions src/LiveComponent/assets/src/live_controller.ts
Original file line number Diff line number Diff line change
@@ -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;