Repository navigation
Description
Describe the bug
A component decorated with @rx.memo compiles its body into a separate JS module, and the call site is represented in the page tree only by a generated MemoComponent wrapper. The wrapper's body subtree is therefore invisible to every app-wrap collector, so providers that components request via app wraps never reach the app root.
The only app wraps that survive today are the ones declared as a static _get_app_wrap_components on the root class of the memo body, which _get_memo_component_class copies onto the wrapper class:
Everything else is dropped:
- Nested children —
_get_app_wrap_componentsdeclared by any descendant of the memo body's root.rx.memo(lambda: rx.box(NeedsProvider()))loses the provider thatrx.memo(lambda: NeedsProvider())keeps. VarData.app_wraps— providers requested through var data rather than a class method, e.g.UploadFilesProviderforrx.upload. These are dropped at any depth in the body, including the root.
Case 2 also hits components whose create() returns a wrapper element: rx.data_editor returns a Div around the grid, so type(body_component) is Div and its DataEditorPortal app wrap is lost even when the data editor is the memo's root.
This isn't specific to any one component — it affects anything that requests an app wrap, including third-party and reflex-enterprise components (the drag-and-drop provider being the case that surfaced it).
To Reproduce
import reflex as rx
@rx.memo
def uploader() -> rx.Component:
return rx.box(rx.upload(rx.text("Drop a file"), id="up"))
def index() -> rx.Component:
return rx.box(uploader())
app = rx.App()
app.add_page(index)Compile and inspect .web/pages/_app.js: UploadFilesProvider is absent from the app-wrap chain, so useContext(UploadFilesContext) inside the memo body resolves to the default value and file selection silently does nothing. Inlining the same rx.upload(...) into index() (no @rx.memo) emits the provider correctly.
The same goes for a class-declared app wrap nested in a memo body:
class Probe(rx.Component):
library = "app-wrap-probe"
tag = "Probe"
@staticmethod
def _get_app_wrap_components() -> dict[tuple[int, str], rx.Component]:
return {(60, "ProbeProvider"): rx.text("probe-provider")}
@rx.memo
def nested() -> rx.Component:
return rx.box(Probe.create()) # ProbeProvider dropped
@rx.memo
def root() -> rx.Component:
return Probe.create() # ProbeProvider keptExpected behavior
A memo wrapper should be a transparent substitute for the subtree it stands in for: every app wrap the body requires — whether declared by the root or any descendant, and whether declared as a class method or through VarData.app_wraps — should reach the app root, exactly as it would if the same subtree were inlined into the page.
Specifics
- Reflex Version:
main(as of v0.9.11a2) - Python Version: 3.12
- OS: Linux
Additional context
The analogous case inside the compiler is already handled: MemoizeStatefulPlugin seals snapshot-boundary subtrees from the page walker and calls collect_var_app_wraps_in_subtree on them before sealing, so their VarData.app_wraps still land in the page registry. User-authored @rx.memo bodies never enter the page tree at all, so nothing does the equivalent for them.
Note there are two collection surfaces that both need to see these wraps: the compiler plugin walk (DefaultCollectorPlugin) for pages, and Component._get_all_app_wrap_components, which App._app_root uses to expand the app-wrap chain itself (that chain contains memo components, e.g. the toaster provider and the sticky badge).
Activity
linear-code commentedon Sep 16, 2026
ENG-12494
Collect app wraps from the whole @rx.memo body (reflex-dev#7176)