Skip to content
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

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

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

Kocal
Copy link
Member

@Kocal Kocal commented Jan 30, 2025

Q A
Bug fix? yes
New feature? no
Issues Fix #...
License MIT

Following https://symfony-devs.slack.com/archives/C01FN4EQNLX/p1738238525455439

With some RUM tools that listen user interactions, some of them can JSON.stringify() their payload. But if their payload contains an HTML element with the property __component (which represents a Proxy to the LiveComponent instance), then it tries to be serialized and lead to an error by trying to call an action toJSON and trigger an XHR request to /toJSON:
image

Let's change the property assignment with Object.defineProperty(), so the property is not enumarable and so not serialized when JSON.stringify() is called:
image

cc @jwage

@carsonbot carsonbot added Bug Bug Fix Feature New Feature LiveComponent Status: Needs Review Needs to be reviewed labels Jan 30, 2025
Copy link

github-actions bot commented Jan 30, 2025

📊 Packages dist files size difference

Thanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
Please review the changes and make sure they are expected.

FileBefore (Size / Gzip)After (Size / Gzip)
LiveComponent
live_controller.js 119.92 kB / 23.37 kB 120 kB0% / 23.4 kB0%

@Kocal Kocal force-pushed the fix-live-component-proxy-attr branch from 733c5ae to 05dc157 Compare January 30, 2025 16:52
@Kocal Kocal requested review from kbond, smnandre and WebMamba January 30, 2025 17:00
@Kocal Kocal removed the Feature New Feature label Jan 30, 2025
@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Jan 31, 2025
@smnandre
Copy link
Member

Thank you @jwage for the time spent to assist / explain what happened.

@Kocal 🙇 you'be been a legend today

Copy link
Member

@kbond kbond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that was a deep dive!

@Kocal Kocal force-pushed the fix-live-component-proxy-attr branch from 05dc157 to e04f8f0 Compare January 31, 2025 08:20
@Kocal
Copy link
Member Author

Kocal commented Jan 31, 2025

(Added missing changelog)

@Kocal Kocal merged commit 9b322da into symfony:2.x Jan 31, 2025
58 of 60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix LiveComponent Status: Reviewed Has been reviewed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants