fix(config): preserve preloaded rxconfig classes
Summary
Classes defined in rxconfig.py (for example a rx.State subclass the app imports from its config module) lost their identity because the config module was executed more than once per process. The app module imports rxconfig, then App.__init__ called reload_config(), which re-executed rxconfig.py and produced a second copy of every class it defines. The result was a StateValueError for the duplicate substate, or _state pointing at a class the app never imported, and pickle round-trips that failed to resolve the original type.
The fix lives in the config loader and in App, so it applies to any ASGI server. No special backend entry point is needed; granian --interface asgi --factory myapp.myapp:app works unchanged.
App.__init__now callsget_config()instead ofreload_config(), reusing the config already loaded in the activeRegistrationContext.- The first
get_config()load of a context reuses anrxconfigmodule that project code already imported from the project root, instead of executing the file again. A module that_get_config()itself loaded is not reused, so separate contexts still get independentConfiginstances.reload_config()still always loads from disk. reflex rundrops its redundantreload_config()after persisting the host and port overrides; those values are already written through_set_persistent.- The unit-test autouse fixture now clears the
Configslot on the context between tests as well as theAppslot, so a mocked config from one test cannot leak into the next.
reflex/utils/exec.py is unchanged from main.
Tests
tests/units/test_app.py: classes defined inrxconfig.pykeep their identity acrossApp()construction, both when the config was loaded first and when the app module importedrxconfigfirst (the direct ASGI case).
Validation
- Full unit suite, ruff and pyright pass.
- A real app whose
rxconfig.pydefines anrx.State: directgranian --factory pkg.mod:appfailed withStateValueErrorbefore and serves requests now;reflex rundev startup, State events, and hot reload of the app file and ofrxconfig.pywork.