Skip to content

use sirv with spa fallback#5711

Merged
adhami3310 merged 4 commits into
mainfrom
khaleel/eng-7315-dyamic-routing-causing-a-404-and-loosing-bootstrap-style
Aug 14, 2025
Merged

use sirv with spa fallback#5711
adhami3310 merged 4 commits into
mainfrom
khaleel/eng-7315-dyamic-routing-causing-a-404-and-loosing-bootstrap-style

Conversation

@adhami3310

Copy link
Copy Markdown
Member

fixes #5706

@linear

linear Bot commented Aug 13, 2025

Copy link
Copy Markdown

@codspeed-hq

codspeed-hq Bot commented Aug 13, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #5711 will not alter performance

Comparing khaleel/eng-7315-dyamic-routing-causing-a-404-and-loosing-bootstrap-style (26c6c5d) with main (38e1efc)

Summary

✅ 8 untouched benchmarks

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fallback
  • app.py: Removes client-side routing imports and simplifies 404 handling, adds suppressHydrationWarning to prevent hydration mismatches
  • Complete removal of client_side_routing.py and client_side_routing.js
  • Updates to pyi_hashes.json removing 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

Edit Code Review Bot Settings | Greptile

@masenf masenf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well that's cool and a lot less hacky

@adhami3310 adhami3310 merged commit 0d01de5 into main Aug 14, 2025
52 of 53 checks passed
@adhami3310 adhami3310 deleted the khaleel/eng-7315-dyamic-routing-causing-a-404-and-loosing-bootstrap-style branch August 14, 2025 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dyamic Routing causing a 404 and loosing bootstrap style

2 participants