You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature symfony#2283 [React] Add permanent option to react_component function (smnandre)
This PR was squashed before being merged into the 2.x branch.
Discussion
----------
[React] Add `permanent` option to `react_component` function
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | yes
| Issues | Fix #...
| License | MIT
(Issue reported on a work project)
Using Turbo `data-turbo-permanent` creates race conditions that lead to the controller code failing to keep or reload the component.
In the current implementation, the Stimulus controller _unmounts_ the component then tried to _create_ it again.. which cannot be done:
> Once you call root.unmount you cannot call root.render again on the same root. Attempting to call root.render on an unmounted root will throw a “Cannot update an unmounted root” error. However, you can create a new root for the same DOM node after the previous root for that node has been unmounted.
https://react.dev/reference/react-dom/client/createRoot#root-unmount
---
~The proposed implementation uses a short delay before calling unmount. It is "morphing-library-agnostic", and will work with any Turbo-like framework, with no impact on the existing projects using UX React (except a bug fixed 😅 ).~
New implementation:
A new option `permanent` prevent the "unmount" of the component when set to true
```twig
{# This component will not be unmounted on "disconnect" #}
{{ react_component('MyComponent', props, {permanent: true}) }}
```
This allows to avoid the bug when a component is disconnected and immediately reconnected (ex with Turbo)
Commits
-------
4d60724 [React] Add `permanent` option to `react_component` function
0 commit comments