Skip to content
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
Next Next commit
fix(files): Only register preview service worker once when the instan…
…ce is hosted at the root path

Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Dec 18, 2024
commit d3bd99947dbf77a9270386f4f57cc87fa760dbe6
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
Loading