Skip to content

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

Merged
Kocal merged 1 commit into
symfony:2.xfrom
Kocal:fix-live-component-proxy-attr
Jan 31, 2025
Merged

[LiveComponent] Prevent __component property to be serialized when called JSON.stringify()#2537
Kocal merged 1 commit into
symfony:2.xfrom
Kocal:fix-live-component-proxy-attr

Conversation

@Kocal

@Kocal Kocal commented Jan 30, 2025

Copy link
Copy Markdown
Member
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
@github-actions

github-actions Bot commented Jan 30, 2025

Copy link
Copy Markdown
Contributor

📊 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 WebMamba, kbond and smnandre 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
Copy Markdown
Member

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

@Kocal 🙇 you'be been a legend today

@kbond kbond left a comment

Copy link
Copy Markdown
Member

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

Kocal commented Jan 31, 2025

Copy link
Copy Markdown
Member Author

(Added missing changelog)

@Kocal Kocal merged commit 9b322da into symfony:2.x Jan 31, 2025
@Kocal Kocal deleted the fix-live-component-proxy-attr branch April 17, 2025 13:51
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