evaluate page regardless
This commit is contained in:
parent
5adc10691c
commit
a6c7f5241d
@ -176,7 +176,7 @@ class OverlayFragment(Fragment):
|
|||||||
@dataclasses.dataclass(
|
@dataclasses.dataclass(
|
||||||
frozen=True,
|
frozen=True,
|
||||||
)
|
)
|
||||||
class UncompiledPage:
|
class UnevaluatedPage:
|
||||||
"""An uncompiled page."""
|
"""An uncompiled page."""
|
||||||
|
|
||||||
component: Component | ComponentCallable
|
component: Component | ComponentCallable
|
||||||
@ -238,11 +238,8 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
# Attributes to add to the html root tag of every page.
|
# Attributes to add to the html root tag of every page.
|
||||||
html_custom_attrs: Optional[Dict[str, str]] = None
|
html_custom_attrs: Optional[Dict[str, str]] = None
|
||||||
|
|
||||||
# A map from a route to an uncompiled page. PRIVATE.
|
# A map from a route to an unevaluated page. PRIVATE.
|
||||||
uncompiled_pages: Dict[str, UncompiledPage] = {}
|
unevaluated_pages: Dict[str, UnevaluatedPage] = {}
|
||||||
|
|
||||||
# A map from a route to an uncompiled page. PRIVATE.
|
|
||||||
uncompiled_pages: Dict[str, UncompiledPage] = {}
|
|
||||||
|
|
||||||
# A map from a page route to the component to render. Users should use `add_page`. PRIVATE.
|
# A map from a page route to the component to render. Users should use `add_page`. PRIVATE.
|
||||||
pages: Dict[str, Component] = {}
|
pages: Dict[str, Component] = {}
|
||||||
@ -517,13 +514,13 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
# Check if the route given is valid
|
# Check if the route given is valid
|
||||||
verify_route_validity(route)
|
verify_route_validity(route)
|
||||||
|
|
||||||
if route in self.uncompiled_pages and os.getenv(constants.RELOAD_CONFIG):
|
if route in self.unevaluated_pages and os.getenv(constants.RELOAD_CONFIG):
|
||||||
# when the app is reloaded(typically for app harness tests), we should maintain
|
# when the app is reloaded(typically for app harness tests), we should maintain
|
||||||
# the latest render function of a route.This applies typically to decorated pages
|
# the latest render function of a route.This applies typically to decorated pages
|
||||||
# since they are only added when app._compile is called.
|
# since they are only added when app._compile is called.
|
||||||
self.uncompiled_pages.pop(route)
|
self.unevaluated_pages.pop(route)
|
||||||
|
|
||||||
if route in self.uncompiled_pages:
|
if route in self.unevaluated_pages:
|
||||||
route_name = (
|
route_name = (
|
||||||
f"`{route}` or `/`"
|
f"`{route}` or `/`"
|
||||||
if route == constants.PageNames.INDEX_ROUTE
|
if route == constants.PageNames.INDEX_ROUTE
|
||||||
@ -544,7 +541,7 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
on_load if isinstance(on_load, list) else [on_load]
|
on_load if isinstance(on_load, list) else [on_load]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.uncompiled_pages[route] = UncompiledPage(
|
self.unevaluated_pages[route] = UnevaluatedPage(
|
||||||
component=component,
|
component=component,
|
||||||
route=route,
|
route=route,
|
||||||
title=title or constants.DefaultPage.TITLE,
|
title=title or constants.DefaultPage.TITLE,
|
||||||
@ -560,8 +557,8 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
Args:
|
Args:
|
||||||
route: The route of the page to compile.
|
route: The route of the page to compile.
|
||||||
"""
|
"""
|
||||||
component = compiler.compile_uncompiled_page_helper(
|
component = compiler.compile_unevaluated_page(
|
||||||
route, self.uncompiled_pages[route]
|
route, self.unevaluated_pages[route]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add the page.
|
# Add the page.
|
||||||
@ -842,7 +839,7 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
"""
|
"""
|
||||||
from reflex.utils.exceptions import ReflexRuntimeError
|
from reflex.utils.exceptions import ReflexRuntimeError
|
||||||
|
|
||||||
print("Compiling the app...")
|
self.pages = {}
|
||||||
|
|
||||||
self._enable_state()
|
self._enable_state()
|
||||||
|
|
||||||
@ -850,17 +847,16 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
return str(datetime.now().time()).split(".")[0]
|
return str(datetime.now().time()).split(".")[0]
|
||||||
|
|
||||||
# Render a default 404 page if the user didn't supply one
|
# Render a default 404 page if the user didn't supply one
|
||||||
if constants.Page404.SLUG not in self.uncompiled_pages:
|
if constants.Page404.SLUG not in self.unevaluated_pages:
|
||||||
self.add_custom_404_page()
|
self.add_custom_404_page()
|
||||||
|
|
||||||
# Add the optional endpoints (_upload)
|
# Add the optional endpoints (_upload)
|
||||||
self._add_optional_endpoints()
|
self._add_optional_endpoints()
|
||||||
|
|
||||||
if not self._should_compile():
|
for route in self.unevaluated_pages:
|
||||||
for route in self.uncompiled_pages:
|
|
||||||
if route in self.pages:
|
|
||||||
continue
|
|
||||||
self._compile_page(route)
|
self._compile_page(route)
|
||||||
|
|
||||||
|
if not self._should_compile():
|
||||||
return
|
return
|
||||||
|
|
||||||
self._validate_var_dependencies()
|
self._validate_var_dependencies()
|
||||||
@ -880,7 +876,7 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
progress.start()
|
progress.start()
|
||||||
task = progress.add_task(
|
task = progress.add_task(
|
||||||
f"[{get_compilation_time()}] Compiling:",
|
f"[{get_compilation_time()}] Compiling:",
|
||||||
total=len(self.uncompiled_pages)
|
total=len(self.unevaluated_pages)
|
||||||
+ fixed_pages_within_executor
|
+ fixed_pages_within_executor
|
||||||
+ adhoc_steps_without_executor,
|
+ adhoc_steps_without_executor,
|
||||||
)
|
)
|
||||||
@ -933,9 +929,6 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
platform.system() in ("Linux", "Darwin")
|
platform.system() in ("Linux", "Darwin")
|
||||||
and os.environ.get("REFLEX_COMPILE_PROCESSES") is not None
|
and os.environ.get("REFLEX_COMPILE_PROCESSES") is not None
|
||||||
):
|
):
|
||||||
for route in self.uncompiled_pages:
|
|
||||||
self._compile_page(route)
|
|
||||||
|
|
||||||
executor = concurrent.futures.ProcessPoolExecutor(
|
executor = concurrent.futures.ProcessPoolExecutor(
|
||||||
max_workers=int(os.environ.get("REFLEX_COMPILE_PROCESSES", 0)) or None,
|
max_workers=int(os.environ.get("REFLEX_COMPILE_PROCESSES", 0)) or None,
|
||||||
mp_context=multiprocessing.get_context("fork"),
|
mp_context=multiprocessing.get_context("fork"),
|
||||||
@ -950,7 +943,7 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
|
|
||||||
ExecutorSafeFunctions.COMPONENTS[route] = component
|
ExecutorSafeFunctions.COMPONENTS[route] = component
|
||||||
|
|
||||||
for route, page in self.uncompiled_pages.items():
|
for route, page in self.unevaluated_pages.items():
|
||||||
if route in self.pages:
|
if route in self.pages:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -970,12 +963,12 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
result_futures.append(f)
|
result_futures.append(f)
|
||||||
|
|
||||||
# Compile all page components.
|
# Compile all page components.
|
||||||
for route in self.uncompiled_pages:
|
for route in self.unevaluated_pages:
|
||||||
if route in self.pages:
|
if route in self.pages:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
f = executor.submit(
|
f = executor.submit(
|
||||||
ExecutorSafeFunctions.compile_uncompiled_page,
|
ExecutorSafeFunctions.compile_unevaluated_page,
|
||||||
route,
|
route,
|
||||||
self.state,
|
self.state,
|
||||||
self.style,
|
self.style,
|
||||||
|
@ -514,10 +514,10 @@ def purge_web_pages_dir():
|
|||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from reflex.app import UncompiledPage
|
from reflex.app import UnevaluatedPage
|
||||||
|
|
||||||
|
|
||||||
def compile_uncompiled_page_helper(route: str, page: UncompiledPage) -> Component:
|
def compile_unevaluated_page(route: str, page: UnevaluatedPage) -> Component:
|
||||||
"""Compiles an uncompiled page into a component and adds meta information.
|
"""Compiles an uncompiled page into a component and adds meta information.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -588,7 +588,7 @@ class ExecutorSafeFunctions:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
COMPONENTS: Dict[str, Component] = {}
|
COMPONENTS: Dict[str, Component] = {}
|
||||||
UNCOMPILED_PAGES: Dict[str, UncompiledPage] = {}
|
UNCOMPILED_PAGES: Dict[str, UnevaluatedPage] = {}
|
||||||
STATE: Optional[Type[BaseState]] = None
|
STATE: Optional[Type[BaseState]] = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -606,18 +606,18 @@ class ExecutorSafeFunctions:
|
|||||||
return compile_page(route, cls.COMPONENTS[route], cls.STATE)
|
return compile_page(route, cls.COMPONENTS[route], cls.STATE)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def compile_uncompiled_page(
|
def compile_unevaluated_page(
|
||||||
cls,
|
cls,
|
||||||
route: str,
|
route: str,
|
||||||
state: Type[BaseState],
|
state: Type[BaseState],
|
||||||
style: ComponentStyle,
|
style: ComponentStyle,
|
||||||
theme: Component,
|
theme: Component,
|
||||||
) -> tuple[str, Component, tuple[str, str]]:
|
) -> tuple[str, Component, tuple[str, str]]:
|
||||||
"""Compile an uncompiled page.
|
"""Compile an unevaluated page.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
route: The route of the page to compile.
|
route: The route of the page to compile.
|
||||||
page: The uncompiled page.
|
page: The unevaluated page.
|
||||||
state: The app state.
|
state: The app state.
|
||||||
style: The style of the page.
|
style: The style of the page.
|
||||||
theme: The theme of the page.
|
theme: The theme of the page.
|
||||||
@ -625,7 +625,7 @@ class ExecutorSafeFunctions:
|
|||||||
Returns:
|
Returns:
|
||||||
The route, compiled component, and compiled page.
|
The route, compiled component, and compiled page.
|
||||||
"""
|
"""
|
||||||
component = compile_uncompiled_page_helper(route, cls.UNCOMPILED_PAGES[route])
|
component = compile_unevaluated_page(route, cls.UNCOMPILED_PAGES[route])
|
||||||
component = component if isinstance(component, Component) else component()
|
component = component if isinstance(component, Component) else component()
|
||||||
component._add_style_recursive(style, theme)
|
component._add_style_recursive(style, theme)
|
||||||
return route, component, compile_page(route, component, state)
|
return route, component, compile_page(route, component, state)
|
||||||
|
Loading…
Reference in New Issue
Block a user