Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set is_hydrated var explicitly on rx.State #2168

Merged
merged 2 commits into from
Nov 14, 2023

Conversation

ElijahAhianyo
Copy link
Collaborator

Define an explicit is_hydrated var on the state so it is converted properly when doing State._init_vars on base vars in the base state

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good solution, but would still want to better understand the root cause

@masenf
Copy link
Collaborator

masenf commented Nov 14, 2023

From discord [1]

in v0.3.2, the hydrate middleware seems to be loaded first, adds the field to the base rx.State, and then the app module defines a substate and hits the __init_subclass__ logic that iameli described above.

In main the hydrate middleware loads after we start running the module code, which actually makes sense, because importing rx.State is not dependent on rx.App (which is what brings in the middleware import).

If i modify my app code to deref rx.App first before defining any substates, then the problem go away. Even just print(rx.App) at the top of the file makes this go away.

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to do anything to specify that this is a Var? Because that logic currently lives in the init_subclass method

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

substates will pick it up as a Var, but it wouldn't be directly usable off of rx.State itself, as far as i can tell.

@picklelo picklelo merged commit f7f8aa1 into main Nov 14, 2023
45 checks passed
Alek99 pushed a commit that referenced this pull request Nov 20, 2023
@masenf masenf deleted the elijah/explicit-hydrated-bool branch December 6, 2023 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants