-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: add app_wraps to VarData for Var-driven provider injection #6447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6ea1eb0
feat: add app_wraps to VarData for Var-driven provider injection
FarhanAliRaza 22e039e
refactor: reach addEvents via module-level import instead of hook hoist
FarhanAliRaza 2a1ff34
Merge remote-tracking branch 'upstream/main' into app-wrap-vardata
FarhanAliRaza d3a56a0
fix: don't memoize subtrees reactive only via no-arg event triggers
FarhanAliRaza cf202d0
fix: clear render cache on Component deepcopy to prevent dropped chil…
FarhanAliRaza ef19648
perf: reuse fetched hooks across page-hook and app-wrap collection
FarhanAliRaza beb3221
fix: mixed event/function dispatch must reach addEvents via module im…
FarhanAliRaza cfe2b90
test: fix tab indentation in postcss config fixture string
FarhanAliRaza d9398e6
perf: share state/event-loop app-wrap providers as cached singletons
FarhanAliRaza b48f28c
test: assert upload provider stays out when no upload Vars are used
FarhanAliRaza 10f08ab
Merge branch 'main' into app-wrap-vardata
FarhanAliRaza 9ac52f1
refactor: centralize app-wrap merge dedup, raise on conflicting slots
FarhanAliRaza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/reflex-base/src/reflex_base/components/state_context.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """App-wrap components mounting the state and event-loop React providers. | ||
|
|
||
| These wrap children in the ``StateProvider`` / ``EventLoopProvider`` JS | ||
| functions emitted into ``utils/context.js`` by ``compile_contexts``. They are | ||
| attached to the VarData returned by :meth:`reflex_base.vars.base.VarData.from_state` | ||
| so the compiler picks them up through the generic Var-driven app-wrap pipeline, | ||
| rather than the JS Layout template hard-coding them around every app. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from reflex_base.components.component import Component | ||
| from reflex_base.constants import Dirs | ||
| from reflex_base.constants.compiler import Hooks | ||
| from reflex_base.vars.base import VarData | ||
|
|
||
|
|
||
| class StateContextProvider(Component): | ||
| """App wrap that mounts the React state-context provider around children.""" | ||
|
|
||
| library = f"$/{Dirs.CONTEXTS_PATH}" | ||
| tag = "StateProvider" | ||
|
|
||
|
|
||
| class EventLoopContextProvider(Component): | ||
| """App wrap that mounts the websocket event-loop provider around children.""" | ||
|
|
||
| library = f"$/{Dirs.CONTEXTS_PATH}" | ||
| tag = "EventLoopProvider" | ||
|
|
||
|
|
||
| def get_events_hooks_var_data() -> VarData: | ||
| """Build the VarData attached to ``Hooks.EVENTS`` for event triggers. | ||
|
|
||
| Higher priority wraps further out, so ``StateProvider`` (100) encloses | ||
| ``EventLoopProvider`` (90) — the latter reads ``DispatchContext`` from | ||
| the former. The returned providers are fresh per call: the compiler's | ||
| ``app_wrap_components`` registry already dedupes by ``(priority, tag)``, | ||
| and caching the instances burned us via ``copy.deepcopy`` carrying | ||
| ``_cached_render_result`` from a prior compile run forward into the next. | ||
|
|
||
| Returns: | ||
| A new VarData carrying both providers as app_wraps. | ||
| """ | ||
| return VarData( | ||
| position=Hooks.HookPosition.INTERNAL, | ||
| app_wraps=( | ||
| (100, StateContextProvider.create()), | ||
| (90, EventLoopContextProvider.create()), | ||
| ), | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.