Conversation
* also initialize vite.config.js during compile, in case user has set a different runtime frontend path * remove assetsDir workaround (base handles this case)
Add `prepend_frontend_path` to `rx.Config` to make it easy to handle the contract in current and future APIs. Use `prepend_frontend_path` in: * rx.get_upload_url * rx.asset * vite config * react router config
Greptile SummaryThis PR fixes
Confidence Score: 4/5Safe to merge for apps using local assets only; shared assets (rx.asset shared=True) will break in subpath deployments until the one-line fix is applied. One P1 gap remains: shared/library assets are not prefixed, making them silently broken when frontend_path is configured. All other changes are clean refactors with correct equivalent behaviour and good integration-test coverage. reflex/assets.py β the shared-asset return path (line 132) needs prepend_frontend_path. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Config.frontend_path = '/prefix'"] --> B["Config.prepend_frontend_path('/') β '/prefix/'"]
B --> C["vite.config.js: base: '/prefix/'"]
B --> D["react-router.config.js: basename: '/prefix/'"]
B --> E["Starlette Mount('/prefix/')"]
B --> F["rx.asset(local) β '/prefix/image.png'"]
E --> G["StaticFiles(dir=static/prefix/)"]
C --> H["Vite build: rewrites JS/CSS asset refs"]
H --> I["build.py: mv static/* β static/prefix/"]
I --> G
J["rx.asset(shared=True)"] --> K["'/external/mod/img.png' β NO prefix β"]
K --> L["Browser requests /external/mod/img.png"]
L --> M["Starlette 404 β not under /prefix/"]
|
playwright uses a session scope fixture which creates an event loop for the session, so subsequent tests using pytest_asyncio fixture cannot start their own loop and fail
include updated test case
Summary
Fixes outstanding issues with the
frontend_pathconfig option and adds comprehensive integration tests to prevent regressions.When
frontend_pathis set (e.g.frontend_path="/app"), the Reflex app is served from a subpath instead of the root. This PR ensures that assets, stylesheets, links, redirects, uploads,on_loadevents, and 404 pages all work correctly under a configuredfrontend_path.Changes
tests/integration/tests_playwright/test_frontend_path.py): Comprehensive playwright tests covering links (static and dynamic routes), redirects (event handler andon_load), assets (local and shared), uploaded files (rx.get_upload_url), CSSurl()references,on_loadevent firing, and 404 pages. Tests are parametrized over dev/prod mode and with/withoutfrontend_path.reflex/assets.py):rx.asset(shared=True)now callsprepend_frontend_pathon its return value, matching the existing behavior for local assets.testing.py: FixAppHarnessProdto locate404.htmlunder thefrontend_pathsubdirectory when set, matching real prod deployment behavior..github/workflows/integration_app_harness.yml): Run playwright tests in a separate job from other integration tests. Thepytest-playwrightplugin keeps an asyncio event loop running on the main thread for the session, which is incompatible withpytest-asynciotests in the same process.Closes
Supersedes
Test plan
uv run pytest tests/integration/tests_playwright/test_frontend_path.py -vpasses in both dev and prod modes, with and withoutfrontend_pathuv run pytest tests/integration --ignore=tests/integration/tests_playwright -v