fix(config): isolate project-imported rxconfig per RegistrationContext

IM
5h ago
+276-8

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) (preserving Config subclasses and all classes/plugin instances defined in rxconfig.py, as relied on by #7144).
  • Duplicates Reflex's mutable container fields (_non_default_attributes, frontend_compression_formats, frontend_packages, plugins, disable_plugins, and vite_allowed_hosts / cors_allowed_origins when 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 that get_config() copies a project-imported rxconfig module's config when present or loads rxconfig.py from disk otherwise.
  • Adds regression tests covering forked and sibling contexts, custom Config subclasses, persisted overrides, and collection isolation, and adds a reflex-base bugfix 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 main and 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_checking on 3.11 & 3.14) and uv 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.