From 47b7ab824262f5d3a1e0afe76ac7bf62a07cff02 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Thu, 12 Jan 2023 09:49:30 -0500 Subject: [PATCH 1/3] fix(worker): Adjust service worker file location before generating the config file (cherry picked from commit b59dd9f005c5132e964d1fc64de87706135d843e) --- src/Uno.Wasm.Bootstrap/ShellTask.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Uno.Wasm.Bootstrap/ShellTask.cs b/src/Uno.Wasm.Bootstrap/ShellTask.cs index ca2daaafa..8c5525f2d 100644 --- a/src/Uno.Wasm.Bootstrap/ShellTask.cs +++ b/src/Uno.Wasm.Bootstrap/ShellTask.cs @@ -258,8 +258,8 @@ public override bool Execute() ExtractAdditionalCSS(); CleanupDist(); PrepareFinalDist(); - GenerateConfig(); TouchServiceWorker(); + GenerateConfig(); MergeConfig(); GenerateIndexHtml(); GenerateEmbeddedJs(); @@ -1825,7 +1825,7 @@ private void GenerateConfig() config.AppendLine($"config.files_integrity = {{{filesIntegrityStr}}};"); config.AppendLine($"config.total_assemblies_size = {totalAssembliesSize};"); config.AppendLine($"config.enable_pwa = {enablePWA.ToString().ToLowerInvariant()};"); - config.AppendLine($"config.offline_files = ['{WebAppBasePath}', {offlineFiles}];"); + config.AppendLine($"config.offline_files = ['{WebAppBasePath}', {offlineFiles}, 'invalidfile'];"); config.AppendLine($"config.uno_shell_mode = \"{_shellMode}\";"); config.AppendLine($"config.emcc_exported_runtime_methods = [{emccExportedRuntimeMethodsParams}];"); From acfac1b2baffc56010f7654715e94294baa69ccc Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Thu, 12 Jan 2023 09:51:09 -0500 Subject: [PATCH 2/3] fix(worker): Don't fail worker installation on failed downloads (cherry picked from commit 29467759199f9d4e8cbd92042a80929115533cd0) --- .../WasmScripts/service-worker.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Uno.Wasm.Bootstrap/WasmScripts/service-worker.js b/src/Uno.Wasm.Bootstrap/WasmScripts/service-worker.js index 0dc173481..53ab08b73 100644 --- a/src/Uno.Wasm.Bootstrap/WasmScripts/service-worker.js +++ b/src/Uno.Wasm.Bootstrap/WasmScripts/service-worker.js @@ -5,9 +5,19 @@ console.debug("[ServiceWorker] Initializing"); self.addEventListener('install', function (e) { console.debug('[ServiceWorker] Installing offline worker'); e.waitUntil( - caches.open('$(CACHE_KEY)').then(function (cache) { + caches.open('$(CACHE_KEY)').then(async function (cache) { console.debug('[ServiceWorker] Caching app binaries and content'); - return cache.addAll(config.offline_files); + + // Add files one by one to avoid failed downloads to prevent the + // worker to fail installing. + for (var i = 0; i < config.offline_files.length; i++) { + try { + await cache.add(config.offline_files[i]); + } + catch (e) { + console.debug(`[ServiceWorker] Failed to fetch ${config.offline_files[i]}`); + } + } }) ); }); From 2e195929b06eba85ae682d3a3407db05231e0418 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Thu, 12 Jan 2023 16:07:02 -0500 Subject: [PATCH 3/3] fix(reg): Remove invalid offline file inclusion --- src/Uno.Wasm.Bootstrap/ShellTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Uno.Wasm.Bootstrap/ShellTask.cs b/src/Uno.Wasm.Bootstrap/ShellTask.cs index 8c5525f2d..6841df356 100644 --- a/src/Uno.Wasm.Bootstrap/ShellTask.cs +++ b/src/Uno.Wasm.Bootstrap/ShellTask.cs @@ -1825,7 +1825,7 @@ private void GenerateConfig() config.AppendLine($"config.files_integrity = {{{filesIntegrityStr}}};"); config.AppendLine($"config.total_assemblies_size = {totalAssembliesSize};"); config.AppendLine($"config.enable_pwa = {enablePWA.ToString().ToLowerInvariant()};"); - config.AppendLine($"config.offline_files = ['{WebAppBasePath}', {offlineFiles}, 'invalidfile'];"); + config.AppendLine($"config.offline_files = ['{WebAppBasePath}', {offlineFiles}];"); config.AppendLine($"config.uno_shell_mode = \"{_shellMode}\";"); config.AppendLine($"config.emcc_exported_runtime_methods = [{emccExportedRuntimeMethodsParams}];");