fix(config): isolate project-imported rxconfig per RegistrationContext
IM
5h ago+276+276+012345678901234567890123456789-8-8-0123456789
Summary
When project code has already imported rxconfig, _imported_config() in packages/reflex-base/src/reflex_base/config.py returned module.config directly. Every RegistrationContext in the process (including forks created via RegistrationContext.fork()) therefore shared the same mutable Config instance, allowing top-level mutations, _set_persistent() overrides, and list edits on one context to leak into other contexts and into rxconfig.config.
This PR gives each RegistrationContext an isolated copy of the imported Config via _copy_config() without re-executing rxconfig.py:
- Performs a shallow
copy.copy(config)(preservingConfigsubclasses and all classes/plugin instances defined inrxconfig.py, as relied on by #7144). - Duplicates Reflex's mutable container fields (
_non_default_attributes,frontend_compression_formats,frontend_packages,plugins,disable_plugins, andvite_allowed_hosts/cors_allowed_originswhen lists) so in-place updates such as_set_persistent()mutating_non_default_attributes(which_replace_defaults()consults) do not leak across contexts. - Updates
RegistrationContext.fork()'s docstring to describe thatget_config()copies a project-importedrxconfigmodule's config when present or loadsrxconfig.pyfrom disk otherwise. - Adds regression tests covering forked and sibling contexts, custom
Configsubclasses, persisted overrides, and collection isolation, and adds areflex-basebugfix news fragment.
Closes #8104
Type of change
- Bug fix (non-breaking change which fixes an issue)
All Submissions:
- Have you followed the guidelines stated in CONTRIBUTING.md file?
- Have you checked to ensure there aren't any other open Pull Requests for the desired change?
Changes To Core Features:
- Have you added an explanation of what your changes do and why you'd like us to include them?
- Have you written new tests for your core changes, as applicable?
- Have you successfully ran tests with your changes locally?
Verification
- Confirmed the new regression tests fail on
mainand pass with this fix. uv run pytest tests/units/test_config.py tests/units/test_app.py -q— 623 passed.uv run pytest tests/units/reflex_base/ -q— 2036 passed, 12 skipped.uv run --no-sync ruff check&ruff format --check&codespell— clean.uv run --no-sync pyright(modified files +tests/type_checkingon 3.11 & 3.14) anduv run --no-sync ty check --python-version 3.14 tests/type_checking— 0 errors.uv run --no-sync python scripts/make_pyi.py --check— clean.BASE_REF=origin/main uv run --frozen --package reflex-release reflex-release changelog-check&check-headings&sync --check— all green.