Skip to content

feat(tldraw): add headless RoomSnapshot to .tldr conversion#8590

Draft
steveruizok wants to merge 7 commits into
mainfrom
feat/room-snapshot-to-tldr
Draft

feat(tldraw): add headless RoomSnapshot to .tldr conversion#8590
steveruizok wants to merge 7 commits into
mainfrom
feat/room-snapshot-to-tldr

Conversation

@steveruizok
Copy link
Copy Markdown
Collaborator

In order to turn a sync-worker RoomSnapshot JSON blob (as written to the R2 rooms-history-ephemeral bucket) into a standard .tldr file without spinning up a live Editor or touching the DOM, this PR adds a pure roomSnapshotToTldrawFile helper in the tldraw package plus a small tsx-based CLI in the sync-worker. Closes #8589.

The helper:

  • Keeps only document-persistent record types (document, page, shape, asset, binding) and drops session-scoped records (instance, instance_page_state, instance_presence, camera, pointer, user).
  • Prunes asset records that aren't referenced by a surviving shape.
  • Uses type-only imports so it stays a zero-side-effect pure function — usable from Node scripts, CFW debugging tools, or anything else that has a snapshot in hand.

The CLI (apps/dotcom/sync-worker/scripts/snapshot-to-tldr.ts) reads a RoomSnapshot JSON from stdin or --in <path>, runs it through the helper, and writes the result to stdout or --out <path>. It imports the helper directly from its source file so we don't load the full tldraw package (React, editor, styles) just to transform JSON.

Asset URL rewriting / data-URI inlining is explicitly out of scope, since that needs a DOM or network. Consumers that want inlined assets can re-import the file into an editor and use the existing serializeTldrawJson path.

API changes

  • Added roomSnapshotToTldrawFile(snapshot) — pure conversion from a RoomSnapshot-shaped input to a TldrawFile.
  • Added RoomSnapshotLike interface — a structural mirror of @tldraw/sync-core's RoomSnapshot, used as the helper's input type so that tldraw does not need to depend on sync-core. Any real RoomSnapshot is structurally assignable to it.

Change type

  • feature

Test plan

  1. Pipe a real bucket snapshot JSON through the CLI:
    yarn tsx apps/dotcom/sync-worker/scripts/snapshot-to-tldr.ts --in snapshot.json --out room.tldr
    
  2. Open the resulting .tldr in the tldraw editor (yarn dev, File → Open). Confirm shapes, pages, and bindings load with no parse errors.
  • Unit tests

Release notes

  • Add roomSnapshotToTldrawFile, a pure helper that converts a sync RoomSnapshot JSON blob into a .tldr-compatible TldrawFile without needing a live editor or DOM.

Code changes

Section LOC change
Core code +65 / -0
Tests +159 / -0
Automated files +22 / -0
Apps +59 / -0

Adds a pure `roomSnapshotToTldrawFile` helper that converts a
`RoomSnapshot` (as produced by the sync server) into a `TldrawFile`
without needing a live editor, DOM, or network access. Session-scoped
records are dropped and orphan assets are pruned.

Also adds a small tsx-based CLI at `apps/dotcom/sync-worker/scripts/snapshot-to-tldr.ts`
that reads a `RoomSnapshot` JSON from stdin/`--in` and writes the
resulting `.tldr` JSON to stdout/`--out`, for debugging bucket
snapshots.

Closes #8589
@huppy-bot huppy-bot Bot added the feature New feature label Apr 20, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
examples Ready Ready Preview Apr 20, 2026 11:30am
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
analytics Ignored Ignored Preview Apr 20, 2026 11:30am
chat-template Ignored Ignored Preview Apr 20, 2026 11:30am
tldraw-docs Ignored Ignored Preview Apr 20, 2026 11:30am
tldraw-shader Ignored Ignored Preview Apr 20, 2026 11:30am
workflow-template Ignored Ignored Preview Apr 20, 2026 11:30am

Request Review

@steveruizok
Copy link
Copy Markdown
Collaborator Author

@copilot review

Copilot AI review requested due to automatic review settings April 20, 2026 11:23
@steveruizok steveruizok review requested due to automatic review settings April 20, 2026 11:23
@huppy-bot
Copy link
Copy Markdown
Contributor

huppy-bot Bot commented Apr 20, 2026

Hey, thanks for your pull request! Before we can merge your PR, you will need to sign our Contributor License Agreement by posting a comment that reads:

I have read and agree to the Contributor License Agreement.

Copilot AI review requested due to automatic review settings April 20, 2026 11:25
@steveruizok steveruizok review requested due to automatic review settings April 20, 2026 11:25
@vercel vercel Bot temporarily deployed to Preview – workflow-template April 20, 2026 11:27 Inactive
@vercel vercel Bot temporarily deployed to Preview – tldraw-shader April 20, 2026 11:27 Inactive
@vercel vercel Bot temporarily deployed to Preview – chat-template April 20, 2026 11:27 Inactive
Copilot AI review requested due to automatic review settings April 20, 2026 11:28
@steveruizok steveruizok review requested due to automatic review settings April 20, 2026 11:28
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

@copilot review

Self-review done. Found and fixed the main issue: duplicated pruneUnusedAssets logic between file.ts and roomSnapshotToTldrawFile.ts. Now pruneUnusedAssets is exported as @internal from file.ts and reused in the new helper. See commit c60f040.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a headless utility to convert RoomSnapshot JSON to a .tldr file

2 participants