use sirv with spa fallback#5711
Conversation
CodSpeed Performance ReportMerging #5711 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Greptile Summary
This PR addresses issue #5706 by fundamentally changing how Reflex handles dynamic routing in production. The key architectural change is replacing the custom client-side routing mechanism with sirv's built-in SPA fallback functionality.
The change removes Reflex's custom client-side routing implementation, which consisted of a Python component (ClientSideRouting) that provided a JavaScript hook (useClientSideRouting) to detect 404 routes and handle redirects. This system was causing 404 errors and styling loss when users navigated to dynamic routes directly (via URL refresh or direct access).
Instead, the production server configuration now uses sirv ./build/client --single __spa-fallback.html --host which implements proper Single Page Application behavior. When a route doesn't match a static file, sirv serves the main HTML file, allowing React Router to handle client-side routing without 404 errors.
The changes span multiple files:
constants/installer.py: Updates production command from 'serve' to 'sirv-cli' with SPA fallbackapp.py: Removes client-side routing imports and simplifies 404 handling, addssuppressHydrationWarningto prevent hydration mismatches- Complete removal of
client_side_routing.pyandclient_side_routing.js - Updates to
pyi_hashes.jsonremoving the deleted component's hash
This approach aligns with modern SPA deployment practices where the server handles routing fallbacks, eliminating the need for complex client-side route detection and redirection logic.
Confidence score: 4/5
- This PR appears safe to merge as it addresses a known issue with a standard SPA solution
- Score reflects architectural complexity of removing client-side routing but using proven sirv approach
- Pay close attention to app.py for the hydration warning suppression and simplified 404 handling
5 files reviewed, no comments
masenf
left a comment
There was a problem hiding this comment.
well that's cool and a lot less hacky
fixes #5706