Skip to content

fix: propagate frontend_path to base in vite.config.js - #5677

Merged
adhami3310 merged 1 commit into
reflex-dev:mainfrom
tartansandal:main
Aug 5, 2025
Merged

adhami3310 merged 1 commit into
reflex-dev:mainfrom
tartansandal:main

Conversation

@tartansandal

Copy link
Copy Markdown
Contributor

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 the base config 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. 😅

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

  1. Adding template infrastructure: A new VITE_CONFIG template constant is added to templates.py and a corresponding VITE_CONFIG_FILE constant is added to base.py, following the established pattern used for other configuration files like React Router.

  2. Converting static to dynamic template: The vite.config.js file is converted from a static template to a Jinja2 template (vite.config.js.jinja2) with a templated base property (base: "{{base}}",) that gets populated during compilation.

  3. Implementing compilation logic: A new _compile_vite_config() function is added to prerequisites.py that reads the frontend_path from the Reflex configuration, normalizes it with proper trailing slashes, and renders it into the Vite config template. An initialize_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

Edit Code Review Bot Settings | Greptile

@codspeed

codspeed Bot commented Aug 5, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #5677 will not alter performance

Comparing tartansandal:main (ba412d4) with main (71a54bf)

Summary

✅ 8 untouched benchmarks

@adhami3310 adhami3310 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this looks good to me, thanks for the contribution!

@masenf for second look

@adhami3310
adhami3310 merged commit a53c324 into reflex-dev:main Aug 5, 2025
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