fix: stabilize web loading and paper rendering

This commit is contained in:
Hakan Seven 2026-07-25 21:34:29 +03:00
commit bca65600cd
25 changed files with 109 additions and 62 deletions

View file

@ -3,9 +3,16 @@ import init, { parse_document } from "./worker_pkg/ocs_web_worker.js";
const ready = init();
self.onmessage = async ({ data }) => {
let stage = "initialize worker";
try {
await ready;
const encoded = parse_document(data.name, new Uint8Array(data.bytes));
const encoded = parse_document(
data.name,
new Uint8Array(data.bytes),
(next) => {
stage = next;
},
);
// wasm-bindgen returns a view into WebAssembly.Memory. Copy to a standalone
// ArrayBuffer before transferring it, otherwise the worker's wasm memory
// itself would be detached.
@ -14,7 +21,9 @@ self.onmessage = async ({ data }) => {
} catch (error) {
self.postMessage({
ok: false,
error: error instanceof Error ? error.message : String(error),
error: `${stage}: ${
error instanceof Error ? error.stack || error.message : String(error)
}`,
});
}
};