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

Minify state names v2 #3728

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

benedikt-bartscher
Copy link
Contributor

@benedikt-bartscher benedikt-bartscher commented Jul 31, 2024

alternative to #3701

currently the new tests are failing because somehow the env vars i was trying to set (in the fixtures) do not persist or do not get passed to frontend and backend correctly

@benedikt-bartscher
Copy link
Contributor Author

benedikt-bartscher commented Aug 4, 2024

Actually, it's not a problem with the env vars not getting passed. Tests are failing due to _var_set_state which is called during init_subclass hooks and writes the state names into the vars/vardata.

@benedikt-bartscher benedikt-bartscher marked this pull request as ready for review August 4, 2024 21:07
@benedikt-bartscher
Copy link
Contributor Author

benedikt-bartscher commented Aug 5, 2024

Actually, it's not a problem with the env vars not getting passed. Tests are failing due to _var_set_state which is called during init_subclass hooks and writes the state names into the vars/vardata.

@masenf do you have any idea how to solve this?
I have added a skip marker to those tests. They are working fine if you set REFLEX_MINIFY_STATES or prod env in your shell.

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.

as for the _var_set_state, we probably could just save a reference to the state class and defer formatting of the state name until it's actually needed (_var_full_name_needs_state_prefix)

@@ -23,6 +23,8 @@ export const clientStorage = {{ client_storage|json_dumps }}
export const clientStorage = {}
{% endif %}

export const main_state_name = "{{const.main_state_name}}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is already coming in as state_name.

reflex/compiler/compiler.py:90

Copy link
Contributor Author

@benedikt-bartscher benedikt-bartscher Aug 5, 2024

Choose a reason for hiding this comment

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

iirc this was the state name for rx.app.App.state. will check

Copy link
Contributor Author

@benedikt-bartscher benedikt-bartscher Aug 5, 2024

Choose a reason for hiding this comment

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

Yes, they are not the same. compile_contexts gets called from reflex.app.App._compile with self.state

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe for clarity, we should call the var root_state_name instead of main_state_name just to indicate that it's the name of rx.State, the root of the state "tree"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about main_state_dispatch should we rename that one to root_state_dispatch as well?

@benedikt-bartscher
Copy link
Contributor Author

as for the _var_set_state, we probably could just save a reference to the state class and defer formatting of the state name until it's actually needed (_var_full_name_needs_state_prefix)

Thanks, i was thinking about that. Do you want me to migrate to state refs in this PR or in a followup?

@masenf
Copy link
Collaborator

masenf commented Aug 5, 2024

i think you can do the refs in this PR, as long as it's not too invasive. We have a big Var refactor coming in the next week or so, that might conflict, but we can fix that up

@benedikt-bartscher benedikt-bartscher marked this pull request as draft September 4, 2024 19:38
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.

2 participants