fix: Handle periods in dynamic route segments for production mode#6129
fix: Handle periods in dynamic route segments for production mode#6129timon0305 wants to merge 2 commits intoreflex-dev:mainfrom
Conversation
Greptile OverviewGreptile SummaryThis PR fixes dynamic routes with periods (e.g., Key Changes:
Issues Found:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant App as App.compile()
participant Route as route.get_dynamic_route_prefixes()
participant Skeleton as frontend_skeleton.initialize_package_json()
participant PackageJson as package.json
App->>App: Collect routes from _unevaluated_pages
App->>Route: get_dynamic_route_prefixes(routes)
Route->>Route: Filter routes with dynamic segments
Route->>Route: Extract prefix before first dynamic segment
Route-->>App: Return list of prefixes (e.g., ["^/data/", "^/posts/"])
alt dynamic_route_prefixes exist
App->>Skeleton: initialize_package_json(dynamic_route_prefixes)
Skeleton->>Skeleton: Build sirv command with --ignores flags
Skeleton->>PackageJson: Write package.json with updated prod command
end
|
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
| prod_command = constants.PackageJson.Commands.PROD | ||
| if dynamic_route_prefixes: | ||
| # Add --ignores flag for each dynamic route prefix | ||
| ignores = " ".join(f"--ignores '{prefix}'" for prefix in dynamic_route_prefixes) |
There was a problem hiding this comment.
use shlex.join instead so these values get properly shell quoted
| prefix = "/" + prefix | ||
| if prefix and prefix != "/": | ||
| # Add trailing slash and anchor to start for sirv pattern | ||
| pattern = f"^{prefix}/" |
There was a problem hiding this comment.
should use re.escape(prefix) here to ensure the prefix will never contain regex injection
|
is this even a bug anymore? on current import reflex as rx
def index():
return rx.heading(rx.State.id, rx.State.version, rx.State.slug)
app = rx.App()
app.add_page(index, route="/foo/[id]/[version]/[slug]")
app.add_page(index, route="/data/[version]/info")
app.add_page(index, route="/posts/[slug]")
app.add_page(index, route="/[id]")
app.add_page(index)all of maybe the bug got fixed upstream? either way, when i run with the |
Summary
Fixes dynamic routes with periods (e.g.,
/data/v1.2.3/info) breaking in production mode. sirv treats URLs with extensions as asset requests, returning 404 instead of falling back to the SPA handler.Changes
get_dynamic_route_prefixes()in reflex/route.py to extract route patterns with dynamic segments_compile_package_json()in reflex/utils/frontend_skeleton.py to accept dynamic route prefixes--ignoresflagsExample
For routes
/data/[version]/infoand/posts/[slug], the generated package.json now includes:Test plan
/data/v1.2.3/infoworks in production modeFixes #5803