Fix build failure when frontend_path is set without prerendering
Type of change
- Bug fix (non-breaking change which fixes an issue)
Description
Fixes a FileNotFoundError that occurs when running reflex run --env prod or reflex export with frontend_path configured and route prerendering disabled (REFLEX_SSR=false).
Root cause: When prerendering is disabled, the static output directory structure is not created with the frontend_path prefix. The build process attempted to move files into a non-existent prefix directory, causing the failure.
Solution: Explicitly create the prefix directory before attempting to relocate static files into it. This ensures the directory exists regardless of whether prerendering created it.
Changes
-
reflex/utils/build.py: Modified thebuild()function to create the prefix directory before moving files, and simplified the file movement logic to use the pre-computedprefix_dirvariable. -
tests/units/utils/test_build.py:- Extracted common test setup into
_patch_build()helper to reduce duplication - Extracted static file creation into
_write_static_output()helper - Added
test_build_relocates_static_output_without_prerendered_prefix_dir()to verify files are correctly relocated when prerendering is off - Added
test_build_merges_static_output_into_prerendered_prefix_dir()to verify prerendered output is preserved when merging with non-prerendered assets
- Extracted common test setup into
-
news/+frontend-path-noprerender-build.bugfix.md: Added changelog entry documenting the fix.
Test Plan
Added comprehensive unit tests covering both scenarios:
- Static output relocation when the prefix directory doesn't exist (prerendering off)
- Merging of static output into an existing prerendered prefix directory
All existing tests continue to pass.