Merge pull request #49917 from nextcloud/fix/files/preview-service-worker-registration

fix(files): Only register preview service worker once when the instance is hosted at the root path
This commit is contained in:
Stephan Orbaugh 2024-12-18 17:19:57 +01:00 committed by GitHub
commit db683da757
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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