perf(arrows): use reactive hooks for arrow handle display and editing state (#8167)
Previously, any change to any shape would cause all arrows to render. We should be careful with any reactive call to getOnlySelectedShape, because it will call when the selected shape is changing. If we need to react to a change in which shape is selected, we should use getOnlySelectedShapeId.
In order to reduce unnecessary re-renders of arrow components, this PR changes a call to
getOnlySelectedShape()?.idtogetOnlySelectedShapeId.To avoid an extra render when editing shape changes, it also wraps
shouldDisplayHandlesandisEditingchecks inuseValuehooks for finer-grained reactivity. It also refactorsgetArrowLabelPositionto acceptisEditingas a parameter rather than computing it internally, avoiding redundant reactive lookups.Change type
improvementTest plan
- Create arrows between shapes
- Select an arrow — handles should display correctly
- Double-click an arrow label to edit — label positioning should work as before
- Deselect and verify handles disappear
- Unit tests
- End to end tests
Release notes
- Improve arrow component rendering performance with finer-grained reactivity
[!NOTE] Medium Risk Touches arrow rendering reactivity (selection/editing state and label positioning), so regressions could show up as missing handles or mispositioned labels, but the changes are localized to UI/perf code.
Overview Reduces unnecessary arrow re-renders by switching arrow component state derivations to fine-grained
useValuesubscriptions (e.g.shouldDisplayHandles, selection, and editing state) and by preferringgetOnlySelectedShapeId()overgetOnlySelectedShape()where only the id is needed.Refactors
getArrowLabelPositionto accept an explicitisEditingflag and updates all call sites (geometry, component render, and SVG export) to avoid redundant reactive lookups when computing label bounds. Also updates touch-end handling inuseCanvasEventsto useeditor.getEditingShapeId().Written by Cursor Bugbot for commit e04558e8f0f3f8a0fdf8e869eb1ce3d3864b1658. This will update automatically on new commits. Configure here.
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802032778号
Build infinite canvas apps in React with the tldraw SDK.
Docs · Examples · Starter kits
Feature highlights
tldraw provides a feature-complete infinite canvas engine designed to be the foundation for any canvas app. Create custom shapes, tools, bindings and UI components for a custom experience. Use the default whiteboarding tool set or use the library’s primitives to build entirely new shapes and interactions.
@tldraw/syncQuick start
Install the tldraw package:
Then, use the
<Tldraw />component in your React app:Starter kits
Starter kits provide the custom shapes, tools, and user interface needed for common applications. Each kit is MIT-licensed. Hack together a prototype, build out an app on top, or reference the code in a larger project.
Start building with:
@tldraw/syncand Cloudflare Durable Objects, the same stack behind tldraw.comLocal development
The development server runs the examples app at
localhost:5420. Clone the repo, then enable corepack for the correct yarn version:Install dependencies and start the dev server:
Community
Contributing
See our contributing guide to learn about contributing to tldraw.
License
The tldraw SDK is provided under the tldraw license. You can use the SDK freely in development. Production use requires a license key. Visit tldraw.dev to learn more.
Trademarks
Copyright (c) 2024-present tldraw Inc. The tldraw name and logo are trademarks of tldraw.
Please see our trademark guidelines for info on acceptable usage.
Contributors
Star history