Edit history

After you edit paragraphs, formatting, or tables, history lets you inspect earlier versions, compare changes, and restore a version when you have permission. The versions are stored by the server. Undo and redo are independent of history: they apply to the current editing session and do not require a history service.

Prepare collaboration and history services

Complete collaboration integration and license configuration first. Then verify that two sessions can edit the same Docs document and that changes survive a reload.

Connect history storage and permissions as described in Office collaboration extensions and the History example. Core collaboration does not enable history by itself; the backend must also serve history lists, version content, and restoration.

Add this configuration to the existing product, license, and collaboration setup. If a preset or an existing configuration already registers these plugins, modify that configuration instead of registering them a second time.

Plugin mode

Installation

Shell
pnpm add @univerjs-pro/edit-history @univerjs-pro/edit-history-ui @univerjs-pro/docs-history @univerjs-pro/docs-history-ui

Usage

TypeScript
import { UniverEditHistoryPlugin } from '@univerjs-pro/edit-history'import EditHistoryLocale from '@univerjs-pro/edit-history-ui/locale/en-US'import { UniverDocsHistoryPlugin } from '@univerjs-pro/docs-history'import { UniverDocsHistoryUIPlugin } from '@univerjs-pro/docs-history-ui'import HistoryLocale from '@univerjs-pro/docs-history-ui/locale/en-US'import { LocaleType, mergeLocales } from '@univerjs/core'import '@univerjs-pro/edit-history-ui/lib/index.css'const historyServerUrl = '/api/history'univerAPI.loadLocales(LocaleType.EN_US, mergeLocales(EditHistoryLocale, HistoryLocale))univer.registerPlugin(UniverEditHistoryPlugin, { historyServerUrl })univer.registerPlugin(UniverDocsHistoryPlugin)univer.registerPlugin(UniverDocsHistoryUIPlugin, {  univerContainerId: 'app',  historyServerUrl,})

Plugin configuration

UniverEditHistoryPlugin

  • historyServerUrl
    stringDefault: '/universer-api/history'
    Base URL of the history service.

UniverDocsHistoryUIPlugin

  • historyServerUrl
    stringDefault: '/universer-api/history'
    Base URL of the history service.
  • univerContainerId
    string
    DOM ID of the editor container.
  • viewerPlugins
    [PluginCtor, object?][]
    Additional plugins for the history viewer.
    • [0]
      PluginCtor
      The plugin constructor.
    • [1]
      object
      Options accepted by that constructor.

Set /api/history to the application's own history endpoint, and make sure that endpoint answers the requests the client sends. Both historyServerUrl values must be identical. Set univerContainerId to the DOM ID of the editor container, and load the locale that matches the editor language.

The history viewer opens a separate read-only editor. If the documents contain custom content, use viewerPlugins to add the plugins that the viewer does not include. Do not register the built-in viewer plugins again.

Preset mode

Installation

Shell
pnpm add @univerjs/preset-docs-collaboration

Usage

UniverDocsCollaborationPreset already includes the history UI and the plugins it depends on. Keep the existing editor and license setup. If the preset is already registered, update that registration instead of registering the preset or the history plugins a second time.

TypeScript
import { UniverDocsCollaborationPreset } from '@univerjs/preset-docs-collaboration'import CollaborationLocale from '@univerjs/preset-docs-collaboration/locales/en-US'import '@univerjs/preset-docs-collaboration/lib/index.css'const collaborationPreset = UniverDocsCollaborationPreset({  universerEndpoint: 'https://your-server.example',  univerContainerId: 'app',})

Preset configuration

UniverDocsCollaborationPreset

  • universerEndpoint
    stringDefault: window.location.origin
    Base URL of the collaboration server.
  • univerContainerId
    stringDefault: 'app'
    DOM ID of the editor container.

Add collaborationPreset to the presets array of the existing createUniver() call, and merge CollaborationLocale into the locale entry for the matching language. Set universerEndpoint to the server base URL and univerContainerId to the editor container ID. The preset builds the history URL as {universerEndpoint}/universer-api/history. Use Plugin Mode if you need a custom historyServerUrl or viewerPlugins configuration. Either mode still requires the backend services described above.

View and restore versions

Open history from the editor menu and select a version to inspect its content and the changes it contains. Restoring a version modifies the current shared document, so it should be limited to users with restore permission, and the server must enforce that permission.

To verify the integration, edit paragraphs, formatting, or tables, wait for collaboration to confirm the changes, then inspect the history list and the version content. Reopen the application and restart the service to confirm that the data persists. Restore an earlier version and confirm that a session in another browser receives the restored state.

If the list is empty, first check whether history was recorded for this document, then check the document ID and the service URL. If versions can be viewed but restoration fails, check the restore permissions and the collaboration connection. Reading history also requires authorization, because older versions can still contain data that has since been deleted.

Compare snapshots

To build a review screen, or to provide an AI Agent with a description of what changed, call compareUnitData(), or prepare a comparison once with prepareUnitComparison() and query it repeatedly. Register the History plugin for the product and import the Facade entry. Pass two fully materialized snapshots of the same unit as beforeSnapshot and afterSnapshot. The comparison is read-only: it requires no history service, and it neither restores nor merges content.

TypeScript
import { UnitComparisonDetailLevel, UnitComparisonFidelity } from '@univerjs-pro/edit-history'import { UniverInstanceType } from '@univerjs/core'import '@univerjs-pro/edit-history/facade'const comparison = univerAPI.prepareUnitComparison({  comparisonId: 'review-1',  unitId: beforeSnapshot.id,  type: UniverInstanceType.UNIVER_DOC,  fidelity: UnitComparisonFidelity.SNAPSHOT,  leftData: beforeSnapshot,  rightData: afterSnapshot,})const overview = comparison.query({ detail: UnitComparisonDetailLevel.SUMMARY })const scope = overview.scopes[0]const page = comparison.query({ scope, offset: 0, limit: 100 })console.log(page.items, page.page.hasMore, page.diagnostics)

Read scopes to see which views are available, then pass one of them to query() to narrow the result without rerunning the comparison. A page holds 100 items by default and accepts up to 1,000. Use page.hasMore with offset to fetch the remaining items. summary describes the entire comparison even when items are filtered. Check diagnostics.readiness and diagnostics.codes before treating the result as a complete comparison. For Node.js or CLI usage without an editor, see the headless comparison API.

How is this guide?

© 2026 DreamNum Co., Ltd.