Skip to content

add tldraw5 with import/export .tldraw offline support - #35

Open
chee wants to merge 13 commits into
mainfrom
tldraw-4.5.12
Open

add tldraw5 with import/export .tldraw offline support#35
chee wants to merge 13 commits into
mainfrom
tldraw-4.5.12

Conversation

@chee

@chee chee commented Jul 30, 2026

Copy link
Copy Markdown
Member
  • also upgrades and unlists tldraw4
  • has a one-way migrator for tldraw4->tldraw5 (in the tldraw5 package)

the tldraw offline support is interesting. because .tldraw has javascript files in it, and the javascript files can add shapes and features, i've had to provide a different initialization process. it runs config.js first if it's there, to set up shapes etc.

this is also a place we could load patchwork tldraw plugins, if we wanted to have that as a concept. defaulting to some that we think are core to the system (being able to embed a patchwork tool?), and allowing more to be added to a given tldrawing (similar to how the /plugins works in Chat now)

so, i think it might be cool to do that as part of this PR. removing the custom code we have for patchwork-view and patchwork dnd and add those as plugins this package also exports and loads by default.

how would we want to implement that? a cute thing might be to initialize new tldraw5s with a config.js that does:

import {getRegistry} from "@inkandswitch/patchwork-plugins"

let plugins = getRegistry("tldraw5:config")
let patchworkView = plugins.get("shape:patchwork-view")

export default function (ctx) {
  return patchworkView(ctx)
}

and a similar main.js

import {getRegistry} from "@inkandswitch/patchwork-plugins"

let plugins = getRegistry("tldraw5:main")
let dnd = plugins.get("dnd")

export default function (ctx) {
  dnd(ctx)
}

though then they wouldn't work when exported to a .tldraw file (without stripping this away*) so maybe better we inject a little plugin system more like Chat and pop it in the menu

*or actually making patchwork-view,plugins,etc work in tldraw offline, which would be sick

chee and others added 3 commits July 31, 2026 00:50
@tldraw/tldraw was pinned to 4.3.1 while tldraw resolved to ^4.3.1 →
4.5.12, so two copies were installed. Nothing imports "tldraw" directly
(the code and main.css both use @tldraw/tldraw), and @tldraw/tldraw
depends on the matching tldraw version, so the direct dependency only
ever produced skew.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@patchcrow

patchcrow commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

✅ Patchwork glance ready

https://patchwork-preview-35--patchwork-base.netlify.app

Patchwork from inkandswitch/patchwork.inkandswitch.com, packages from this PR at 8cf7213.

build-info.json

chee and others added 10 commits July 31, 2026 03:40
Presence was keyed by contact URL, so a user's own tabs collided and
their cursors flickered between positions. usePresence keys peers by
peerId, which is unique per session.

Also hide the cursor while the window is unfocused. The record keeps
being broadcast with a null cursor rather than withdrawn: tldraw only
writes pointer updates while it can see a collaborator, so withdrawing
ours would freeze the other side's cursor instead.

Pin automerge-repo and automerge-repo-react-hooks to the same release.
The mismatch gave the hooks package its own copy of automerge-repo,
whose DocHandle is nominally incompatible with ours.
…ches

Replaying patch mechanics required modeling every patch shape automerge can
emit, and gaps (nested del, conflict) silently diverged the store from the
doc until reload — e.g. remote draw strokes rendering as closed shapes. Now
patches only identify which records changed and their contents are rebuilt
from the post-change doc, making the doc the single source of truth.
tldraw keeps the last pointer position, so peers saw the cursor frozen where
it left the canvas. Gate the live broadcast on hover over the tool element in
addition to window focus, reusing the blur behavior (record stays, cursor
cleared) so collaborator counts don't flicker.
Same changes as Paul's tldraw4 work: usePresence instead of the
awareness hooks, per-session userId, records rebuilt from the doc
instead of replaying patches, and the cursor hidden when the pointer
leaves the tool. tldraw5 keeps its TLUser-derived presence, minus the
explicit instanceId now that peers key records by peerId.

Co-Authored-By: Paul Sonnentag <paul.sonnentag@gmail.com>
@chee
chee marked this pull request as ready for review July 31, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants