Set is_hydrated var explicitly on rx.State (#2168)
This commit is contained in:
parent
f3929f47e3
commit
f7f8aa171b
@ -13,9 +13,6 @@ if TYPE_CHECKING:
|
|||||||
from reflex.app import App
|
from reflex.app import App
|
||||||
|
|
||||||
|
|
||||||
State.add_var(constants.CompileVars.IS_HYDRATED, type_=bool, default_value=False)
|
|
||||||
|
|
||||||
|
|
||||||
class HydrateMiddleware(Middleware):
|
class HydrateMiddleware(Middleware):
|
||||||
"""Middleware to handle initial app hydration."""
|
"""Middleware to handle initial app hydration."""
|
||||||
|
|
||||||
@ -57,7 +54,6 @@ class HydrateMiddleware(Middleware):
|
|||||||
|
|
||||||
# Get the route for on_load events.
|
# Get the route for on_load events.
|
||||||
route = event.router_data.get(constants.RouteVar.PATH, "")
|
route = event.router_data.get(constants.RouteVar.PATH, "")
|
||||||
|
|
||||||
# Add the on_load events and set is_hydrated to True.
|
# 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 = [*app.get_load_events(route), type(state).set_is_hydrated(True)] # type: ignore
|
||||||
events = fix_events(events, event.token, router_data=event.router_data)
|
events = fix_events(events, event.token, router_data=event.router_data)
|
||||||
|
@ -194,6 +194,9 @@ class State(Base, ABC, extra=pydantic.Extra.allow):
|
|||||||
# The router data for the current page
|
# The router data for the current page
|
||||||
router: RouterData = RouterData()
|
router: RouterData = RouterData()
|
||||||
|
|
||||||
|
# The hydrated bool.
|
||||||
|
is_hydrated: bool = False
|
||||||
|
|
||||||
def __init__(self, *args, parent_state: State | None = None, **kwargs):
|
def __init__(self, *args, parent_state: State | None = None, **kwargs):
|
||||||
"""Initialize the state.
|
"""Initialize the state.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user