Skip to content

ENG-6500: Add vite-plugin-safari-cachebust to smooth out HMR issues#5513

Merged
adhami3310 merged 6 commits into
mainfrom
safari-cachebust
Jul 1, 2025
Merged

ENG-6500: Add vite-plugin-safari-cachebust to smooth out HMR issues#5513
adhami3310 merged 6 commits into
mainfrom
safari-cachebust

Conversation

@masenf
Copy link
Copy Markdown
Collaborator

@masenf masenf commented Jul 1, 2025

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

  • create blank app
  • reflex run
  • open app in Safari
  • add rx.State.router.session.client_token in the blank app somewhere
  • without this fix, we get a frontend error that is not clearable without a shift-refresh

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.
@linear
Copy link
Copy Markdown

linear Bot commented Jul 1, 2025

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

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.ts implementing a Safari-specific middleware that injects timestamp parameters into modulepreload links
  • Modified reflex/.templates/web/vite.config.js to integrate the new plugin for development mode only
  • Plugin operates by adding __reflex_ts query 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

Comment thread reflex/.templates/web/vite-plugin-safari-cachebust.ts Outdated
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jul 1, 2025

CodSpeed Performance Report

Merging #5513 will not alter performance

Comparing safari-cachebust (ab32135) with main (33de56b)

Summary

✅ 8 untouched benchmarks

@adhami3310 adhami3310 merged commit 80942f6 into main Jul 1, 2025
40 of 41 checks passed
@adhami3310 adhami3310 deleted the safari-cachebust branch July 1, 2025 19:11
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.

2 participants