Stable node identity and deterministic serialization before any diffable document format

Author: dannoteCreated Sep 25, 2026Updated Sep 25, 2026
Labelsenhancement

Problem

Any diffable or mergeable document format depends on two things OpenPencil does not provide yet: node identity that is stable across processes and unique across concurrent edits, and serialization that produces the same bytes for the same document. Until both hold, a text format diffs as noise and merges wrong, so choosing one is premature.

This came up in #751, where the suggestion was to pair the Storybook export with a git-diffable .pen file (#173). The format is the easy part; these two are the prerequisite.

Identity

generateId() in packages/scene-graph/src/index.ts is a process-local counter:

typescript
let nextLocalID = 1
export function generateId(): string {
  return `0:${nextLocalID++}`
}

The 0: prefix is Figma's sessionID (packages/kiwi/src/fig/guid.ts formats a GUID as sessionID:localID), hardcoded to zero. The session half is what makes concurrently created IDs distinct, so we keep the scheme and drop the part that does the work.

Consequences:

  • Two branches that each add a node both mint 0:7 for different nodes. Nothing in a merge can tell them apart.
  • A document rebuilt in a fresh process renumbers from 1, so identity does not survive regeneration and a diff shows unrelated nodes as changed.
  • Imported .fig nodes keep their original GUIDs, so a document mixes stable imported IDs with volatile locally minted ones.

SceneGraph.createNode does skip IDs already present in the loaded graph, so nothing collides within one session. The problem is only across sessions and branches.

Serialization

.fig export in packages/core/src/io/formats/fig/export.ts writes createdAt: new Date().toISOString() into the container metadata and embeds a rendered thumbnail, so saving the same document twice produces different bytes. Beyond that, a diffable format needs a documented order for object keys and for collections that are currently unordered, and fixed number formatting so equivalent values do not serialize differently.

What would need deciding

  • Whether IDs become globally unique at creation (UUID/ULID, or a real per-session sessionID), and how existing documents migrate.
  • Whether git merge or the existing CRDT (Yjs, src/app/collab/) is authoritative when both could apply. They are two different answers to the same question and should not both own it.
  • Whether the goal is a git-native text format at all, or structured node-tree diffs as review artifacts, which the roadmap already lists and diff_create / diff_jsx partly cover.

Out of scope

A specific file format. .pen in particular is read-only today and a subset of the scene graph (vector geometry as an SVG path string, blend modes imported as NORMAL, no mask or boolean-op representation), so it is not a candidate until both problems above are solved and the format question is decided on its own terms.