Set is_hydrated var explicitly on rx.State (#2168)

This commit is contained in:
Elijah Ahianyo 2023-11-14 18:26:25 +00:00 committed by GitHub
parent f3929f47e3
commit f7f8aa171b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -13,9 +13,6 @@ if TYPE_CHECKING:
from reflex.app import App
State.add_var(constants.CompileVars.IS_HYDRATED, type_=bool, default_value=False)
class HydrateMiddleware(Middleware):
"""Middleware to handle initial app hydration."""
@ -57,7 +54,6 @@ class HydrateMiddleware(Middleware):
# Get the route for on_load events.
route = event.router_data.get(constants.RouteVar.PATH, "")
# Add the on_load events and set is_hydrated to True.
events = [*app.get_load_events(route), type(state).set_is_hydrated(True)] # type: ignore
events = fix_events(events, event.token, router_data=event.router_data)

View File

@ -194,6 +194,9 @@ class State(Base, ABC, extra=pydantic.Extra.allow):
# The router data for the current page
router: RouterData = RouterData()
# The hydrated bool.
is_hydrated: bool = False
def __init__(self, *args, parent_state: State | None = None, **kwargs):
"""Initialize the state.