Repository navigation
Description
For context, I'm serving a number of reflex apps from different frontend paths, using a reverse proxy to deliver the appropriate frontend code and proxy the websocket requests to the appropriate backend. This this works well, provided I set REFLEX_FRONTEND_PATH and REFLEX_API_URL appropriately during the build and when running the apps, plus doing a little path wrangling in the reverse proxy config. All good.
Since v0.8, however, I've had a problem with on_load and on_mount handlers that I use to redirect users based on authentication status. Here's a minimal app to demonstrate the problem that just focuses on the on_load handlers.
import reflex as rx # noqa: D100
@rx.page("/")
def index() -> rx.Component: # noqa: D103
return rx.container(
rx.vstack(
rx.heading("This is the index page!"),
rx.button("Go to Subpage!", on_click=rx.redirect("/subpage")),
),
)
@rx.page("/subpage")
def subpage() -> rx.Component: # noqa: D103
return rx.container(
rx.vstack(
rx.heading("This is the sub page!"),
rx.button("Go to index!", on_click=rx.redirect("/")),
rx.button("Bounce to index!", on_click=rx.redirect("/bouncer")),
)
)
@rx.page("/bouncer", on_load=rx.redirect("/"))
def bouncer() -> rx.Component: # noqa: D103
return rx.container(
rx.vstack(
rx.heading("This is the bouncer page!"),
rx.text("You should not be here!"),
rx.button("Go to index!", on_click=rx.redirect("/")),
),
)
app = rx.App()This all works as expected when run in either development mode or in production with a single port and serving everything from root:
- Clicking on the "Go to index!" and "Go to subpage!" buttons do just that.
- Clicking on the "Bounce to index!" button causes the "/bouncer" page's
on_loadhandler to redirect back to the index page.
However, if I adjust the environment variables to build and serve from "/prefix"
- The "Go to index!" and "Go to subpage!" buttons work as expected
- Clicking on the "Bounce to index!" button displays the "/bouncer" page but does not then redirect to the index page. (I do note that an extra "/" is appended to the path though).
- Reloading the "/bouncer/" page redirects to the index page.
I get the same behaviour using both Caddy and Nginx as reverse proxies.
Demonstrating the issue requires a fair bit of set up, so I've provided a zip file with the full docker-compose setup for:
- The baseline working case
- The prefix case that demonstrates the primary issue
- A potential hack that fixes a secondary issue with the location of javascript assets, but not the primary one.
#5677 is an attempt to fix the secondary issue. (I was hoping it would fix the primary one as well, but no such luck).
Hope this all makes sense and we can get this to work as it's the final hurdle to upgrading to v0.8. 😅
Activity
linear commentedon Aug 5, 2025
ENG-7266 Since v0.8 redirects from `on_load` and `on_mount` handlers are lost when serving from a non-root frontend path.
jamesalphanome commentedon Aug 14, 2025
getting similar issues with redirects from on_mount handlers
Add integration tests for frontend_path redirects