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 #728 [Live] Smart Rendering! Mix/match live components with external JavaScript (weaverryan)
This PR was squashed before being merged into the 2.x branch.
Discussion
----------
[Live] Smart Rendering! Mix/match live components with external JavaScript
| Q | A
| ------------- | ---
| Bug fix? | yesish
| New feature? | yes
| Tickets | Fixes#702, Fixes#490, Fixes#515, Fixes#270, Fixes Bug H on #102, Fixes#354 Replaces #519
| License | MIT
Hi!
This fixes the biggest pain-point with LiveComponents: mixing them with custom JavaScript. Before this PR, a lot of things were difficult/weird: keeping modals open, collapsing content (#702), using JS widgets like Autocomplete or a date picker, and more. The best part? Everything works automatically with you needing to do anything.
With this PR, a new philosophy is born: **start with a live component, then mix in any "extras" you want with Stimulus controllers**.
The new "smart rendering" system isn't designed to catch everything (see the docs), but I think it will catch 95%+ of the situations. Here are 2 cool things that now work out-of-the-box:
A) ux-autocomplete + Live components works perfectly now - even if the available options completely change - the "dependent form fields" example has been updated to use autocomplete on both fields 🔥
https://user-images.githubusercontent.com/121003/224790239-3b723fa0-1eb7-4f27-bd71-a04bf32687f1.mp4
B) I added a new demo of Live Components + Autocomplete + Chartjs. What you see is done without needing to write any JavaScript:
https://user-images.githubusercontent.com/121003/224789304-ac1228a8-57eb-4797-8df0-245bd767872b.mp4
### How Does it Work?
If you care about the technical details, we leverage a `MutationObserver` to watch your component for changes made by anything *other* than live components. Those changes are "tracked". Then, during re-render, we use that info to *keep* those custom changes.
Cheers!
Commits
-------
d142431 [Live] Smart Rendering! Mix/match live components with external JavaScript
0 commit comments