From 65930138eb593ba3069a0b7033757f63b4e530b7 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Mon, 10 Feb 2025 15:07:49 -0800 Subject: [PATCH] fix dynamic imports app --- reflex/app.py | 21 ++++++++++++--------- reflex/compiler/compiler.py | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/reflex/app.py b/reflex/app.py index 665e37faa..281727b3f 100644 --- a/reflex/app.py +++ b/reflex/app.py @@ -178,7 +178,8 @@ def extra_overlay_function() -> Optional[Component]: module, _, function_name = extra_config.rpartition(".") try: module = __import__(module) - config_overlay = getattr(module, function_name)() + config_overlay = Fragment.create(getattr(module, function_name)()) + config_overlay._get_all_imports() except Exception as e: from reflex.compiler.utils import save_error @@ -290,7 +291,9 @@ class App(MiddlewareMixin, LifespanMixin): app_wraps: Dict[tuple[int, str], Callable[[bool], Optional[Component]]] = ( dataclasses.field( default_factory=lambda: { - (55, "ErrorBoundary"): lambda stateful: default_error_boundary(), + (55, "ErrorBoundary"): ( + lambda stateful: default_error_boundary() if stateful else None + ), (5, "Overlay"): ( lambda stateful: default_overlay_component() if stateful else None ), @@ -1073,6 +1076,13 @@ class App(MiddlewareMixin, LifespanMixin): # Add the custom components from the page to the set. custom_components |= component._get_all_custom_components() + # Add the app wraps to the app. + for key, app_wrap in self.app_wraps.items(): + component = app_wrap(self._state is not None) + if component is not None: + app_wrappers[key] = component + custom_components |= component._get_all_custom_components() + if self.error_boundary: console.deprecate( feature_name="App.error_boundary", @@ -1082,13 +1092,6 @@ class App(MiddlewareMixin, LifespanMixin): ) app_wrappers[(55, "ErrorBoundary")] = self.error_boundary() - # Add the app wraps to the app. - for key, app_wrap in self.app_wraps.items(): - component = app_wrap(self._state is not None) - if component is not None: - app_wrappers[key] = component - custom_components |= component._get_all_custom_components() - # Perform auto-memoization of stateful components. with console.timing("Auto-memoize StatefulComponents"): ( diff --git a/reflex/compiler/compiler.py b/reflex/compiler/compiler.py index c2a76aad3..7cd87fb71 100644 --- a/reflex/compiler/compiler.py +++ b/reflex/compiler/compiler.py @@ -78,6 +78,7 @@ def _compile_app(app_root: Component) -> str: hooks=app_root._get_all_hooks(), window_libraries=window_libraries, render=app_root.render(), + dynamic_imports=app_root._get_all_dynamic_imports(), )