Skip to content

[pull] main from tldraw:main#540

Merged
pull[bot] merged 2 commits into
code:mainfrom
tldraw:main
May 8, 2026
Merged

[pull] main from tldraw:main#540
pull[bot] merged 2 commits into
code:mainfrom
tldraw:main

Conversation

@pull

@pull pull Bot commented May 8, 2026

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

Bumps `next` from `15.5.15` to `15.5.16` to pick up fixes for the
React/Next.js vulnerabilities disclosed in the [Cloudflare advisory of
2026-05-06](https://developers.cloudflare.com/changelog/post/2026-05-06-react-nextjs-vulnerabilities/).

Affected packages in this repo:

- `apps/docs`
- `templates/chat`
- `templates/nextjs`

Plain `react` / `react-dom` are not flagged — the advisory only names
`react-server-dom-{webpack,parcel,turbopack}`, none of which are in our
lockfile.

After merge, add `docs-hotfix-please` to redeploy docs. Templates
publish only as part of an SDK release or via a manual run of the
`Publish templates` workflow.

### Change type

- [x] `other`

### Test plan

- CI passes (`yarn typecheck`, `yarn lint-current` clean locally)
- Docs site builds with `next@15.5.16`

### Release notes

- Internal-only: dependency bump for security advisory.

### Code changes

| Section         | LOC change |
| --------------- | ---------- |
| Documentation   | +1 / -1    |
| Templates       | +2 / -2    |
| Config/tooling  | +44 / -44  |
In order to keep `editor.getRenderingShapes()` cheap on busy canvases,
this PR caches the sort permutation by id. When the set of ids on the
page hasn't changed since the last call (the common case while drawing —
only props change, not the id set), we skip `Array.sort(sortById)` and
place each entry at its known sorted position in O(N) instead of O(N log
N).

Tracing on Chrome OS at 300 shapes showed `sortById` self-time at ~2.3
ms per call, ~70 ms/sec during drawing. After this change, the same call
takes ~0.1 ms on the cache-hit path (~23× faster).

Stacks with the other in-flight perf work:
- #8778 — incremental b64 encode and prefix-decode cache
- spatial index epoch + `notVisibleShapes` short-circuit (separate PR)

### Correctness

`sortById` is a deterministic, stateless string comparator on shape ids.
The sorted order of an array is uniquely determined by its set of ids
(ids are unique within a page). So if the cached `Map<id,
sortedPosition>` has the same size as the new array and every new id is
present in the cache, the cached permutation produces exactly the same
result as `Array.sort(sortById)`. If any id is missing, or the size
differs, we fall through to the slow path: full sort, rebuild cache.

### Change type

- [x] `improvement`

### Test plan

1. Draw, drag, and select shapes on a page with many shapes (300+);
ordering of overlapping shapes should be unchanged.
2. Add and delete shapes; the sort cache rebuilds on the first call
after the id set changes.
3. Check that `<iframe>`-style shapes (e.g. embeds) don't re-mount when
sibling shapes update — the DOM-key stability is the whole reason for
the sort, and the cache must preserve it.

- [x] Unit tests

### Release notes

- Faster pointer events on busy canvases — `getRenderingShapes()` skips
its sort step when only shape props (not the id set) have changed.

### Code changes

| Section         | LOC change |
| --------------- | ---------- |
| Core code       | +31 / -1   |
@pull pull Bot locked and limited conversation to collaborators May 8, 2026
@pull pull Bot added the ⤵️ pull label May 8, 2026
@pull pull Bot merged commit 2eb9f83 into code:main May 8, 2026
@pull pull Bot had a problem deploying to bemo-canary May 8, 2026 15:13 Failure
@pull pull Bot had a problem deploying to deploy-production May 8, 2026 15:13 Failure
@pull pull Bot had a problem deploying to vsce publish May 8, 2026 15:13 Failure
@pull pull Bot had a problem deploying to deploy-staging May 8, 2026 15:13 Error
@pull pull Bot had a problem deploying to deploy-staging May 8, 2026 15:13 Error
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant