Skip to content

Commit

Permalink
Correctly fall back from the prefetched Hugo wasm to the network file
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Oct 5, 2023
1 parent a8bde91 commit 76c236a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions javascript-modules/engines/hugo-engine/lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Engine {
if (compressedHugoWasm?.constructor === Uint8Array) {
await this.initializeInlineHugo();
} else {
await this.initializeLocalCompressedHugo();
await this.initializeLocalCompressedHugo(true);
}

// TODO: Tidy
Expand Down Expand Up @@ -100,7 +100,7 @@ export class Engine {
}));
}

async initializeLocalCompressedHugo() {
async initializeLocalCompressedHugo(usePrefetch) {
try {

let prefetched = {};
Expand All @@ -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 {
Expand All @@ -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);
}
}
}

Expand Down

0 comments on commit 76c236a

Please sign in to comment.