Skip to content

Add integration tests for frontend path#5712

Open
tartansandal wants to merge 6 commits intoreflex-dev:mainfrom
tartansandal:kjh/integration-tests-for-frontend-path
Open

Add integration tests for frontend path#5712
tartansandal wants to merge 6 commits intoreflex-dev:mainfrom
tartansandal:kjh/integration-tests-for-frontend-path

Conversation

@tartansandal
Copy link
Contributor

@tartansandal tartansandal commented Aug 14, 2025

Introduces an integration test for #5674.
This xfails on main but passes on #5698

Edit: also fixed an apparent bug in test_link_hover.py. There may be a deeper issue here.
Edit: removed xfail after merging main which now includes #5698.
Edit: added a test for 404s.

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 14, 2025

Merging this PR will not alter performance

✅ 8 untouched benchmarks


Comparing tartansandal:kjh/integration-tests-for-frontend-path (0afccdf) with main (3c11451)

Open in CodSpeed

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR introduces integration testing for frontend path functionality, specifically addressing issue #5674 where on_load and on_mount handlers fail to redirect properly when Reflex applications are served from non-root frontend paths (e.g., '/prefix').

The changes include two main components:

  1. Environment Variable Addition: A new REFLEX_FRONTEND_PATH environment variable is added to the EnvironmentVariables class in reflex/environment.py. This string variable defaults to an empty string and provides the configuration mechanism for specifying the base path under which the frontend is served.

  2. Comprehensive Integration Test: A new test file tests/integration/tests_playwright/test_frontend_path.py creates a complete end-to-end test using Playwright. The test creates a Reflex app with redirect pages and validates that redirects work correctly both in normal conditions and when served from a non-root frontend path.

The integration test uses two fixtures - one for production mode and another that sets the REFLEX_FRONTEND_PATH to '/prefix'. It employs parametrized testing to verify both scenarios, with the prefix case marked as xfail since it demonstrates the known bug that should be resolved by the related PR #5698.

This change fits into the broader Reflex ecosystem by enabling proper deployment behind reverse proxies, a common pattern where multiple applications are served from different paths on the same domain. The environment variable provides a clean configuration interface that other parts of the codebase can reference to adjust their behavior for non-root deployments.

Confidence score: 4/5

  • This PR introduces well-structured integration testing with minimal risk to existing functionality
  • Score reflects solid test design and environment variable implementation, though the xfail test indicates known issues
  • Pay close attention to the test file to ensure proper cleanup of environment variables and test isolation

2 files reviewed, 2 comments

Edit Code Review Bot Settings | Greptile

@tartansandal
Copy link
Contributor Author

Note I'm using simple environment module tweaks to simulate changing the environment. An alternative would be to modify AppHarness to take a config object. That would be a much larger change, but might be useful testing some configuration scenarios.

@tartansandal tartansandal changed the title Add an integration tests for frontend path Add integration tests for frontend path Aug 17, 2025
@tartansandal tartansandal force-pushed the kjh/integration-tests-for-frontend-path branch from 619abbb to e5d9f9b Compare August 26, 2025 02:44
@tartansandal tartansandal force-pushed the kjh/integration-tests-for-frontend-path branch from e5d9f9b to 26c3be7 Compare September 30, 2025 05:26
@tartansandal tartansandal force-pushed the kjh/integration-tests-for-frontend-path branch 2 times, most recently from 26c3be7 to 02650f3 Compare October 2, 2025 03:09
Copy link

@shahshahii shahshahii left a comment

Choose a reason for hiding this comment

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

Shah

@masenf
Copy link
Collaborator

masenf commented Mar 6, 2026

needs to be updated to remove the new Environment variables (those are exposed by default), and have the test update the Config instance directly.

When frontend_path is set, the build output (including 404.html) is
nested under that prefix directory. Update the static file server to
mirror what sirv does in real prod deployments.
Test on_load and on_mount redirects with and without a frontend_path
prefix in both dev mode (AppHarness) and prod mode (AppHarnessProd).

See reflex-dev#5674
Use REFLEX_SHOW_BUILT_WITH_REFLEX env var to set the Config value,
avoiding the need for a custom environment variable definition.
AppHarness._initialize_app calls get_config(reload=True), which
resets any direct Config mutations made before the harness starts.
@tartansandal tartansandal force-pushed the kjh/integration-tests-for-frontend-path branch from 9aebd43 to 4be4cbe Compare March 9, 2026 11:41
@tartansandal
Copy link
Contributor Author

Thanks for taking another look at this! 🙏

I've rebased onto current main and revised the approach based on your feedback:

  • Removed all environment.py changes — those env vars have become defaults since this PR was originally created, so the additions were redundant.
  • Switched to os.environ for setting REFLEX_FRONTEND_PATH and REFLEX_SHOW_BUILT_WITH_REFLEX in the test fixtures. I initially tried mutating the Config instance directly (e.g. get_config().frontend_path = "/prefix"), but AppHarness._initialize_app calls get_config(reload=True) which creates a fresh Config from disk and wipes out any prior mutations. Setting the values via os.environ means they survive the reload through Config.update_from_env() — and it mirrors how users actually configure these in practice.
  • Fixed AppHarnessProd._run_frontend — it was hardcoding the 404.html path at the web root, but when frontend_path is set the build output (including 404.html) is nested under that prefix. Updated it to match what sirv does in real prod deployments.
  • Added prod-mode prefix tests — the original fixtures were inconsistently using AppHarnessProd for baselines but AppHarness (dev mode) for prefix cases. Now both dev and prod are covered for the prefix scenarios.

All 7 tests passing, pre-commit checks green ✅

@tartansandal
Copy link
Contributor Author

TIL: monkeypatch.setenv 😄

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.

3 participants