Commit d43ab91
committed
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 JavaScriptFile tree
32 files changed
+4463
-262
lines changed- src
- Autocomplete/assets
- dist
- src
- test
- Chartjs/assets
- dist
- src
- test
- LiveComponent
- assets
- dist
- Component
- Rendering
- src
- Component
- Rendering
- test
- Rendering
- controller
- doc
- ux.symfony.com
- src
- Controller
- Form
- Service
- data
- Twig
- templates
- components
- live_component_demo
32 files changed
+4463
-262
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
3 | 10 | | |
4 | 11 | | |
5 | 12 | | |
| |||
23 | 30 | | |
24 | 31 | | |
25 | 32 | | |
| 33 | + | |
| 34 | + | |
26 | 35 | | |
27 | 36 | | |
28 | 37 | | |
| 38 | + | |
29 | 39 | | |
30 | 40 | | |
31 | 41 | | |
32 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
33 | 49 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
| |||
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
| |||
79 | 82 | | |
80 | 83 | | |
81 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
82 | 202 | | |
83 | 203 | | |
84 | 204 | | |
| |||
103 | 223 | | |
104 | 224 | | |
105 | 225 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | 226 | | |
111 | 227 | | |
112 | 228 | | |
| |||
115 | 231 | | |
116 | 232 | | |
117 | 233 | | |
118 | | - | |
| 234 | + | |
119 | 235 | | |
120 | 236 | | |
121 | 237 | | |
122 | 238 | | |
123 | | - | |
| 239 | + | |
124 | 240 | | |
125 | 241 | | |
126 | 242 | | |
| |||
183 | 299 | | |
184 | 300 | | |
185 | 301 | | |
186 | | - | |
| 302 | + | |
| 303 | + | |
187 | 304 | | |
188 | | - | |
| 305 | + | |
| 306 | + | |
189 | 307 | | |
190 | 308 | | |
191 | 309 | | |
| |||
0 commit comments