Skip to content

Commit caeaa3f

Browse files
authored
Merge pull request #33 from ByteVeda/fix/wasm-cache-busting
fix(docs): cache-bust WASM module URL to prevent stale load errors
2 parents a6ba88e + 9c022b7 commit caeaa3f

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

docs-site/docusaurus.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const config: Config = {
2020
onBrokenLinks: 'throw',
2121
onBrokenMarkdownLinks: 'warn',
2222

23+
customFields: {
24+
wasmCacheBuster: String(Date.now()),
25+
},
26+
2327
markdown: {
2428
mermaid: true,
2529
},

docs-site/src/hooks/usePaperjam.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
12
import type { WasmModule } from '@site/src/types/paperjam';
23
import { useEffect, useState } from 'react';
34

45
let cachedModule: WasmModule | null = null;
56

67
export function usePaperjam() {
8+
const { siteConfig } = useDocusaurusContext();
9+
const cacheBuster =
10+
(siteConfig.customFields?.wasmCacheBuster as string) || '';
11+
712
const [loading, setLoading] = useState(!cachedModule);
813
const [error, setError] = useState<string | null>(null);
914
const [paperjam, setPaperjam] = useState<WasmModule | null>(cachedModule);
1015

1116
useEffect(() => {
1217
if (cachedModule) return;
13-
const wasmUrl = '/paperjam/wasm/paperjam_wasm.js';
18+
const wasmUrl = `/paperjam/wasm/paperjam_wasm.js?v=${cacheBuster}`;
1419
(async () => {
1520
try {
1621
const mod = await import(/* webpackIgnore: true */ wasmUrl);
@@ -23,7 +28,7 @@ export function usePaperjam() {
2328
setLoading(false);
2429
}
2530
})();
26-
}, []);
31+
}, [cacheBuster]);
2732

2833
return { paperjam, loading, error };
2934
}

0 commit comments

Comments
 (0)