Skip to content

fix(draw): guard against zero pressure pointer events#5693

Merged
steveruizok merged 4 commits intomainfrom
david/int-1135-handle-pen-pressures-of-0
Feb 13, 2026
Merged

fix(draw): guard against zero pressure pointer events#5693
steveruizok merged 4 commits intomainfrom
david/int-1135-handle-pen-pressures-of-0

Conversation

@ds300
Copy link
Copy Markdown
Collaborator

@ds300 ds300 commented Mar 19, 2025

We had a user of a Xiaomi tablet report that they couldn't draw anything, and after much debugging we discovered that their tablet was setting the pen pressure to 0 for every point. Interesting choice.

This PR accounts for that in two ways:

  1. If the first point on a line has a pressure of 0, assume the device is broken and use pressure simulation instead of real pressure values.
  2. In getStrokePoints, clamp any zero/near-zero pressure points to a minimum value (0.025) instead of stripping them. Previously, low-pressure points were stripped from the start and end of the stroke, which could remove most or all of the points when a device reports z=0 throughout. The old code had a 50% revert heuristic as a safety net, but reverting still left zero-pressure data in the points, producing near-invisible stroke sections. Clamping is simpler and also fixes existing saved documents with z=0 data at render time.

Change type

  • bugfix

Test plan

  1. Use a device that reports 0 pressure (or simulate it in code)
  2. Verify that draw shapes are still created using simulated pressure
  • Unit tests (if present)
  • End to end tests (if present)

Release notes

  • Tweaked the draw shape svg rendering to be more forgiving for tablets which report low pen pressures.
  • Fix an edge case where some tablets report 0 pressure for all pointer move events.

Note

Low Risk
Small, localized changes to pressure handling in the drawing pipeline; primary risk is subtle stroke-thickness behavior changes for low-pressure inputs.

Overview
Fixes an edge case where some tablets report z=0 pen pressure, which could prevent drawing or create near-invisible strokes.

In Drawing.startShape, pen input is no longer treated as pen/stylus when the initial pressure is 0, causing the tool to use the non-pen (simulated) pressure path. In getStrokePoints, replaces start/end low-pressure stripping with clamping all pressures to a minimum (0.025) when not simulating pressure, preserving points and improving rendering of existing z=0 stroke data.

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

@ds300 ds300 requested a review from steveruizok March 19, 2025 09:10
@linear
Copy link
Copy Markdown

linear bot commented Mar 19, 2025

@huppy-bot huppy-bot bot added the other ⚙️ Changes that don't affect SDK users, e.g. internal or .com changes label Mar 19, 2025
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 19, 2025

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

Project Deployment Actions Updated (UTC)
examples Ready Ready Preview Feb 13, 2026 8:40am
tldraw-docs Ready Ready Preview Feb 13, 2026 8:40am
4 Skipped Deployments
Project Deployment Actions Updated (UTC)
analytics Ignored Ignored Preview Feb 13, 2026 8:40am
chat-template Skipped Skipped Feb 13, 2026 8:40am
tldraw-shader Skipped Skipped Feb 13, 2026 8:40am
workflow-template Skipped Skipped Feb 13, 2026 8:40am

Request Review

@ds300
Copy link
Copy Markdown
Collaborator Author

ds300 commented Mar 19, 2025

hmm testing with light strokes on a samsung tablet it can sometimes end a line with a 0 pressure point, which suggests that it might also sometimes start a line with a 0 pressure point. or if not samsung then maybe other tablets.

@ds300
Copy link
Copy Markdown
Collaborator Author

ds300 commented Mar 19, 2025

also looking at the lines the affected user drew with this pr's preview deploy, all the points still have z: 0 and it's not doing pressure simulation for some reason (should be 0.5 and pressure simulation) so i must not have been faking their devices behavior correctly while testing.

this.isPenOrStylus = isPen || (z > 0 && z < 0.5) || (z > 0.5 && z < 1)
// if z === 0 on the initial point, treat this pen as a mouse because it's likely a broken pen
// or a broken OS.
this.isPenOrStylus = (isPen && z !== 0) || (z > 0 && z < 0.5) || (z > 0.5 && z < 1)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We'd need to test this across browsers. IIRC Safari (?) reports zero pressure in unusual scenarios, such as at the start of lines when using the Apple Pencil. I vaguely remember removing a zero check.

I actually wouldn't mind a "Input device: auto / mouse / pen" setting, similar to the "mousewheel behavior". Better input controls have been on my list forever.

@steveruizok
Copy link
Copy Markdown
Collaborator

Do we still want to work on this?

@steveruizok steveruizok added the bugfix Bug fix label Jan 2, 2026
@steveruizok steveruizok changed the title Draw shape: Guard against zero pressure pointer events fix(draw): guard against zero pressure pointer events Jan 2, 2026
@steveruizok steveruizok added the sdk Affects the tldraw sdk label Jan 2, 2026
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Feb 13, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
branching-chat-template 592854d Commit Preview URL

Branch Preview URL
Feb 13 2026, 08:04 AM

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
🔵 In progress
View logs
image-pipeline-template 592854d Feb 13 2026, 08:00 AM

Replace the strip-from-start/end logic with a simple pressure clamp.
Some pens or OSes report z=0 while the pen is touching, and stripping
those points could remove most of the stroke. Clamping to a minimum
pressure preserves all input points and also fixes existing saved
documents with z=0 data.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@steveruizok
Copy link
Copy Markdown
Collaborator

I replaced the strip-and-revert approach in getStrokePoints with a simpler pressure clamp.

Why: The original approach (strip low-pressure points from start/end, then revert if >50% were stripped) had two issues:

  • The 50% threshold is arbitrary and fragile
  • Reverting puts back points with z=0, which still produce near-zero-width stroke sections downstream in setStrokePointRadii — so the stroke doesn't vanish entirely, but it looks broken

What changed: Instead of stripping points and potentially reverting, we now clamp any point with z < 0.025 up to 0.025. This means:

  • No points are ever removed, so there's no risk of stripping most of the stroke
  • Zero-pressure points render as very thin (minimum pressure) rather than invisible
  • Existing saved documents with z=0 data get fixed at render time
  • Legitimate light-pressure strokes still work naturally — they just can't go below 2.5%

The isPenOrStylus guard on the first point (Change 1) is kept as-is — if the pen reports zero pressure from the start, falling back to simulated pressure mode is the right call.

Merged via the queue into main with commit cfef7eb Feb 13, 2026
15 checks passed
@steveruizok steveruizok deleted the david/int-1135-handle-pen-pressures-of-0 branch February 13, 2026 08:44
github-merge-queue bot pushed a commit that referenced this pull request Feb 14, 2026
In order to keep the release notes current for the upcoming SDK release,
this PR updates `apps/docs/content/releases/next.mdx` with documentation
for recently merged changes.

### Changes

- Add "What's new" section for the experimental `onDropOnCanvas` canvas
drop handler (#7911)
- Add API change entry for `TldrawOptions.experimental__onDropOnCanvas`
- Update release intro paragraph to mention the new drop handler
- Add bug fix entry for CJS compatibility regression from ESM-only rbush
(#7905)
- Add bug fix entry for zero pen pressure on tablets affecting draw
shapes (#5693)

### Change type

- [x] `docs`

### Test plan

- [ ] Verify the release notes render correctly on the docs site

### Release notes

- Update next release notes with experimental canvas drop handler, CJS
fix, and tablet pressure fix
huppy-bot bot pushed a commit that referenced this pull request Feb 14, 2026
In order to keep the release notes current for the upcoming SDK release,
this PR updates `apps/docs/content/releases/next.mdx` with documentation
for recently merged changes.

### Changes

- Add "What's new" section for the experimental `onDropOnCanvas` canvas
drop handler (#7911)
- Add API change entry for `TldrawOptions.experimental__onDropOnCanvas`
- Update release intro paragraph to mention the new drop handler
- Add bug fix entry for CJS compatibility regression from ESM-only rbush
(#7905)
- Add bug fix entry for zero pen pressure on tablets affecting draw
shapes (#5693)

### Change type

- [x] `docs`

### Test plan

- [ ] Verify the release notes render correctly on the docs site

### Release notes

- Update next release notes with experimental canvas drop handler, CJS
fix, and tablet pressure fix
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 other ⚙️ Changes that don't affect SDK users, e.g. internal or .com changes sdk Affects the tldraw sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants