@vitessce/neuroglancer-workers 4.1.3 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,16 +1,29 @@
1
- We want to inline worker scripts to make the package more portable (i.e., not dependent on relative worker URLs).
1
+ # @vitessce/neuroglancer-workers
2
2
 
3
- Using typescript alone does not allow us to do this: we need a build step to do it for us.
4
-
5
- We can use rollup and [rollup-plugin-web-worker-loader](https://github.com/darionco/rollup-plugin-web-worker-loader) to perform this build step.
3
+ Inlined Neuroglancer worker scripts, so that consumers of Vitessce do not need to configure their bundler to emit Neuroglancer's worker and WebAssembly files (and so that Vitessce works when loaded cross-origin, e.g. from a CDN in vitessce-python).
6
4
 
7
5
  ```sh
8
6
  pnpm run build
9
7
  ```
10
8
 
11
- ## Neuroglancer Workers
9
+ ## How it works
10
+
11
+ Mainline [neuroglancer](https://github.com/google/neuroglancer) creates its workers with
12
+ `new Worker(new URL('./chunk_worker.bundle.js', import.meta.url), { type: 'module' })`
13
+ and loads WASM decoders (Draco, PNG, JPEG-XL, compresso) with
14
+ `fetch(new URL('./x.wasm', import.meta.url))`.
15
+
16
+ `scripts/build.mjs` uses Rollup to bundle each worker entry point into a single classic-worker IIFE:
17
+
18
+ - Neuroglancer's package-internal `#src/...` subpath imports are resolved with the `default` condition (all datasources/kvstores enabled).
19
+ - `new URL('./x.wasm', import.meta.url)` is replaced with a `data:application/wasm;base64,...` URL.
20
+ - The async-computation worker (decoders) is spawned from inside the chunk worker, so its code is embedded in the chunk worker and started from a Blob URL (a nested worker). Terminating the chunk worker also terminates these.
21
+
22
+ `dist/index.js` exports `ChunkWorker()`, which starts the chunk worker from a Blob URL.
23
+
24
+ The main-thread side lives in `@vitessce/neuroglancer`: `setup-viewer.js` passes the worker to Neuroglancer's `DataManagementContext`, which is patched (`patches/neuroglancer@2.41.2.patch`) to accept an injected worker instead of constructing one from a URL. The viewer takes ownership of the worker and terminates it on `viewer.dispose()`.
12
25
 
13
- The authors of `react-neuroglancer` suggest to copy workers from `neuroglancer` during a consumer application's bundling: https://github.com/neuroglancerhub/react-neuroglancer/issues/37#issuecomment-2576251703
26
+ ## Upgrading Neuroglancer
14
27
 
15
- However, we want to inline worker code to avoid passing the burden of setting up workers onto the consumers of Vitessce.
16
- See `@vitessce/workers` for an example of how we have previously done this for custom worker scripts for the heatmap view.
28
+ 1. Bump `neuroglancer` here and in `@vitessce/neuroglancer`, and rename the patch / `patchedDependencies` entry to the new version (re-apply with `pnpm patch` if `lib/data_management_context.js` changed).
29
+ 2. Run `pnpm run build`. The build fails loudly if the async worker construction in `lib/async_computation/request.js` changed shape, or if any `import.meta` reference survives bundling.