Web Workers

Univer Docs can run document layout in a Web Worker1 by registering UniverDocsLayoutWorkerPlugin. Register the plugin after the Docs core plugin. The workerFactory it accepts creates a new Worker for the layout service.

The snippets below extend the setup described in installation and basic usage. Plugins must be registered before content is created or loaded. To change an existing registration, modify that registration instead of registering the same plugin twice.

Main thread

UniverDocsLayoutWorkerPlugin

  • workerFactory
    () => Worker
    Creates the Worker that runs document layout. Required.
  • fontFaces
    object[]
    Loads the specified fonts in the editor and in the layout Worker before layout starts.
    • family
      string
      Font family name used for document layout.
    • source
      string | ArrayBuffer
      Font bytes, or a CSS FontFace source such as url(...).
    • descriptors
      FontFaceDescriptors
      Font weight, style, or other browser FontFace descriptors.
  • requestTimeoutMs
    numberDefault: 15_000
    Starts recovery when a single Worker request runs longer than this value, in milliseconds.
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 { Univer } from '@univerjs/core'import { UniverDocsWorkerPlugin } from '@univerjs/docs/worker'const univer = new Univer()univer.registerPlugin(UniverDocsWorkerPlugin)

Use a module Worker with a separate entry file. Keep the package versions in the Worker and on the main thread identical. Rendering and user interaction remain 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.