Repository navigation
fix: propagate frontend_path to base in vite.config.js - #5677
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR addresses a deployment issue where JavaScript assets built with Vite were always served from the '/assets' path, ignoring the configured frontend_path setting. This caused problems when serving multiple Reflex applications from the same web server using distinct frontend paths.
The solution involves making the Vite configuration dynamic by:
-
Adding template infrastructure: A new
VITE_CONFIGtemplate constant is added totemplates.pyand a correspondingVITE_CONFIG_FILEconstant is added tobase.py, following the established pattern used for other configuration files like React Router. -
Converting static to dynamic template: The
vite.config.jsfile is converted from a static template to a Jinja2 template (vite.config.js.jinja2) with a templatedbaseproperty (base: "{{base}}",) that gets populated during compilation. -
Implementing compilation logic: A new
_compile_vite_config()function is added toprerequisites.pythat reads thefrontend_pathfrom the Reflex configuration, normalizes it with proper trailing slashes, and renders it into the Vite config template. Aninitialize_vite_config()function writes the generated config file, and this is integrated into the web directory initialization process.
This change enables proper multi-app deployments where each Reflex app can serve its assets from the correct subdirectory (e.g., '/myapp/assets' instead of just '/assets'), following the same pattern already used for React Router's basename configuration.
Confidence score: 4/5
- This PR addresses a legitimate deployment issue and follows established patterns in the codebase for handling configuration templates
- Score reflects that this is a targeted fix with comprehensive test coverage and consistent implementation across multiple files
- Pay close attention to the Vite configuration template and the path normalization logic in
prerequisites.py
5 files reviewed, no comments
CodSpeed Performance ReportMerging #5677 will not alter performanceComparing Summary
|
adhami3310
left a comment
There was a problem hiding this comment.
this looks good to me, thanks for the contribution!
@masenf for second look
Currently all javascript assets built using vite are served from the '/assets' path, ignoring whatever has been set for
frontend_path. This is problematic when trying to serve two distinct reflex apps from the same web server but using distinct frontend paths. This patch set thebaseconfig entry for vite based on the reflex configuration so the compiled javascript will be served from a subfolder of the frontend_path.Not sure if this is the best place to tweak the configuration. I've tried to follow what has been done elsewhere. 😅