diff --git a/ui/src/lib/demo/components/engine-panel.svelte b/ui/src/lib/demo/components/engine-panel.svelte index c26974ac..6cd108de 100644 --- a/ui/src/lib/demo/components/engine-panel.svelte +++ b/ui/src/lib/demo/components/engine-panel.svelte @@ -106,7 +106,8 @@ - {#each snapshot.orders as order (order.order_id)} + + {#each snapshot.orders as order, index (`${index}:${order.order_id}`)} {/each} diff --git a/website/scripts/build.mjs b/website/scripts/build.mjs index b09050af..0f6e7bf7 100644 --- a/website/scripts/build.mjs +++ b/website/scripts/build.mjs @@ -23,11 +23,23 @@ for (const [from, to] of Object.entries(redirects)) { const ui = new URL('../ui/', root); const chdb = new URL('node_modules/chdb-wasm/', root); const { version: engineVersion } = JSON.parse(await readFile(new URL('package.json', chdb), 'utf8')); -// The parts are cached for good, so their path names the exact bytes: gzip output can differ -// between builds of the same version, and a half-cached old part must never join a new one. +// The engine's files are cached for good, so their path names the exact bytes: gzip output can +// differ between builds of the same version, and a half-cached old part must never join a new one. const wasm = await readFile(new URL('dist/chdb.wasm', chdb)); const packed = gzipSync(wasm, { level: 9 }); -const engineBase = `/demo/engine/${engineVersion}-${createHash('sha256').update(packed).digest('hex').slice(0, 12)}/`; +// The engine's worker hands Emscripten the downloaded wasm as bytes (wasmBinary), and Firefox then +// never finishes starting it; streaming the same blob URL starts in about a second in every browser. +const workerSource = await readFile(new URL('dist/worker.js', chdb), 'utf8'); +const wasmAsBytes = ` const bytes = await fetchWithProgress(payload.wasmUrl, id); + if (bytes) + moduleOpts.wasmBinary = bytes;`; +if (!workerSource.includes(wasmAsBytes)) throw new Error(`chdb-wasm ${engineVersion}'s worker no longer loads the wasm as bytes; recheck the Firefox start.`); +const worker = workerSource.replace( + wasmAsBytes, + ` moduleOpts.locateFile = (path, prefix) => (path.endsWith('.wasm') ? payload.wasmUrl : prefix + path);`, +); +const engineHash = createHash('sha256').update(packed).update(worker).digest('hex').slice(0, 12); +const engineBase = `/demo/engine/${engineVersion}-${engineHash}/`; if (!existsSync(new URL('node_modules/', ui))) { // The UI's lockfile needs the npm it pins, as `make ui-install` uses. const { packageManager } = JSON.parse(await readFile(new URL('package.json', ui), 'utf8')); @@ -44,9 +56,10 @@ await cp(new URL('build/', ui), demo, { recursive: true }); // at most 25 MiB, and the page joins and gunzips them. const engine = new URL(engineBase.slice(1), output); await mkdir(engine, { recursive: true }); -for (const file of ['index.js', 'async.js', 'bindings.js', 'platform.js', 'protocol.js', 'status.js', 'worker.js', 'chdb.mjs']) { +for (const file of ['index.js', 'async.js', 'bindings.js', 'platform.js', 'protocol.js', 'status.js', 'chdb.mjs']) { await copyFile(new URL(`dist/${file}`, chdb), new URL(file, engine)); } +await writeFile(new URL('worker.js', engine), worker); await copyFile(new URL('LICENSE', chdb), new URL('LICENSE', engine)); const half = Math.ceil(packed.length / 2); const parts = [packed.subarray(0, half), packed.subarray(half)]; diff --git a/website/tests/ui-demo.test.mjs b/website/tests/ui-demo.test.mjs index 7c23f0f0..5cca7f40 100644 --- a/website/tests/ui-demo.test.mjs +++ b/website/tests/ui-demo.test.mjs @@ -126,7 +126,9 @@ test('on the real engine Execute, Promote and Roll back run, and every page read }); test('without cross-origin isolation the demo says so and plays the recording', async ({ page }) => { + // Only the page's own headers decide isolation; other requests the page may drop mid-flight. await page.route('**/demo/**', async (route) => { + if (route.request().resourceType() !== 'document') return route.continue(); const response = await route.fetch(); const headers = response.headers(); delete headers['cross-origin-embedder-policy'];
#{order.order_id}{order.status}{dollars(order.total_cents)}