add tldraw5 with import/export .tldraw offline support - #35
Open
chee wants to merge 13 commits into
Open
Conversation
@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>
Collaborator
✅ Patchwork glance readyhttps://patchwork-preview-35--patchwork-base.netlify.appPatchwork from |
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
marked this pull request as ready for review
July 31, 2026 20:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-viewand 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:
and a similar main.js
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