Fix build failure when frontend_path is set without prerendering - #7044
Fix build failure when frontend_path is set without prerendering#7044masenf wants to merge 3 commits into
Conversation
… output When frontend_path is set, build() moves every child of .web/build/client into .web/build/client/<frontend_path>/. With route prerendering enabled, React Router already emits the prerendered HTML under that prefix, so the target directory exists by accident. With prerendering disabled (REFLEX_SSR=false) nothing creates it: os.rename fails, shutil.move falls back to copy2, and opening the destination raises FileNotFoundError, crashing `reflex run --env prod` and `reflex export`. Create the prefix directory up front so the relocation no longer depends on prerendering. The existing skip for the prefix's first segment keeps the prerendered output merging in as before. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UwbNDEaQNGWeHWS8nxsURd
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UwbNDEaQNGWeHWS8nxsURd
Merging this PR will not alter performance
Comparing Footnotes
|
Greptile SummaryThis PR creates the configured frontend prefix before relocating production build artifacts and adds regression coverage for builds with and without prerendered prefix output. The latest changes also reject parent-directory segments in
Confidence Score: 4/5The PR does not yet appear safe to merge because the existing output-containment issue remains unresolved. The previous finding is only partially fixed: rejecting Files Needing Attention: reflex/utils/build.py, packages/reflex-base/src/reflex_base/config.py
|
| Filename | Overview |
|---|---|
| reflex/utils/build.py | Creates the frontend prefix directory before relocation, but the earlier path-containment finding remains only partially addressed. |
| packages/reflex-base/src/reflex_base/config.py | Rejects parent-directory segments during normal configuration construction, while leaving absolute-path containment to the build logic. |
| tests/units/utils/test_build.py | Adds coverage for absent and prerendered prefix directories, though the expected destination conflicts with absolute PosixPath joining semantics. |
| tests/units/test_config.py | Covers rejection of bare parent segments and acceptance of non-traversal dotted names. |
Reviews (2): Last reviewed commit: "Reject ".." segments in frontend_path" | Re-trigger Greptile
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
frontend_path is a URL prefix, but it also names the directory below .web/build/client that the production build is relocated into (build.py) and served from (exec.py). A ".." segment would move the built frontend outside the build output, and since path_ops.mv removes existing destinations, could overwrite neighboring files. Validate this once in Config._normalize_paths so every consumer can trust the value, rather than re-checking at each filesystem use. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UwbNDEaQNGWeHWS8nxsURd
Type of change
Description
Fixes a
FileNotFoundErrorthat occurs when runningreflex run --env prodorreflex exportwithfrontend_pathconfigured and route prerendering disabled (REFLEX_SSR=false).Root cause: When prerendering is disabled, the static output directory structure is not created with the
frontend_pathprefix. 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:_patch_build()helper to reduce duplication_write_static_output()helpertest_build_relocates_static_output_without_prerendered_prefix_dir()to verify files are correctly relocated when prerendering is offtest_build_merges_static_output_into_prerendered_prefix_dir()to verify prerendered output is preserved when merging with non-prerendered assetsnews/+frontend-path-noprerender-build.bugfix.md: Added changelog entry documenting the fix.Test Plan
Added comprehensive unit tests covering both scenarios:
All existing tests continue to pass.
https://claude.ai/code/session_01UwbNDEaQNGWeHWS8nxsURd