Skip to content

feat(joint-router-avoid): worker.createWorker option and /worker subpath export - #3488

Open
kumilingus wants to merge 1 commit into
clientIO:devfrom
kumilingus:feat/router-avoid-worker-factory
Open

feat(joint-router-avoid): worker.createWorker option and /worker subpath export#3488
kumilingus wants to merge 1 commit into
clientIO:devfrom
kumilingus:feat/router-avoid-worker-factory

Conversation

@kumilingus

@kumilingus kumilingus commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Description

WorkerProvider spawns its Web Worker with a hardcoded new Worker(new URL('./Worker.mjs', import.meta.url), { type: 'module' }). That only works when the consumer's bundler transforms this pattern inside node_modules (Vite, webpack 5). The Angular CLI esbuild builder transforms it only in application TS sources — at runtime the URL resolves against the main bundle (/Worker.mjs → 404), and hand-copying the file cannot work either, since it contains bare @joint/core / libavoid-js specifiers. The worker script URL was not configurable at all.

Changes

1. worker.createWorker option

initAvoidRouter(graph, {
    worker: {
        createWorker: () => new Worker(new URL('./my-avoid.worker', import.meta.url), { type: 'module' })
    }
});

The factory is stripped from the options posted to the Worker (a function cannot be structured-cloned). Default path unchanged — Vite/webpack consumers are unaffected.

2. @joint/router-avoid/worker subpath export

Public worker entry so the application-side worker file is one line — import '@joint/router-avoid/worker'; — and never references the private dist/ layout. Same pattern as pdfjs-dist and the Monaco editor workers.

Tests

TDD — written first and watched fail on dev: worker.createWorker overrides how the routing Worker is spawned (factory called once, provider talks to the factory-created Worker through the init/ready handshake, worker options forwarded). 29/29 passing; lint clean. Changeset: @joint/router-avoid minor.

The MainThreadProvider idle fix that briefly lived on this branch was split out to #3489 (patch, against master).

🤖 Generated with Claude Code

@kumilingus
kumilingus force-pushed the feat/router-avoid-worker-factory branch from c163c7f to 9f372fc Compare August 26, 2026 18:08
@kumilingus kumilingus changed the title feat(joint-router-avoid): worker.createWorker option and /worker subpath export; fire idle after incremental main-thread changes feat(joint-router-avoid): worker.createWorker option and /worker subpath export Aug 26, 2026
…port

Angular CLI's esbuild builder only transforms 'new Worker(new URL(...))'
spawns in application sources, so the provider's hardcoded spawn 404s at
runtime and the worker script URL was not configurable. The new
'worker.createWorker' option lets the application spawn the Worker
itself, and the '@joint/router-avoid/worker' subpath export gives it a
public worker entry to spawn (same pattern as pdfjs-dist). The factory
is stripped from the options posted to the Worker - a function cannot
be structured-cloned.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kumilingus
kumilingus force-pushed the feat/router-avoid-worker-factory branch from 9f372fc to c9066ef Compare August 26, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants