Add displayName to React components for DevTools visibility
Type of change
- New feature (non-breaking change which adds functionality)
- This change requires a documentation update
Description
This PR adds displayName properties to all compiled React components and contexts, improving visibility in React DevTools. Without explicit display names, DevTools shows generic labels like Context.Provider, Anonymous, or Component for every instance in the tree, making it difficult to debug component hierarchies.
Changes:
-
Context template (
context_template): AddeddisplayNameassignments for:- Built-in contexts:
ColorModeContext,UploadFilesContext,DispatchContext,EventLoopContext - State contexts: Named as
StateContext(python.state.name)to identify which Python state they carry ClientSidewrapper: Now a named function component with display name reflecting the wrapped component
- Built-in contexts:
-
Page template (
page_template): Every page compiles to a component namedComponent, so the route is now carried in itsdisplayName(e.g.,Component(about),Component(test/[dynamic])) to distinguish pages in DevTools -
Memo components (
_render_memo_component): AddeddisplayNameassignment to exported memoized components, using either:- The Python function name for
@rx.memodecorated components - The wrapped Python class name for auto-memoized components (instead of the hash-suffixed tag)
- The Python function name for
-
MemoComponentDefinition: Added optional
display_namefield to carry the name React DevTools should show -
Dynamic imports: Updated
ClientSide()calls to pass the component name as a second argument, enabling the wrapper to set an appropriate display name -
Theme context (
react-theme.js): AddeddisplayNameto the theme context
Test coverage
- Added 5 new unit tests in
test_compiler.pycovering context display names, page display names, and theClientSidewrapper naming - Added 3 new unit tests in
test_memo.pycovering memo display names, custom wrappers, and string escaping - Added 1 new unit test in
test_memoize_plugin.pycovering auto-memo display names - All existing tests pass
Checklist
- Tests pass with adequate coverage
-
uv run ruff check .anduv run ruff format .clean -
uv run pyright reflex testspasses -
pyi_hashes.jsonupdated - News fragment added