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

fix: Fetch CORS resources from network #9586

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

Dschoordsch
Copy link
Contributor

@Dschoordsch Dschoordsch commented Apr 2, 2024

If we fetch our own assets we want a CORS response to properly cache it in the service worker. If the response is served from the browser cache however, then there is a high chance that the required response headers are missing and the browser responds with a CORS error instead of refetching the resource. This happens because the Vary header does not include headers not present in the original request. To avoid this error, always fetch from the network for requests we intend to cache in the SW.

Demo

https://www.loom.com/share/280ee174d1484814a06e4d2a1c9c2674?sid=374d929f-89ef-4ae5-ad9b-b108e5391737

Testing scenarios

  • setup ngrok to get a public URL with https (ngrok http 3000) and configure it in .env afterwards
  • locally run in production mode (yarn predeploy && yarn start)
  • open the site from the public URL
  • clear service worker cache
  • close tab and reopen the site
  • on master you'll now see broken login images, on PR this is fixed

Final checklist

  • I checked the code review guidelines
  • I have added Metrics Representative as reviewer(s) if my PR invovles metrics/data/analytics related changes
  • I have performed a self-review of my code, the same way I'd do it for any other team member
  • I have tested all cases I listed in the testing scenarios and I haven't found any issues or regressions
  • Whenever I took a non-obvious choice I added a comment explaining why I did it this way
  • I added the label Skip Maintainer Review Indicating the PR only requires reviewer review and can be merged right after it's approved if the PR introduces only minor changes, does not contain any architectural changes or does not introduce any new patterns and I think one review is sufficient'
  • PR title is human readable and could be used in changelog

If we fetch our own assets we want a CORS response to properly cache it
in the service worker. If the response is served from the browser cache
however, then there is a high chance that the required response headers
are missing and the browser responds with a CORS error instead of
refetching the resource. This happens because the Vary header does not
include headers not present in the original request.
To avoid this error, always fetch from the network for requests we
intend to cache in the SW.
@rafaelromcar-parabol
Copy link
Contributor

LGTM!

@Dschoordsch Dschoordsch merged commit b6ddfa5 into master Apr 2, 2024
7 checks passed
@Dschoordsch Dschoordsch deleted the fix/avoidBrowserCacheForCachedFiles branch April 2, 2024 13:08
@github-actions github-actions bot mentioned this pull request Apr 2, 2024
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants