ENG-6500: Add vite-plugin-safari-cachebust to smooth out HMR issues#5513
Merged
Conversation
Safari with react-router has a fairly long standing issue where key modules are aggressively cached, which results in code mismatch during hot reload that cannot be resolved even by refreshing the browser. It requires a Shift+Refresh to bypass the cache, which isn't a great DX. This plugin rewrites the resulting HTML in dev mode to add timestamp query parameter to modulepreload links in an attempt to get Safari to reload stuff from the network. Not needed in prod mode because those files already contain a content hash in the filename.
Contributor
There was a problem hiding this comment.
PR Summary
Added a specialized Vite plugin to fix Safari's aggressive module caching issues during development, improving hot module reload (HMR) reliability specifically for React Router applications.
- Added
reflex/.templates/web/vite-plugin-safari-cachebust.tsimplementing a Safari-specific middleware that injects timestamp parameters into modulepreload links - Modified
reflex/.templates/web/vite.config.jsto integrate the new plugin for development mode only - Plugin operates by adding
__reflex_tsquery parameter to force network reloads instead of using cached modules - Solution specifically targets Safari browsers and only affects HTML responses in dev environment
2 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile
CodSpeed Performance ReportMerging #5513 will not alter performanceComparing Summary
|
Generate an array of pattern, replacement pairs, and then reduce those over the original html at the end.
adhami3310
approved these changes
Jul 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Safari with react-router has a fairly long standing issue where key modules are aggressively cached, which results in code mismatch during hot reload that cannot be resolved even by refreshing the browser. It requires a Shift+Refresh to bypass the cache, which isn't a great DX.
This plugin rewrites the resulting HTML in dev mode to add timestamp query parameter to modulepreload links in an attempt to get Safari to reload stuff from the network. Not needed in prod mode because those files already contain a content hash in the filename.
Testing
reflex runrx.State.router.session.client_tokenin the blank app somewhere