Skip to content

canvas: a two-finger pan over a board no longer goes back a page - #59

Merged
Jing-yilin merged 1 commit into
mainfrom
fix-swipe-back
Sep 9, 2026
Merged

canvas: a two-finger pan over a board no longer goes back a page#59
Jing-yilin merged 1 commit into
mainfrom
fix-swipe-back

Conversation

@Jing-yilin

Copy link
Copy Markdown
Contributor

The bug

Cursor over a board on the canvas, two-finger swipe left to pan — the browser goes back a page.

Root cause

A wheel event whose target is inside an <iframe> never reaches the parent document. tldraw's own answer to this gesture is to preventDefault the wheel that reaches its container (useGestureEvents, bound with {passive: false}) — over a board, that call never happens, and the browser reads the horizontal component as history navigation. The page's own overscroll-behavior: none in canvas/src/index.css cannot reach in: overscroll chains one frame at a time, and a board's document declares nothing. tldraw sets that property only on its own UI panels, never on the canvas, for the same reason — the canvas relies on the wheel handler.

be13507 fixed the case it could see, by putting the board iframe behind its container (zIndex: -1), which also does the second half of the job: it lets the pan actually reach tldraw. That line stays. But it only applies to a board that is not being edited, and it is not available to the other two iframes — the inspector's preview is meant to take input, and the link card's cover sits on an opaque white background, so a negative z-index there would paint it out of existence.

The fix

What all three iframes share is the HTML, so the fix goes there: loadCanvasFileHtml appends <style>html{overscroll-behavior:none}</style> to every board. One place, and a fourth iframe cannot miss it.

Appended rather than spliced before </body>: 37 of the 180 boards emit none, and a tag put before the doctype would drop the board into quirks mode. A trailing <style> is parsed into the body, and the inspector agent already skips STYLE elements (inspectorAgent.ts:292), so this adds no layer to the inspector.

Verified

bun run lint, bun run test (85 passing, one new), bun run build. scripts/bump-version.sh --check: all 7 agree on 1.1.0.

Checklist

  • No ref-*.html, assets/refs/ or other third-party captures are in this PR.
  • No canvas folder changed.
  • User-visible, so it has its ## Unreleased line.

A wheel event whose target is inside an iframe never reaches the parent
document. tldraw stops this gesture by calling preventDefault on the wheel that
reaches its container (useGestureEvents, bound passive:false), so over a board
that call never happens and the browser takes the horizontal component as a
back navigation. The page's own overscroll-behavior: none cannot help: overscroll
chains one frame at a time, and a board's document declares nothing.

be13507 fixed the case it could see by putting the board iframe behind its
container, which also lets the pan reach tldraw. That line stays — it does the
other half of the job — but it only applies to a board that is not being edited,
and it is not available to the other two iframes: the inspector's preview is
meant to take input, and the link card's cover sits on an opaque background, so
a negative z-index there would paint it out of existence.

What all three share is the HTML, so the fix goes there: every board is loaded
with a style tag that stops overscroll in its own document. Appended rather than
spliced, because 37 of the 180 boards emit no </body> and a tag before the
doctype would mean quirks mode.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying super-prototyping with  Cloudflare Pages  Cloudflare Pages

Latest commit: a2c90e1
Status: ✅  Deploy successful!
Preview URL: https://a8751d2d.super-prototyping.pages.dev
Branch Preview URL: https://fix-swipe-back.super-prototyping.pages.dev

View logs

@Jing-yilin
Jing-yilin merged commit 1846473 into main Sep 9, 2026
8 checks passed
@Jing-yilin
Jing-yilin deleted the fix-swipe-back branch September 9, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant