Raise actionable error for components declaring library react-router-dom - #6991
Conversation
React Router 8 dropped the react-router-dom re-export package and Reflex no longer installs it (#6854), but a custom component declaring library="react-router-dom" still fell through the generic custom-library path: bun installed an unpinned react-router-dom@^7, nesting a second React Router 7 copy beside the first-party v8. Dev happened to work (vite deduped to the hoisted v8 copy), while prod builds failed at prerender with a cryptic "Cannot destructure property 'basename'" TypeError. Found as FINDING-010 in 0.9.9a1 pre-release testing. Component._get_imports now rejects any import contribution that resolves to the react-router-dom package - the bare name, versioned forms (react-router-dom@7.18.2), and subpath imports (react-router-dom/server), whether from library, lib_dependencies, or add_imports - with an error naming the component and pointing at library="react-router" (or "react-router/dom" for RouterProvider/HydratedRouter). Similarly named packages such as react-router-dom-fork are unaffected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EMjBXPozsNeQNSBZecNH8x
Greptile SummaryThe PR adds compile-time validation that rejects component import contributions resolving to the removed
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| packages/reflex-base/src/reflex_base/components/component.py | Adds a centralized prohibited-import guard and invokes it on each component’s merged import contributions before caching. |
| tests/units/components/test_component.py | Covers rejected bare, versioned, subpath, and dependency forms, plus accepted replacement and similarly named libraries. |
| packages/reflex-base/news/+react-router-dom-guard.bugfix.md | Documents the new actionable compilation failure and supported React Router replacements. |
Reviews (3): Last reviewed commit: "Delete news/+react-router-dom-guard.bugf..." | Re-trigger Greptile
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
All Submissions:
Type of change
Changes To Core Features:
Defect
FINDING-010 (MEDIUM) from the 0.9.9a1 pre-release testing round: React Router 8 dropped the
react-router-domre-export package and Reflex no longer installs it (#6854), but a custom component declaringlibrary = "react-router-dom"still fell through the generic custom-library install path.bun addthen installed an unpinnedreact-router-dom@^7, nesting a second React Router 7 copy beside the first-party v8:reflex.lock/package.json— working purely by accident.TypeError: Cannot destructure property 'basename' of React10.useContext(...) as it is null, exit 1, with nothing pointing at the real cause.Fix
Component._get_imports(reflex-base) now checks the component's merged import contributions —library,lib_dependencies, andadd_importsalike — and raises a pointeredValueErrorwhen any of them resolves to the removedreact-router-dompackage. The bare name, versioned forms (react-router-dom@7.18.2), and subpath imports (react-router-dom/server,react-router-dom@7.18.2/server) are all caught; similarly named but distinct packages (e.g.react-router-dom-fork) are not. The error names the offending component and tells the author to uselibrary = "react-router"(or"react-router/dom"forRouterProvider/HydratedRouter), matching the migration documented in the React Router 8 changelog entry:The check sits in the per-component import-collection chokepoint (before the imports cache is populated), so it fires at compile/collection time in both dev and prod, names the component that declared the library, and costs a single
startswithpre-filter per import key. News fragments added undernews/andpackages/reflex-base/news/.Test plan
tests/units/components/test_component.py:test_get_imports_rejects_react_router_dom_library(parametrized over the bare, versioned, subpath, and versioned+subpath forms) — all 4 fail withDID NOT RAISE ValueErroron unfixedmain, pass with the fix.test_get_imports_rejects_react_router_dom_lib_dependency— fails on unfixedmain, passes with the fix.test_get_imports_allows_react_router_libraries—react-router,react-router/dom, andreact-router-dom-forkremain accepted.uv run pytest tests/units/components tests/units/compiler— 4338 passed;uv run pytest tests/units/test_app.py tests/units/reflex_base— 393 passed.uv run ruff check .anduv run ruff format .clean;uv run pyright reflex tests packages/reflex-base— 0 errors (one pre-existing warning in an untouched file).uv run python scripts/make_pyi.py— nopyi_hashes.jsonchanges.🤖 Generated with Claude Code
https://claude.ai/code/session_01EMjBXPozsNeQNSBZecNH8x
Generated by Claude Code