Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: More robust solution to Safari dev cache bug #476

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

mattbrictson
Copy link
Contributor

@mattbrictson mattbrictson commented Jul 2, 2024

Description 📖

Safari had an annoying bug where it will ignore changes to CSS files, breaking the developer's hot-reload experience. The Vite Ruby troubleshooting guide recommends moving CSS into the JS entrypoint as a workaround.

However, in Safari 17.5, the problem is now even worse: the bug now affects JS files as well. That means the previously documented workaround is no longer a solution for the entire scope of Safari HMR issues.

Background 📜

Ultimately, the problem is a known bug in Safari where it aggressively caches JS and CSS files that are marked rel=preload.

If a request is preloaded, Safari will always retrieve it from the cache, regardless of the cache headers for that request.

https://bugs.webkit.org/show_bug.cgi?id=193533

The Fix 🔨

Update the Vite Ruby troubleshooting guide with a more robust workaround: disable the rel=preload Link header in development. This completely solves the issue for me.

FWIW, I'm running:

macOS 14.5 (23F79)
Safari 17.5 (19618.2.12.11.6)

@mattbrictson mattbrictson force-pushed the docs/fix-safari-cache-bug branch from f2f74ef to a0bf454 Compare July 3, 2024 00:02
@mattbrictson
Copy link
Contributor Author

mattbrictson commented Jul 3, 2024

Looks like there is a global way to disable rel=preload that is supported all the way back to Rails 6.1. I'll revise my PR to recommend this approach instead.

https://guides.rubyonrails.org/configuring.html#config-action-view-preload-links-header

Edit: done ✅

@mattbrictson mattbrictson force-pushed the docs/fix-safari-cache-bug branch from a0bf454 to 4392f17 Compare July 3, 2024 00:13
@ElMassimo
Copy link
Owner

Looks great, thanks Matt!

@ElMassimo ElMassimo merged commit 93ae26f into ElMassimo:main Jul 3, 2024
17 checks passed
@mattbrictson mattbrictson deleted the docs/fix-safari-cache-bug branch July 3, 2024 17:08
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