fix(files): Only register preview service worker once when the instance is hosted at the root path

Signed-off-by: provokateurin <kate@provokateurin.de>
pull/49917/head
provokateurin 2024-12-18 16:46:30 +07:00
parent 407ac7f739
commit d3bd99947d
No known key found for this signature in database
1 changed files with 8 additions and 1 deletions

@ -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) {