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(pwa): file SWR filter & allow navigation 403s [LIBS-356] [LIBS-357] #762

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions pwa/src/service-worker/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,18 @@ export function setUpServiceWorker() {
const navigationRouteHandler = ({ request }) => {
return fetch(request)
.then((response) => {
if (response.type === 'opaqueredirect') {
// It's sending a redirect to the login page. Return
// that to the client
if (response.type === 'opaqueredirect' || !response.ok) {
// It's sending a redirect to the login page,
// or an 'unauthorized'/'forbidden' response.
// Return that to the client
return response
}

// Otherwise return precached index.html
return matchPrecache(indexUrl)
})
.catch(() => {
// Request failed (maybe offline). Return cached response
// Request failed (probably offline). Return cached response
return matchPrecache(indexUrl)
})
}
Expand Down Expand Up @@ -137,13 +138,13 @@ export function setUpServiceWorker() {

// If not recording, fall through to default caching strategies for app
// shell:
// SWR strategy for static assets that can't be precached.
// SWR strategy for image assets that can't be precached.
// (Skip in development environments)
registerRoute(
({ url }) =>
PRODUCTION_ENV &&
urlMeetsAppShellCachingCriteria(url) &&
fileExtensionRegexp.test(url.pathname),
/\.(jpg|gif|png|bmp|tiff|ico)$/.test(url.pathname),
new StaleWhileRevalidate({ cacheName: 'other-assets' })
)

Expand Down