Skip to content

Commit

Permalink
Merge pull request #49917 from nextcloud/fix/files/preview-service-wo…
Browse files Browse the repository at this point in the history
…rker-registration

fix(files): Only register preview service worker once when the instance is hosted at the root path
  • Loading branch information
sorbaugh authored Dec 18, 2024
2 parents 407ac7f + 4298898 commit db683da
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion apps/files/src/services/ServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ export default () => {
window.addEventListener('load', async () => {
try {
const url = generateUrl('/apps/files/preview-service-worker.js', {}, { noRewrite: true })
const scope = getRootUrl()
let scope = getRootUrl()
// If the instance is not in a subfolder an empty string will be returned.
// The service worker registration will use the current path if it receives an empty string,
// which will result in a service worker registration for every single path the user visits.
if (scope === '') {
scope = '/'
}

const registration = await navigator.serviceWorker.register(url, { scope })
logger.debug('SW registered: ', { registration })
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-init.js.map

Large diffs are not rendered by default.

0 comments on commit db683da

Please sign in to comment.