Add deprecation shims for bundled_libraries module globals

Merged
MA
2mo ago
+121-3

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

Description

Adds compatibility shims to maintain backward compatibility with downstream packages (notably reflex-enterprise) that read reflex_base.components.dynamic.bundled_libraries and DEFAULT_BUNDLED_LIBRARIES directly.

These module-level globals were moved onto RegistrationContext in a prior breaking change. This PR restores read access to them via __getattr__ hooks that:

  1. Resolve against the active RegistrationContext when accessed
  2. Emit deprecation warnings (removal in 1.0) directing users to the new API
  3. Properly propagate AttributeError for unknown attributes

The shims are implemented in:

  • reflex_base.components.dynamic.__getattr__() — handles the actual resolution
  • reflex/components/dynamic.__getattr__() — delegates to reflex_base for names the star import misses

Changes

  • reflex_base/components/dynamic.py: Added __getattr__() to provide deprecated access to bundled_libraries and DEFAULT_BUNDLED_LIBRARIES, resolving them against the active context with deprecation warnings
  • reflex/components/dynamic.py: Added __getattr__() to delegate attribute lookups to reflex_base (needed because star imports don't trigger __getattr__)
  • tests/units/reflex_base/components/test_dynamic.py: Comprehensive test coverage for the shims, including context isolation, deprecation warnings, and error handling
  • news/6382.breaking.md and news/+bundled-libraries-shim.deprecation.md: Updated breaking change notes to document the deprecation path

Test Plan

Added unit tests covering:

  • Shim returns active context's bundled_libraries
  • Shim works via reflex namespace (reflex.components.dynamic)
  • DEFAULT_BUNDLED_LIBRARIES shim returns correct default list
  • Deprecation warnings are emitted with correct feature names
  • Unknown attributes raise AttributeError with proper module name

All tests pass with adequate coverage.

Checklist

  • Tests pass with adequate coverage
  • uv run ruff check . and uv run ruff format . clean
  • uv run pyright reflex tests passes
  • Documentation updated (news files)
  • Deprecation warnings added with proper version info

https://claude.ai/code/session_019RU2VRJPPA3MWrjCGL15sy