Skip to main content

Restore Utilities

Utilities for loading, restoring, and validating Excalidraw elements and application state from saved data.

Element Restoration

restoreElements

Restores elements from saved data, fixing inconsistencies and validating bindings.
readonly ExcalidrawElement[]
required
Elements to restore
ElementsMapOrArray
Existing local elements for context (e.g., for repairing arrow bindings)
boolean
default:"false"
Refresh text element dimensions
boolean
default:"false"
Repair arrow bindings and container relationships
boolean
default:"false"
Mark invisibly small elements as deleted
OrderedExcalidrawElement[]
Restored and validated elements with fractional indices
Example:

restoreElement

Restores a single element with proper type handling and migrations.
ExcalidrawElement
required
Element to restore
ElementsMap
required
Map of all elements being restored
ElementsMap
Map of existing elements for context
boolean
Whether to mark invisible elements as deleted
ExcalidrawElement | null
Restored element or null if invalid
What it does:
  • Migrates legacy properties (e.g., font, boundElementIds, strokeSharpness)
  • Normalizes dimensions and coordinates
  • Repairs line/arrow points
  • Validates and restores bindings
  • Handles text wrapping and dimensions
  • Restores image elements with proper status

App State Restoration

restoreAppState

Restores application state with default values and migrations.
Partial<AppState>
required
App state from saved data
Partial<AppState>
Local app state to merge with
AppState
Complete app state with all properties initialized
Example:
What it restores:
  • View state (zoom, scroll position)
  • UI state (sidebar, theme, grid)
  • Tool selection
  • Export settings
  • Collaboration state
  • Legacy property migrations

Library Restoration

restoreLibraryItems

Restores library items from saved data.
LibraryItem[]
required
Library items to restore
'published' | 'unpublished'
required
Default status for items without one
LibraryItem[]
Restored library items with valid elements
Example:

Version Management

bumpElementVersions

Bumps element versions relative to local elements (for conflict resolution).
readonly ExcalidrawElement[]
required
Elements to bump versions for
ElementsMapOrArray
Local elements to compare against
ExcalidrawElement[]
Elements with versions bumped where needed
Example:
When to use:
  • Importing files (to avoid conflicts with local elements)
  • Handling collaborative updates
  • Merging element collections

Data Serialization

serializeAsJSON

Serializes elements, app state, and files to JSON.
readonly ExcalidrawElement[]
required
Elements to serialize
Partial<AppState>
required
App state to serialize
BinaryFiles
required
Binary files to include
'local' | 'database'
required
Serialization type (affects what’s included)
string
JSON string with formatted Excalidraw data
Example:
Type differences:
  • "local": Includes files, export-ready app state
  • "database": Strips files, minimal app state for collaboration

serializeLibraryAsJSON

Serializes library items to JSON.
LibraryItem[]
required
Library items to serialize
string
JSON string with library data
Example:

Data Validation

isValidExcalidrawData

Validates if data is a valid Excalidraw document.
unknown
required
Data to validate
boolean
Whether data is valid Excalidraw format
Example:

Complete Restoration Example

See Also