Web Workers

Docs can run document layout in a Web Worker1 through UniverDocsLayoutWorkerPlugin. Register it after the Docs core plugin. workerFactory creates a fresh Worker for the layout service.

Start with installation and basic usage. The following snippets extend that setup. Register the plugins before creating or loading content; replace existing registrations rather than registering a plugin twice.

Main thread

TypeScript
import { UniverDocsLayoutWorkerPlugin } from '@univerjs/docs'univer.registerPlugin(UniverDocsLayoutWorkerPlugin, {  workerFactory: () => new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' }),})

Worker entry

TypeScript
import { startDocsLayoutWorker } from '@univerjs/docs'startDocsLayoutWorker()

Use a module Worker and a separate entry file. Keep the Worker and main-thread package versions aligned. Rendering and user interaction stay on the main thread.

Footnotes

  1. A Web Worker runs JavaScript outside the browser’s main thread and exchanges messages with it. It cannot access the page DOM directly; moving calculations into a Worker does not move the editor UI there.

How is this guide?

© 2026 DreamNum Co., Ltd.