Skip to content

Since v0.8 redirects from on_load and on_mount handlers are lost when serving from a non-root frontend path. #5674

Closed

Description

@tartansandal

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:

  1. Clicking on the "Go to index!" and "Go to subpage!" buttons do just that.
  2. Clicking on the "Bounce to index!" button causes the "/bouncer" page's on_load handler to redirect back to the index page.

However, if I adjust the environment variables to build and serve from "/prefix"

  1. The "Go to index!" and "Go to subpage!" buttons work as expected
  2. 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).
  3. 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:

  1. The baseline working case
  2. The prefix case that demonstrates the primary issue
  3. 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

  1. added
    bug
    on Aug 6, 2025
  2. self-assigned this
    on Aug 9, 2025
  3. jamesalphanome commented on Aug 14, 2025

    @jamesalphanome

    getting similar issues with redirects from on_mount handlers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions