{"record":{"id":"bcefa3f76cf531e2","repo":"reflex-dev/reflex","slug":"var-returning-rx-memo-func-name-cannot-depe-bcefa3","errorCode":null,"errorMessage":"Var-returning `@rx.memo` `{func_name}` cannot depend on embedded components, custom code, or dynamic imports. Use a component-returning `@rx.memo` instead.","messagePattern":"Var-returning `@rx\\.memo` `(.+?)` cannot depend on embedded components, custom code, or dynamic imports\\. Use a component-returning `@rx\\.memo` instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/components/memo.py","lineNumber":816,"sourceCode":"    \"\"\"\n    var_data = VarData.merge(return_expr._get_all_var_data())\n    if var_data is None:\n        return\n\n    if var_data.hooks:\n        msg = (\n            f\"Var-returning `@rx.memo` `{func_name}` cannot depend on hooks. \"\n            \"Use a component-returning `@rx.memo` instead.\"\n        )\n        raise TypeError(msg)\n\n    if var_data.components:\n        msg = (\n            f\"Var-returning `@rx.memo` `{func_name}` cannot depend on embedded \"\n            \"components, custom code, or dynamic imports. Use a component-returning \"\n            \"`@rx.memo` instead.\"\n        )\n        raise TypeError(msg)\n\n    bundled_libraries = RegistrationContext.ensure_context().bundled_libraries\n    for lib in dict(var_data.imports):\n        if not lib:\n            continue\n        if lib.startswith((\".\", \"/\", \"$/\", \"http\")):\n            continue\n        if format.format_library_name(lib) in bundled_libraries:\n            continue\n        msg = (\n            f\"Var-returning `@rx.memo` `{func_name}` cannot import `{lib}` because \"\n            \"it is not bundled. Use a component-returning `@rx.memo` instead.\"\n        )\n        raise TypeError(msg)\n\n\ndef _rest_placeholder(name: str) -> RestProp:\n    \"\"\"Create the placeholder RestProp.","sourceCodeStart":798,"sourceCodeEnd":834,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/components/memo.py#L798-L834","documentation":"A `@rx.memo` function that returns an `rx.Var` (a computed value, not a component) had its body evaluated, and the resulting Var carries component dependencies (`var_data.components`). Var-returning memos are inlined as pure expressions into the client bundle, so they cannot embed components, custom code, or dynamic imports. Reflex raises this TypeError at decoration time to prevent unsupported usage.","triggerScenarios":"Decorating a function with `@rx.memo` whose return expression builds or references an `rx.Component` (e.g. returns something derived from `rx.cond(...)`, an embedded component, or code that registers components via `rx.el`), i.e. the computed Var's VarData contains a non-empty `components` list.","commonSituations":"Developers migrating a component-returning helper to a Var-returning memo and forgetting to remove component usage inside; referencing a child component in a computed string/format expression; using `rx.match`/`rx.cond` over components inside a memo expected to return a plain value.","solutions":["Convert the memo to return an `rx.Component` (annotate the return type as `rx.Component` or return a component) so components are legal","Remove the embedded component / custom code / dynamic import from the Var-returning memo body and compute only plain values","Split the logic: keep a Var-returning memo for the value and a separate component-returning memo for rendering"],"exampleFix":"// before\n@rx.memo\ndef badge_text(count: rx.Var[int]) -> rx.Var[str]:\n    return rx.cond(count > 0, rx.badge(count), \"none\")  # component in Var memo\n\n// after\n@rx.memo\ndef badge_text(count: rx.Var[int]) -> rx.Var[str]:\n    rx.cond(count > 0, f\"{count}\", \"none\")  # values only\n\n@rx.memo\ndef badge(count: rx.Var[int]) -> rx.Component:\n    return rx.badge(count)","handlingStrategy":"validation","validationCode":"import reflex as rx\n\ndef var_memo_is_pure(fn) -> bool:\n    \"\"\"Smoke-test a Var-returning memo body for component dependencies.\"\"\"\n    try:\n        with rx.memo.Var evaluation context:  # pseudo; simply calling fn in dev is enough\n            pass\n    except TypeError:\n        return False\n    return True","typeGuard":"import reflex as rx\n\ndef returns_component(fn) -> bool:\n    import inspect, typing\n    ret = typing.get_type_hints(fn).get(\"return\")\n    if ret is None:\n        return False\n    args = typing.get_args(ret)\n    return rx.Component in args or ret is rx.Component","tryCatchPattern":"try:\n    @rx.memo\n    def value_memo(n: rx.Var[int]) -> rx.Var[int]: ...\nexcept TypeError as e:\n    if \"cannot depend on embedded components\" in str(e):\n        # fall back to a component-returning memo\n        ...","preventionTips":["Annotate memo return types explicitly (`-> rx.Var[...]` vs `-> rx.Component`) so intent is clear","Keep Var-returning memo bodies free of rx.cond over components, embedded components, and dynamic imports","Run the app once in dev after adding a memo — these errors raise at import/decoration time"],"tags":["reflex","rx-memo","typeerror","validation","components"],"backgroundTag":"decorator-validation-failed","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}