Skip to content

Commit 6c910a4

Browse files
committed
fix(pdf-server): clear pinch transform in same frame as canvas resize
commitPinch cleared the CSS transform BEFORE renderPage's first await — for one frame the page snapped back to the old rendered size, then jumped forward when the canvas resized. renderPage now clears the transform immediately after setting canvas.style.width/ height, so the size handoff is atomic. Also bump the wheel settle timer 150→200ms; slow trackpad pinches can leave >150ms gaps and would commit mid-gesture.
1 parent c45d034 commit 6c910a4

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

examples/pdf-server/src/mcp-app.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,6 +3048,11 @@ async function renderPage() {
30483048
// Set display size in CSS pixels
30493049
canvasEl.style.width = `${viewport.width}px`;
30503050
canvasEl.style.height = `${viewport.height}px`;
3051+
// If a pinch preview transform is on .page-wrapper, drop it in the same
3052+
// frame as the canvas resize. Clearing earlier (in commitPinch, before
3053+
// the await getPage() above) snaps the page back to the old size for
3054+
// one frame; clearing later double-applies the scale until render ends.
3055+
pageWrapperEl.style.transform = "";
30513056

30523057
// Scale context for retina
30533058
ctx.scale(dpr, dpr);
@@ -3778,11 +3783,16 @@ function updatePinch(nextScale: number) {
37783783
}
37793784

37803785
function commitPinch() {
3781-
pageWrapperEl.style.transform = "";
37823786
pageWrapperEl.style.transition = "";
3783-
if (Math.abs(previewScale - scale) < 0.01) return; // dead-zone, no-op
3787+
if (Math.abs(previewScale - scale) < 0.01) {
3788+
// Dead-zone — no re-render. Clear here since renderPage won't run.
3789+
pageWrapperEl.style.transform = "";
3790+
return;
3791+
}
37843792
userHasZoomed = true;
37853793
scale = previewScale;
3794+
// renderPage clears the transform in the same frame as the canvas
3795+
// resize (after its first await) so there's no snap-back.
37863796
renderPage().then(scrollSelectionIntoView);
37873797
}
37883798

@@ -3805,10 +3815,12 @@ canvasContainerEl.addEventListener(
38053815
// pinch out then back lands where you started.
38063816
updatePinch(previewScale * Math.exp(-e.deltaY * 0.01));
38073817
if (pinchSettleTimer) clearTimeout(pinchSettleTimer);
3818+
// 200ms — slow trackpad pinches can leave >150ms gaps between wheel
3819+
// events, which would commit-then-restart and feel steppy.
38083820
pinchSettleTimer = setTimeout(() => {
38093821
pinchSettleTimer = null;
38103822
commitPinch();
3811-
}, 150);
3823+
}, 200);
38123824
return;
38133825
}
38143826

0 commit comments

Comments
 (0)