mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #4223 from overleaf/bg-load-server-worker-timeout
add timeout on loading of service worker GitOrigin-RevId: d2153c9abf1dbd6eee3b2fcfd770a21766ebb84e
This commit is contained in:
parent
392b854f49
commit
866e2f0aab
2 changed files with 11 additions and 3 deletions
|
@ -369,7 +369,7 @@ If the project has been renamed please look in your project list for a new proje
|
|||
if (getMeta('ol-resetServiceWorker')) {
|
||||
unregisterServiceWorker()
|
||||
} else if (getMeta('ol-enablePdfCaching')) {
|
||||
loadServiceWorker()
|
||||
loadServiceWorker({ timeout: 5000 })
|
||||
}
|
||||
|
||||
export default angular.bootstrap(document.body, ['SharelatexApp'])
|
||||
|
|
|
@ -11,9 +11,9 @@ export function waitForServiceWorker() {
|
|||
return pendingWorkerSetup
|
||||
}
|
||||
|
||||
export function loadServiceWorker() {
|
||||
export function loadServiceWorker(options) {
|
||||
if (supportsServiceWorker()) {
|
||||
pendingWorkerSetup = navigator.serviceWorker
|
||||
const workerSetup = navigator.serviceWorker
|
||||
.register('/serviceWorker.js', {
|
||||
scope: '/project/',
|
||||
})
|
||||
|
@ -38,6 +38,14 @@ export function loadServiceWorker() {
|
|||
.catch(error =>
|
||||
captureException(OError.tag(error, 'Cannot register serviceWorker'))
|
||||
)
|
||||
if (options && options.timeout > 0) {
|
||||
const workerTimeout = new Promise(resolve => {
|
||||
setTimeout(resolve, options.timeout)
|
||||
})
|
||||
pendingWorkerSetup = Promise.race([workerSetup, workerTimeout])
|
||||
} else {
|
||||
pendingWorkerSetup = workerSetup
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue