Edit history
After you edit slide text, shapes, or slide order, open history to inspect earlier versions, compare changes, and restore a version when permission allows. History reads the versions that the server stores. Undo and redo apply only to the current editing session and do not require a history service.
Prepare collaboration and history services
Begin with collaboration integration and license configuration. Verify that two sessions can edit the same Slides document and that changes survive a reload.
Connect history storage and permissions through Office collaboration extensions and the History example. Core collaboration does not enable history by itself. The backend must also support history lists, version content, and restoration.
Add the history plugins
Add the following registrations 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.
pnpm add @univerjs-pro/edit-history @univerjs-pro/edit-history-ui @univerjs-pro/slides-history @univerjs-pro/slides-history-uinpm install @univerjs-pro/edit-history @univerjs-pro/edit-history-ui @univerjs-pro/slides-history @univerjs-pro/slides-history-uiyarn add @univerjs-pro/edit-history @univerjs-pro/edit-history-ui @univerjs-pro/slides-history @univerjs-pro/slides-history-uibun add @univerjs-pro/edit-history @univerjs-pro/edit-history-ui @univerjs-pro/slides-history @univerjs-pro/slides-history-uiimport { UniverEditHistoryPlugin } from '@univerjs-pro/edit-history'import EditHistoryLocale from '@univerjs-pro/edit-history-ui/locale/en-US'import { UniverSlidesHistoryPlugin } from '@univerjs-pro/slides-history'import { UniverSlidesHistoryUIPlugin } from '@univerjs-pro/slides-history-ui'import HistoryLocale from '@univerjs-pro/slides-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(UniverSlidesHistoryPlugin)univer.registerPlugin(UniverSlidesHistoryUIPlugin, { univerContainerId: 'app', historyServerUrl,})Plugin configuration
UniverEditHistoryPlugin
historyServerUrlstringDefault:'/universer-api/history'Base URL of the history service.
UniverSlidesHistoryUIPlugin
historyServerUrlstringDefault:'/universer-api/history'Base URL of the history service.univerContainerIdstringDOM ID of the editor container.viewerPlugins[PluginCtor, object?][]Additional plugins for the history viewer.[0]PluginCtorThe plugin constructor.[1]objectOptions accepted by the constructor.
Replace /api/history with the history endpoint of the application, and ensure that the 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.
The history viewer runs a separate read-only editor. If the content requires plugins that the viewer does not include, add them through viewerPlugins, and do not register the built-in viewer plugins a second time.
View and restore versions
Open history from the editor menu, select a version, and inspect its content and changes. Restoration rewrites the current shared document, so only users who hold the restore permission should perform it, and the server must enforce that permission.
To verify the integration, edit slide text, shapes, or slide order, wait for the collaboration confirmation, then inspect the history list and the version content. Reopen the application and restart the service to verify persistence. Restore an earlier version and confirm that another browser session receives the restored state.
If the list is empty, check whether history was recorded for this document, then check the document ID and the service URL. If versions are visible but restoration fails, check the restore permissions and the collaboration connection. Reading history also requires authorization, because older versions may contain data that has since been deleted.
Compare snapshots
To build a review screen or to pass changes to an AI agent, call compareUnitData(), or prepare the comparison once with prepareUnitComparison(). Register the History plugin for the product and import the Facade entry. Both beforeSnapshot and afterSnapshot must be fully materialized snapshots of the same unit. The comparison is read-only, requires no history service, and neither restores nor merges content.
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_SLIDE, 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)scopes lists the views that the comparison offers. Pass one scope to query() to filter the result without running the comparison again. A page returns 100 items by default and accepts up to 1,000. Use page.hasMore together with offset to retrieve the remaining items. summary still describes the whole comparison, even when the items are filtered. Check diagnostics.readiness and diagnostics.codes before treating a result as a complete comparison. For Node.js or CLI use without an editor, see the headless comparison API.
How is this guide?