From 76c236aaf668d4eda1153df3e9d3d27c036771ec Mon Sep 17 00:00:00 2001 From: Liam Bigelow <40188355+bglw@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:26:06 +1300 Subject: [PATCH] Correctly fall back from the prefetched Hugo wasm to the network file --- CHANGELOG.md | 2 ++ javascript-modules/engines/hugo-engine/lib/engine.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e06b5514..d7229675 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ ## Unreleased +* Fixes an error when loading Bookshop's dependencies through CloudCannon's client editing interface + ## v3.8.0 (September 27, 2023) * Added support for extraFiles that can be passed to Bookshop's Hugo engine, allowing custom shortcodes and partials to be used diff --git a/javascript-modules/engines/hugo-engine/lib/engine.js b/javascript-modules/engines/hugo-engine/lib/engine.js index 47c1d31d..3a748c03 100644 --- a/javascript-modules/engines/hugo-engine/lib/engine.js +++ b/javascript-modules/engines/hugo-engine/lib/engine.js @@ -72,7 +72,7 @@ export class Engine { if (compressedHugoWasm?.constructor === Uint8Array) { await this.initializeInlineHugo(); } else { - await this.initializeLocalCompressedHugo(); + await this.initializeLocalCompressedHugo(true); } // TODO: Tidy @@ -100,7 +100,7 @@ export class Engine { })); } - async initializeLocalCompressedHugo() { + async initializeLocalCompressedHugo(usePrefetch) { try { let prefetched = {}; @@ -114,7 +114,7 @@ export class Engine { const compressedWasmPath = (new URL(compressedWasmOrigin)).pathname; let compressedBuffer; - if (prefetched[compressedWasmPath]) { + if (usePrefetch && prefetched[compressedWasmPath]) { compressedBuffer = await prefetched[compressedWasmPath]?.arrayBuffer(); this.loadedFrom = "prefetch"; } else { @@ -134,6 +134,11 @@ export class Engine { } catch (e) { console.error("Couldn't load the local compressed Hugo WASM"); console.error(e); + + // If our prefetch fails, fall back to loading the wasm ourselves + if (usePrefetch) { + await this.initializeLocalCompressedHugo(false); + } } }