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

Signed-off-by: provokateurin <kate@provokateurin.de>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
This commit is contained in:
provokateurin 2024-12-18 16:46:30 +01:00 committed by nextcloud-command
parent 5e6b36aa2a
commit eea37f13d6
3 changed files with 11 additions and 4 deletions

View file

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

4
dist/files-init.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long