Skip to content

@rx.memo components don't pick up app wraps from their body, except the root class's static ones #7174

Closed

Description

@masenf

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:

https://github.com/reflex-dev/reflex/blob/main/packages/reflex-base/src/reflex_base/components/memo.py#L472-L479

Everything else is dropped:

  1. Nested children — _get_app_wrap_components declared by any descendant of the memo body's root. rx.memo(lambda: rx.box(NeedsProvider())) loses the provider that rx.memo(lambda: NeedsProvider()) keeps.
  2. VarData.app_wraps — providers requested through var data rather than a class method, e.g. UploadFilesProvider for rx.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 kept

Expected 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

  1. added
    bug
    on Sep 16, 2026
  2. linear-code commented on Sep 16, 2026

    @linear-code
  3. added a commit that references this issue on Sep 17, 2026
    ae17496
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions