Commit 9b322da
committed
bug #2537 [LiveComponent] Prevent
This PR was merged into the 2.x branch.
Discussion
----------
[LiveComponent] Prevent `__component` property to be serialized when called `JSON.stringify()`
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License | MIT
<!--
Replace this notice by a description of your feature/bugfix.
This will help reviewers and should be a good start for the documentation.
Additionally (see https://symfony.com/releases):
- Always add tests and ensure they pass.
- For new features, provide some code snippets to help understand usage.
- Features and deprecations must be submitted against branch main.
- Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
- Never break backward compatibility (see https://symfony.com/bc).
-->
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`:

Let's change the property assignment with `Object.defineProperty()`, so the property is not enumarable and so not serialized when `JSON.stringify()` is called:
<img width="648" alt="image" src="https://github.com/user-attachments/assets/dc18c06b-0793-424c-b561-b72647ec4d93" />
cc `@jwage`
Commits
-------
e04f8f0 [LiveComponent] Prevent `__component` property to be serialized when called `JSON.stringify()`__component property to be serialized when called JSON.stringify() (Kocal)File tree
3 files changed
+9
-3
lines changed- src/LiveComponent
- assets
- dist
- src
3 files changed
+9
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3059 | 3059 | | |
3060 | 3060 | | |
3061 | 3061 | | |
3062 | | - | |
| 3062 | + | |
| 3063 | + | |
| 3064 | + | |
| 3065 | + | |
3063 | 3066 | | |
3064 | 3067 | | |
3065 | 3068 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
289 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
290 | 292 | | |
291 | 293 | | |
292 | 294 | | |
| |||
0 commit comments