diff --git a/reflex/app.py b/reflex/app.py index c52f0ef8a3..3f9f100916 100644 --- a/reflex/app.py +++ b/reflex/app.py @@ -726,7 +726,7 @@ def _apply_decorated_pages(self): This can move back into `compile_` when py39 support is dropped. """ # Add the @rx.page decorated pages to collect on_load events. - for render, kwargs in DECORATED_PAGES: + for render, kwargs in DECORATED_PAGES[get_config().app_name]: self.add_page(render, **kwargs) def compile_(self, export: bool = False): diff --git a/reflex/page.py b/reflex/page.py index 4ad3bb503b..1e5e8603d1 100644 --- a/reflex/page.py +++ b/reflex/page.py @@ -2,9 +2,12 @@ from __future__ import annotations -from typing import Any +from collections import defaultdict +from typing import Any, Dict, List -DECORATED_PAGES = [] +from reflex.config import get_config + +DECORATED_PAGES: Dict[str, List] = defaultdict(list) def page( @@ -55,7 +58,7 @@ def decorator(render_fn): if on_load: kwargs["on_load"] = on_load - DECORATED_PAGES.append((render_fn, kwargs)) + DECORATED_PAGES[get_config().app_name].append((render_fn, kwargs)) return render_fn @@ -69,6 +72,6 @@ def get_decorated_pages() -> list[dict]: The decorated pages. """ return sorted( - [page_data for render_fn, page_data in DECORATED_PAGES], + [page_data for _, page_data in DECORATED_PAGES[get_config().app_name]], key=lambda x: x["route"], ) diff --git a/reflex/testing.py b/reflex/testing.py index 1d1ee0068d..11b9647d81 100644 --- a/reflex/testing.py +++ b/reflex/testing.py @@ -238,13 +238,15 @@ def _initialize_app(self): # ensure config and app are reloaded when testing different app reflex.config.get_config(reload=True) # Save decorated pages before importing the test app module - before_decorated_pages = reflex.app.DECORATED_PAGES.copy() + before_decorated_pages = reflex.app.DECORATED_PAGES[self.app_name].copy() # Ensure the AppHarness test does not skip State assignment due to running via pytest os.environ.pop(reflex.constants.PYTEST_CURRENT_TEST, None) self.app_module = reflex.utils.prerequisites.get_compiled_app(reload=True) # Save the pages that were added during testing self._decorated_pages = [ - p for p in reflex.app.DECORATED_PAGES if p not in before_decorated_pages + p + for p in reflex.app.DECORATED_PAGES[self.app_name] + if p not in before_decorated_pages ] self.app_instance = self.app_module.app if isinstance(self.app_instance._state_manager, StateManagerRedis): @@ -409,7 +411,7 @@ def stop(self) -> None: # Cleanup decorated pages added during testing for page in self._decorated_pages: - reflex.app.DECORATED_PAGES.remove(page) + reflex.app.DECORATED_PAGES[self.app_name].remove(page) def __exit__(self, *excinfo) -> None: """Contextmanager protocol for `stop()`.