Skip to content

fix(draw): prevent zero scaleX/scaleY on draw and highlight shapes#8067

Merged
ds300 merged 3 commits intomainfrom
fix-draw-shape-zero-scale
Feb 23, 2026
Merged

fix(draw): prevent zero scaleX/scaleY on draw and highlight shapes#8067
ds300 merged 3 commits intomainfrom
fix-draw-shape-zero-scale

Conversation

@ds300
Copy link
Copy Markdown
Collaborator

@ds300 ds300 commented Feb 23, 2026

Closes #7997

When resizing a draw or highlight shape to zero width or height, Box.Resize returns scaleX=0 or scaleY=0. The onResize handlers in DrawShapeUtil and HighlightShapeUtil multiplied this directly into the shape's scaleX/scaleY props, producing 0, which violates the nonZeroFiniteNumber validator and throws a ValidationError.

This PR guards against that by keeping the existing scale value when the computed result would be 0.

Change type

  • bugfix

Test plan

  1. Create a draw shape on the canvas
  2. Select it and resize by dragging an edge handle until the shape collapses to zero width or height
  3. Verify no validation error is thrown
  • Unit tests

Release notes

  • Fixed a crash when resizing draw or highlight shapes to zero width or height.

Made with Cursor


Note

Low Risk
Small, localized guard in resize logic plus tests; behavior only changes for the edge case of collapsing a shape to zero size.

Overview
Prevents DrawShapeUtil and HighlightShapeUtil from applying a resize operation that would result in scaleX or scaleY becoming 0; the onResize handler now returns undefined (no-op) in that case.

Adds unit coverage for DrawShapeUtil to ensure resizing to zero width/height leaves scale unchanged and that negative scale (flipping) is preserved. Updates the generated API report to reflect the new onResize return type ({ props: ... } | undefined).

Written by Cursor Bugbot for commit 2738894. This will update automatically on new commits. Configure here.

When resizing a draw or highlight shape to zero width or height,
Box.Resize returns scaleX=0 or scaleY=0. Multiplying this into the
shape's scaleX/scaleY props produces 0, which violates the
nonZeroFiniteNumber validator and throws a ValidationError.

Closes #7997

Co-authored-by: Cursor <[email protected]>
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
examples Ready Ready Preview Feb 23, 2026 10:20am
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
analytics Ignored Ignored Preview Feb 23, 2026 10:20am
chat-template Ignored Ignored Preview Feb 23, 2026 10:20am
tldraw-docs Ignored Ignored Preview Feb 23, 2026 10:20am
tldraw-shader Ignored Ignored Preview Feb 23, 2026 10:20am
workflow-template Ignored Ignored Preview Feb 23, 2026 10:20am

Request Review

@huppy-bot huppy-bot bot added the bugfix Bug fix label Feb 23, 2026
@huppy-bot
Copy link
Copy Markdown
Contributor

huppy-bot bot commented Feb 23, 2026

Hey! 👋

This PR contains changes to api-report.api.md, which means you've made some API changes. To help reviewers and SDK users understand the impact, please add a "### API changes" section to your PR description.

Here's an example:

### API changes
- Describe what API changes were made
- List any breaking changes
- Note any new or removed parameters

Once you add this section, the check will pass automatically!

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.


override onResize(shape: TLDrawShape, info: TLResizeInfo<TLDrawShape>) {
const { scaleX, scaleY } = info
if (scaleX === 0 || scaleY === 0) return
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resize ignores other axis when collapsed

Medium Severity

onResize now returns undefined when either info.scaleX or info.scaleY is 0, which drops the non-zero axis resize too. If a resize produces { scaleX: 0, scaleY: 2 } (or vice versa), the shape becomes a full no-op instead of applying the valid axis while preserving the existing scale on the collapsed axis.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intentional

@ds300 ds300 added this pull request to the merge queue Feb 23, 2026
Merged via the queue into main with commit faef145 Feb 23, 2026
18 of 19 checks passed
@ds300 ds300 deleted the fix-draw-shape-zero-scale branch February 23, 2026 11:25
steveruizok added a commit that referenced this pull request Feb 27, 2026
Add 12 new entries from PRs merged since v4.4.0:
- Featured: click-through on transparent image pixels (#7942)
- API: enum-to-const-object refactor (#8084)
- Improvements: SVG sanitizer (#7896), save-on-blur (#8037)
- Bug fixes: cross-origin download (#8090), zero-size draw (#8067),
  rich text toolbar cleanup (#8050), zoom threshold (#8040),
  selection foreground fallback (#8011), sticky note SVG shadow (#7934),
  arrow frame clamping (#7932), zero pressure draw (#5693)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Draw shape validation fails when scaleY is zero

1 participant