ELK runs in a worker: the flow layout loads elkjs's worker build as a Vite ?worker behind elk-api, so a phone's eight layout passes no longer block the page (Demo house at 390px with 4x CPU throttling, long tasks 15.0 to 0.8 s, longest 2.1 to 0.3 s); positions and routes unchanged
This commit is contained in:
@@ -14,6 +14,20 @@ import assert from "node:assert/strict"
|
||||
// @ts-expect-error the runtime has it, the DOM types say it is not removable.
|
||||
globalThis.self = undefined
|
||||
|
||||
// A page runs ELK in a worker Vite builds (`?worker`). Here the same build
|
||||
// runs in-thread, as the fake worker it exports outside a worker.
|
||||
// @ts-expect-error the worker build ships without types.
|
||||
const { Worker: InThread } = await import("elkjs/lib/elk-worker.min.js")
|
||||
// @ts-expect-error bun's global, which the DOM types do not know.
|
||||
Bun.plugin({
|
||||
name: "elk in-thread",
|
||||
setup: (build: { module: (id: string, load: () => object) => void }) =>
|
||||
build.module("elkjs/lib/elk-worker.min.js?worker", () => ({
|
||||
exports: { default: InThread },
|
||||
loader: "object",
|
||||
})),
|
||||
})
|
||||
|
||||
const { layoutGraph, nodeHeight, portFraction, PORT_SPAN } = await import(
|
||||
"./layout"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user