Commit 6f8db6b
authored
feat: add app_wraps to VarData for Var-driven provider injection (#6447)
* feat: add app_wraps to VarData for Var-driven provider injection
Lets Vars declare app-level wrapper components in their VarData so the
compiler can mount providers (state context, event loop, upload, etc.)
based on what's actually used, instead of relying on hardcoded chains
or special-case logic. State/event-loop providers now ride along on
VarData.from_state and the events-hook helper, and UploadFilesProvider
is mounted when selected_files/upload_file is referenced — even without
an Upload component on the page. Layout renders the assembled chain so
AppWrap reduces to hooks + children.
* refactor: reach addEvents via module-level import instead of hook hoist
EventLoopProvider now populates a module-level addEvents in
$/utils/context, so JSX literals constructed outside the React-tree
hoist path (e.g. ErrorBoundary.onError) can dispatch events without
useContext(EventLoopContext) being lexically in scope. State and
event-loop providers ride along on event-invocation VarData.app_wraps
(and via _get_event_app_wraps) so they still mount in the app root.
connectErrors stays on useContext since it drives re-renders;
AppWrap is now a Fragment rendering the chain in its body.
* fix: don't memoize subtrees reactive only via no-arg event triggers
Per review: a no-arg handler (on_click=State.ping) surfaces only through
event_triggers and reaches addEvents via a module-level import, not a
hoisted hook. The inline callback carries no reactive data and never
drives a re-render, so wrapping it in a memo gains nothing. Drop the
event_triggers fast-path from the reactive-data check and let such
callbacks render in the page module. Handlers that reference state still
surface through the per-Var scan and memoize as before.
* fix: clear render cache on Component deepcopy to prevent dropped children
App._app_root deep-copies app-wrap components and rebinds their children
to assemble the provider chain. __copy__ already drops the render-path
caches for this reason, but copy.deepcopy preserved them, so a component
rendered during page compilation (e.g. a State/EventLoop/UploadFiles
provider injected via VarData.app_wraps) returned its stale, childless
_cached_render_result after children were appended. The page content
(children/Outlet) was silently dropped and the page rendered blank.
Add a __deepcopy__ that mirrors __copy__: the clone is for compile-time
mutation, so render caches are not carried over. Extract the shared cache
attr list to _COMPILE_CACHE_ATTRS. Regression test fails before the fix.
* perf: reuse fetched hooks across page-hook and app-wrap collection
The page collector already pulls _get_hooks_internal/_get_added_hooks for
page-hook aggregation; pass those dicts into the Var app-wrap scan instead of
re-fetching, so each component avoids a second (uncached) _get_added_hooks and
_get_event_app_wraps per compile. Event-trigger providers now surface solely
through the Var scan, dropping the event_triggers special-case in the
subclass-override app-wrap path.
* fix: mixed event/function dispatch must reach addEvents via module import
The mixed-dispatch path (_dispatch_mixed_event_var, used by
on_click=lambda: rx.cond(..., function_var, event_spec)) still emitted the
legacy hooks={Hooks.EVENTS: None} hook — const [addEvents, connectErrors]
= useContext(EventLoopContext) — but Imports.EVENTS no longer imports
EventLoopContext. The rendered component threw "ReferenceError:
EventLoopContext is not defined", crashing the page and failing the
test_event_chain_click integration tests.
Match the other dispatch sites: reach addEvents through the module-level
import and ride the state/event-loop providers on app_wraps via
get_event_app_wraps(). Drop the now-unused Hooks import. Regression test
covers the mixed-dispatch VarData.
* test: fix tab indentation in postcss config fixture string
* perf: share state/event-loop app-wrap providers as cached singletons
Construct StateProvider/EventLoopProvider once and reuse them instead of
rebuilding per state Var. This is now safe because consumers deep-copy before
rebinding children and the render-cache no longer survives deepcopy, so the
shared markers are never mutated; it lets the page-tree deepcopy and render
hash memoize them. VarData.add_state now routes through get_event_app_wraps()
for the single source of truth.
* test: assert upload provider stays out when no upload Vars are used
* refactor: centralize app-wrap merge dedup, raise on conflicting slots
Extract the per-(priority, tag) app-wrap merge rule into a shared
insert_app_wraps primitive used by both VarData.merge and the compiler's
page-wide collection, so the dedup logic lives in one place. Two
different wrappers claiming the same slot now raise instead of silently
keeping the first. Hash app_wraps as a frozenset so merge order no longer
affects VarData identity (a + b == b + a).1 parent ea8155b commit 6f8db6b
24 files changed
Lines changed: 1292 additions & 98 deletions
File tree
- news
- packages
- reflex-base
- news
- src/reflex_base
- compiler
- components
- constants
- event
- vars
- reflex-components-core
- news
- src/reflex_components_core
- base
- core
- reflex/compiler
- plugins
- tests/units
- compiler
- components
- core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 27 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
| 221 | + | |
226 | 222 | | |
227 | 223 | | |
228 | 224 | | |
| |||
373 | 369 | | |
374 | 370 | | |
375 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
376 | 390 | | |
377 | 391 | | |
378 | 392 | | |
| |||
403 | 417 | | |
404 | 418 | | |
405 | 419 | | |
406 | | - | |
| 420 | + | |
407 | 421 | | |
408 | 422 | | |
409 | 423 | | |
410 | 424 | | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
411 | 430 | | |
412 | 431 | | |
413 | | - | |
| 432 | + | |
414 | 433 | | |
415 | 434 | | |
416 | 435 | | |
| |||
Lines changed: 74 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
279 | 280 | | |
280 | 281 | | |
281 | 282 | | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
282 | 292 | | |
283 | 293 | | |
284 | 294 | | |
| |||
349 | 359 | | |
350 | 360 | | |
351 | 361 | | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
352 | 388 | | |
353 | 389 | | |
354 | 390 | | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
| 391 | + | |
362 | 392 | | |
363 | 393 | | |
364 | 394 | | |
| |||
1970 | 2000 | | |
1971 | 2001 | | |
1972 | 2002 | | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
1973 | 2009 | | |
1974 | | - | |
| 2010 | + | |
1975 | 2011 | | |
1976 | | - | |
1977 | | - | |
1978 | | - | |
1979 | | - | |
1980 | | - | |
| 2012 | + | |
1981 | 2013 | | |
1982 | 2014 | | |
1983 | 2015 | | |
| |||
2132 | 2164 | | |
2133 | 2165 | | |
2134 | 2166 | | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
2135 | 2196 | | |
2136 | 2197 | | |
2137 | 2198 | | |
| |||
Lines changed: 68 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
Lines changed: 16 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
151 | 154 | | |
152 | | - | |
153 | | - | |
| 155 | + | |
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
160 | 169 | | |
161 | 170 | | |
162 | 171 | | |
163 | 172 | | |
| 173 | + | |
| 174 | + | |
164 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
165 | 179 | | |
166 | 180 | | |
167 | 181 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
1080 | 1080 | | |
1081 | 1081 | | |
1082 | 1082 | | |
1083 | | - | |
| 1083 | + | |
1084 | 1084 | | |
1085 | 1085 | | |
1086 | 1086 | | |
1087 | 1087 | | |
1088 | 1088 | | |
1089 | 1089 | | |
1090 | | - | |
| 1090 | + | |
1091 | 1091 | | |
1092 | 1092 | | |
1093 | 1093 | | |
| |||
2098 | 2098 | | |
2099 | 2099 | | |
2100 | 2100 | | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
2101 | 2104 | | |
2102 | 2105 | | |
2103 | 2106 | | |
2104 | 2107 | | |
2105 | | - | |
| 2108 | + | |
2106 | 2109 | | |
2107 | 2110 | | |
2108 | 2111 | | |
| |||
2418 | 2421 | | |
2419 | 2422 | | |
2420 | 2423 | | |
| 2424 | + | |
| 2425 | + | |
| 2426 | + | |
2421 | 2427 | | |
2422 | 2428 | | |
2423 | 2429 | | |
2424 | 2430 | | |
2425 | | - | |
| 2431 | + | |
2426 | 2432 | | |
2427 | 2433 | | |
2428 | 2434 | | |
| |||
2463 | 2469 | | |
2464 | 2470 | | |
2465 | 2471 | | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
2466 | 2475 | | |
2467 | 2476 | | |
2468 | 2477 | | |
2469 | 2478 | | |
2470 | | - | |
| 2479 | + | |
2471 | 2480 | | |
2472 | 2481 | | |
2473 | 2482 | | |
| |||
0 commit comments