atagen

malice

public
Star0
Watch0

Commit 2c899da1562b

tarball

atagen <boss@atagen.co>2026-10-26 06:04 UTC

2 files changed+4-2
web: name the device worker without breaking vite's worker detection

Vite only bundles new SharedWorker(new URL(...)) when the options are a static literal, so the runtime trace name made the device build fail. Importing the worker as ?worker&url keeps the bundling and lets the name be computed.
Modified file: web/src/lib/transport-worker.ts+3 additions−2 deletions
@@ -4,6 +4,7 @@ import type { MemberSummary, RoomSummary } from './types';
44 import { ApiError, type CommandRequest, type SendKind, type SessionInfo, type SoftLogout, type Transport, type UploadExtras, type VerifyAction } from './transport';
55 import { statusForKind } from './wire-status';
66 import { pageTraceFilter, workerName } from './trace-name';
7+import workerUrl from '../worker/worker.ts?worker&url';
78
89 function toApiError(error: { kind: string; message: string }): ApiError {
910 return new ApiError(statusForKind(error.kind), error.message, error.kind);
@@ -38,7 +39,7 @@ class WorkerClient {
3839
3940 private connect(): void {
4041 if (typeof SharedWorker !== 'undefined') {
41- const worker = new SharedWorker(new URL('../worker/worker.ts', import.meta.url), {
42+ const worker = new SharedWorker(workerUrl, {
4243 type: 'module',
4344 name: workerName(pageTraceFilter())
4445 });
@@ -46,7 +47,7 @@ class WorkerClient {
4647 worker.port.start();
4748 this.port = worker.port;
4849 } else {
49- const worker = new Worker(new URL('../worker/worker.ts', import.meta.url), {
50+ const worker = new Worker(workerUrl, {
5051 type: 'module',
5152 name: workerName(pageTraceFilter())
5253 });
Modified file: web/vite.config.ts+1 additions
@@ -60,6 +60,7 @@ export default defineConfig(({ mode }) => {
6060 plugins: [svelte(), twemojiPlugin(), precacheManifestPlugin()],
6161 define: { __MALICE_DEVICE__: JSON.stringify(device) },
6262 assetsInclude: ['**/*.wasm'],
63+ worker: { format: 'es' },
6364 resolve: {
6465 alias: {
6566 'malice:device-transport': device ? '/src/lib/device-transport.ts' : '/src/lib/device-transport.stub.ts'