Review finding 12.
The finding: the `renderEnvironment` option this branch added to
`updateBoundElements` (a9b2d2878) was passed only by the transform, and
since e0f198c15 not even by that (it calls `updateBoundArrow` directly),
so the option was dead while documenting that it "measures the labels of
the updated arrows". Meanwhile every editor path re-measured bound labels
with the default environment, ignoring the host's
`<Excalidraw renderEnvironment>` (its custom `textMetrics`), so a label
laid out with the host's metrics re-wrapped the first time its arrow was
touched.
The re-wrap itself predates this branch: master's `updateBoundElements`
never took an environment and called `handleBindTextResize(element,
scene, false)`, as `LinearElementEditor`'s point drag still did. Rather
than drop the dead option, this wires it (and the other label-measuring
editor paths) to the host's environment.
Reproduction: convert two rectangles A, B and an arrow bound to both,
labelled "aaaa bbbb cccc dddd eeee ffff", with
`convertToExcalidrawElements(..., { renderEnvironment })`, whose
`textMetrics.getLineWidth` is `text.length * 5`. Move B by 1px and call
`updateBoundElements(B, scene)` as the drag path does. In the editor:
render `<Excalidraw renderEnvironment={env}>` with the same scene and drag
or arrow-key nudge B, align A and B, undo/redo the drag, or drag the
arrow's point.
Failure case (this branch and master alike):
observed: "aaaa bbbb cccc dddd eeee ffff", width 145, becomes
"aaaa bbbb cccc dddd\neeee ffff", width 190
expected: unchanged, "aaaa bbbb cccc dddd eeee ffff", width 145
Cause: no editor caller passed `updateBoundElements` an environment, so
it called `updateBoundArrow` without one; `ElementsDelta`'s redraw,
`LinearElementEditor`'s point drag and `listMarker`'s re-numbering
likewise measured without one.
Fix: optional `renderEnvironment` threaded the way resize already does it
(a trailing param, or an option where the function takes an options bag):
- `updateBoundElements`: its existing option is now passed by the editor
(doc comment updated); `updateBindings` gains the same option and
forwards it. Both pass it to `updateBoundArrow`.
- drag: `dragSelectedElements` (new trailing param), from the selection tool.
- arrow-key nudge (App.tsx).
- align / distribute: `alignElements` / `distributeElements` (new trailing
param), from their actions.
- rotate/resize: the `updateBoundElements` calls in `transformElements`,
`rotateMultipleElements`, `resizeSingleElement`, `resizeMultipleElements`
now pass the environment they already had.
- sticky notes: `updateStickyNoteLayout` passes its `renderEnvironment` on
to its bound-arrow pass.
- undo/redo: `ApplyToOptions.renderEnvironment` reaches
`ElementsDelta.redrawElements` (both the bound-text redraw and the
bound-arrow pass); `History.undo/redo` and `HistoryDelta.applyTo` take
it, the history actions pass `app.renderEnvironment`, and
`App.applyDeltas` defaults to it.
- `LinearElementEditor` point drag: `handleBindTextResize` gets
`app.renderEnvironment`.
- list-marker re-numbering on duplicate (`advanceDuplicatedListMarkers`,
`applyListMarkerAdvances`, new trailing param): both its label redraw and
its free-text refresh.
- the remaining editor callers of `updateBoundElements` / `updateBindings`,
each of which can move a labelled arrow bound to the element: text
editing (App.text, textWysiwyg), duplicate, crop/uncrop, wrap/unwrap
(also its `redrawTextBoundingBox`), font/style/auto-resize actions,
element type conversion, and the Stats position/angle/dimension inputs
(`moveElement` gets a trailing param).
Left alone:
- `updateBindings`' arrow branch (`updateArrowBindings`): it only rebinds
the arrow's ends and measures no label.
- `transform.ts`: already measured with its environment (via
`updateBoundArrow`).
- callers that already passed `app.renderEnvironment` to
`redrawTextBoundingBox` / `handleBindTextResize` (resize, Stats font
size, font/bound-text actions, textWysiwyg submit, type conversion).
- `updateBoundElements` re-measures only arrow labels (its visitor skips
non-arrows), so no non-arrow container label path needed changing there.
- free-text measurement helpers called directly (`measureText`, `wrapText`,
`refreshTextDimensions`, ...) outside these bound-label paths: not part
of this finding.
Without the prop, `app.renderEnvironment` is the owner-window environment
with no `textMetrics`, so measurement still falls back to the global
provider or a canvas; single-window behaviour is unchanged (no snapshot
changes). All new params are optional, so external callers are unaffected.
Tests: a direct `updateBoundElements` test (packages/element) and editor
tests rendering `<Excalidraw renderEnvironment>` for drag, nudge, align,
undo/redo and arrow point drag; each fails without its path's change.
Excalidraw Editor | Blog | Documentation | Excalidraw+
An open source virtual hand-drawn style whiteboard.
Collaborative and end-to-end encrypted.
Features
The Excalidraw editor (npm package) supports:
- 💯 Free & open-source.
- 🎨 Infinite, canvas-based whiteboard.
- ✍️ Hand-drawn like style.
- 🌓 Dark mode.
- 🏗️ Customizable.
- 📷 Image support.
- 😀 Shape libraries support.
- 🌐 Localization (i18n) support.
- 🖼️ Export to PNG, SVG & clipboard.
- 💾 Open format - export drawings as an
.excalidrawjson file. - ⚒️ Wide range of tools - rectangle, circle, diamond, arrow, line, free-draw, eraser...
- ➡️ Arrow-binding & labeled arrows.
- 🔙 Undo / Redo.
- 🔍 Zoom and panning support.
Excalidraw.com
The app hosted at excalidraw.com is a minimal showcase of what you can build with Excalidraw. Its source code is part of this repository as well, and the app features:
- 📡 PWA support (works offline).
- 🤼 Real-time collaboration.
- 🔒 End-to-end encryption.
- 💾 Local-first support (autosaves to the browser).
- 🔗 Shareable links (export to a readonly link you can share with others).
We'll be adding these features as drop-in plugins for the npm package in the future.
Quick start
Note: following instructions are for installing the Excalidraw npm package when integrating Excalidraw into your own app. To run the repository locally for development, please refer to our Development Guide.
Use npm or yarn to install the package.
npm install react react-dom @excalidraw/excalidraw
# or
yarn add react react-dom @excalidraw/excalidraw
Check out our documentation for more details!
Contributing
- Missing something or found a bug? Report here.
- Want to contribute? Check out our contribution guide or let us know on Discord.
- Want to help with translations? See the translation guide.
Integrations
Who's integrating Excalidraw
Google Cloud • Meta • CodeSandbox • Obsidian Excalidraw • Replit • Slite • Notion • HackerRank • and many others
Sponsors & support
If you like the project, you can become a sponsor at Open Collective or use Excalidraw+.
Thank you for supporting Excalidraw
Last but not least, we're thankful to these companies for offering their services for free: