Skip to content

[3.0 WB] fix viewer's unfaithful slide position by panning - #25691

Closed
hiroshisuga wants to merge 3 commits into
bigbluebutton:v3.0.x-developfrom
hiroshisuga:patch-78
Closed

hiroshisuga wants to merge 3 commits into
bigbluebutton:v3.0.x-developfrom
hiroshisuga:patch-78

Conversation

@hiroshisuga

@hiroshisuga hiroshisuga commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR changes the calculation of tlCamPercent from Math.round() to parseInt() so that it uses the same integer conversion as BBB's zoomValue.
This PR changes the calculation of boundZoom in zoomChanger() at whiteboard from parseInt() to Math.round() so that it uses the same integer conversion as tldraw's zoom-level value.
This prevents valid pan updates from being rejected when the tldraw camera zoom contains a fractional value.

Closes Issue(s)

Closes #25690 (fixes only the pan problem, but not the cursor position delay)

Motivation

BBB stores the presentation zoom percentage using parseInt(), while tlCamPercent, which is derived from the tldraw camera, was calculated using Math.round(). (see

for the parseInt part)
Because of this difference, the two values could differ by 1 even though they represented the same zoom level. For example in my investigation:

tldraw zoom: 215.73%
BBB zoom:    215%

Math.round(215.73) = 216
parseInt(215.73)   = 215

actually happened.

The camera synchronization check requires these values to match before publishing pan updates. When they differed, valid pan updates were skipped, causing the presenter's and viewers' camera positions to become desynchronized. Changing the zoom level would usually synchronize them again.
Using the same integer conversion on both sides keeps the existing synchronization logic while avoiding this false mismatch.

How to test

  1. Join a meeting with one presenter and one viewer.
  2. Zoom the presentation to various (hopefully non-integer) zoom levels.
  3. Pan the presentation repeatedly in different directions and at different speeds.
  4. Confirm that the viewer continues to show the same presentation area as the presenter.

More

  • Added/updated documentation

@coderabbitai

coderabbitai Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c6bd8a2d-df68-42d5-ad21-cb965bcf5437

📥 Commits

Reviewing files that changed from the base of the PR and between 2530608 and 07495a8.

📒 Files selected for processing (1)
  • bigbluebutton-html5/imports/ui/components/presentation/component.jsx

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

The zoomChanger function now rounds numeric zoom values with Math.round instead of parsing integers with parseInt.

Priority: ➖ Normal

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 07495

The zoom conversion is consistent across the synchronization path and introduces no merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The linked issue requires a correction to the presentation camera-following behavior [#25690]. The stated objective requires changing tlCamPercent from Math.round() to parseInt(). The reviewed d… Apply the required tlCamPercent conversion from Math.round() to parseInt(..., 10) in the camera synchronization path. Add or retain automated coverage for fractional zoom values and repeated panning.
✅ Passed checks (4 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The only changed code is Presentation.zoomChanger, which handles presentation zoom behavior related to the zoom and camera-following problem in [#25690]. The PR does not add unrelated functionality.…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Title check ✅ Passed The title identifies the main user-facing change: fixing inaccurate viewer slide positioning during panning. It is concise and related to the code change.
Description check ✅ Passed The description clearly explains the rounding change, the pan synchronization problem, the known limitation, and the test steps.
Full details: Linked Issues check

Explanation

The linked issue requires a correction to the presentation camera-following behavior [#25690]. The stated objective requires changing tlCamPercent from Math.round() to parseInt(). The reviewed diff changes Presentation.zoomChanger in the opposite direction, from parseInt(zoom, 10) to Math.round(zoom). The diff does not show the required tlCamPercent change or tests for the stated fractional-zoom pan case.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@imdt-claudiop imdt-claudiop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tested this on a from-source 3.0 environment (this PR applied on top of the current v3.0.x-develop tip, conflict-free) with a presenter + viewer Playwright matrix: zoom levels 100/150/200%, pan, panels visible/hidden, and window resize, reading the tldraw camera numerically on both sides and cross-checking with screenshots.

Results:

  • On base (v3.0.x-develop tip), viewer camera tracked the presenter within 0.05px in all 7 scenarios - I could not reproduce the unfaithful viewer position this PR describes.
  • On this PR, two scenarios fail reproducibly: with the chat and user-list panels hidden (slide letterboxed, widthGap > 0), after the presenter zooms and pans, the viewer never receives the zoom or the pan and stays on the pristine camera. Base handles the identical scenario correctly.

Root cause is detailed in the inline comment: the rounding change is inverted for the one-sided drift that the gap calculation produces, so the zoomSlide() broadcast gate never matches.

Comparison video (base on top / PR below, presenter + viewer side by side): https://claudio.sfo3.digitaloceanspaces.com/work-evidences/2026-09-08/9e1d6f85-c031-4e9b-8dd4-3d7a0ce55505/COMPARISON-base-vs-PR25691.mp4

Isolated regression (PR build, panels hidden, zoom 200% + pan): https://claudio.sfo3.digitaloceanspaces.com/work-evidences/2026-09-08/aeeb329c-5c10-45d5-80eb-5bee45e78dec/PR25691-regression-S2-gap-z200.mp4

Since I could not reproduce the original issue on base, could you share the repro configuration for the unfaithful position? If the reported case has the computed percent landing above the nominal zoom, truncation would help there - but for the gap configurations I tested the drift is always negative, where Math.round is the more tolerant direction.

);
const tlCamPercent = Math.round(
(nextCam.z / (initialZoomRef.current || 1)) * 100
const tlCamPercent = parseInt(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This truncation breaks the broadcast gate whenever widthGap > 0 (slide letterboxed by hidden panels).

In that case syncCameraOnPresenterZoom sets the camera from calculateZoomWithGapValue(), which subtracts the gap from the available width, while tlCamPercent divides by initialZoomRef.current (no gap subtraction). The computed percent therefore lands slightly below the nominal zoom. Since the gap can only ever subtract width, this drift is one-sided (always negative):

  • Math.round rounds the percent back up to the nominal value, so tlCamPercent === zoomValueRef.current holds and zoomSlide() publishes the viewed region.
  • parseInt truncates down, the equality never matches, and the viewer's camera sync never fires at all (not just the pan - the viewer misses the zoom too).

Repro (PR build): presenter zooms to 200% and pans with chat + user-list hidden (widthGap = 337px on a 1280px viewport) - viewer stays at the pristine camera (z=0.70, x=y=-0.57) while the presenter is at x=-528.87, y=-302.22. Base in the identical scenario tracks within 0.05px.

For parseInt to be the correct fix, the drift would have to be positive; I could not produce a configuration where it is.

@hiroshisuga

Copy link
Copy Markdown
Contributor Author

@imdt-claudiop , I will take a look. Thanks!

@hiroshisuga hiroshisuga changed the title [3,0 WB] fix viewer's unfaithful slide position by panning [3.0 WB] fix viewer's unfaithful slide position by panning Sep 12, 2026
@hiroshisuga

hiroshisuga commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @imdt-claudiop , thanks for the review and testing. I completely missed the case that widthGap is positive.

On a fresh installation of 3.0.37, I was able to reproduce both the issue I reported and the regression you found (widthGap > 0). See also the movie that I obtained at the official demo site (3.0.35): #25690.

First, my original issue is reproducible when the zoom value has a fractional part for which parseInt() and Math.round() produce different integers, such as 200.59%. I could not reproduce it when, for instance, zoom level is exactly 150%, 200%, 250%...etc, as you (perhaps) tested.

I logged the zoom metrics with the following code:
At zoomChanger() in component.jsx of the presentation:

const rawZoom = Number(zoom);
const zoomDebug = {
  rawZoom,
  parseIntZoom: parseInt(rawZoom, 10),
  roundZoom: Math.round(rawZoom),
  storedZoom: boundZoom,
};

-> then print the "zoomDebug" after 300 ms using setTimeout.

After the tlCamPercent calculation in component.jsx of the whiteboard:

const tlCamPercentRaw = (
  camera.z / (initialZoomRef.current || 1)
) * 100;
const dimensions = getContainerDimensions?.();
console.log('[ZOOM tldraw settled]', {
  cameraZ: camera.z,
  initialZoom: initialZoomRef.current,
  tlCamPercentRaw,
  tlCamPercentRound: Math.round(tlCamPercentRaw),
  tlCamPercentParseInt: parseInt(tlCamPercentRaw, 10),
  bbbZoom: zoomValueRef.current,
  rawDelta: tlCamPercentRaw - zoomValueRef.current,
  roundMatches: Math.round(tlCamPercentRaw) === zoomValueRef.current,
  parseIntMatches: parseInt(tlCamPercentRaw, 10) === zoomValueRef.current,
  widthGap: dimensions?.widthGap,
});

-> this I also wrapped by setTimeout (300ms) just in case.

Then I zoom by wheel and pan by dragging the presentation. After a couple of operations, I got this:

[ZOOM BBB settled] 
rawZoom: 200.59012855778192
parseIntZoom: 200
roundZoom: 201
storedZoom: 200

[ZOOM tldraw settled]
bbbZoom: 200
cameraZ: 1.0709284085779358
initialZoom: 0.5338888888888889
parseIntMatches: true
rawDelta: 0.5901285577819237
roundMatches: false
tlCamPercentParseInt: 200
tlCamPercentRaw: 200.59012855778192
tlCamPercentRound: 201
widthGap: 0

And the slide position mismatches between the presenter and the viewer:
スクリーンショット 2026-09-12 8 43 33

Next I hid the chat and user-list panes and got this:

[ZOOM BBB settled] 
rawZoom: 172.53072838246408
parseIntZoom: 172
roundZoom: 173
storedZoom: 172

[ZOOM tldraw settled] 
bbbZoom: 172
cameraZ: 1.3176235626838555
initialZoom: 0.7637037037037038
parseIntMatches: true
rawDelta: 0.5307283824640763
roundMatches: false
tlCamPercentParseInt: 172
tlCamPercentRaw: 172.53072838246408
tlCamPercentRound: 173
widthGap: 161

The slide position mismatches again:
スクリーンショット 2026-09-12 8 37 44

Finally I tried to reproduce the condition you tested as much as possible, like:

Viewport size: width: 1273.96px; height: 716.6px;
chat: hidden
user list: hidden
widthGap: 322
Zoom: 200% (not fractional)

, and I got this:

[ZOOM BBB settled] 
rawZoom: 200
parseIntZoom: 200
roundZoom: 200
storedZoom: 200

[ZOOM tldraw settled] 
bbbZoom: 200
cameraZ: 1.7693827160493825
initialZoom: 0.8846913580246913
parseIntMatches: false
rawDelta: -2.842170943040401e-14
roundMatches: true
tlCamPercentParseInt: 199
tlCamPercentRaw: 199.99999999999997
tlCamPercentRound: 200
widthGap: 322

In this case, not surprisingly, the slide pan position perfectly matches between the presenter and the viewer because I did not touch the code. Obviously I will get the problem immediately when the Math.round -> parseInt change is applied at the tlCamPercent calculation (the regression that you found).

These results suggest what to change is not the Math.round at tlCamPercent calculation, but the parseInt at boundZoom calculation.

Based on this assumption, I reverted the tlCamPercent calculation modifiication and changed the parseInt to Math.round at boundZoom calculation. So far, I have not been able to reproduce either problem.

@github-actions

Copy link
Copy Markdown

✅ Automated tests have passed!

@TiagoJacobs

Copy link
Copy Markdown
Member

hello @imdt-claudiop - can you review it again, considering this last comment?

@imdt-claudiop

Copy link
Copy Markdown
Contributor

Thanks for the detailed instrumentation, @hiroshisuga. It settles this: your conclusion is correct, and the current head (07495a81) is the right fix. The regression I reported earlier came from the previous revision, which changed tlCamPercent to parseInt. You reverted that in 2530608e, so it doesn't apply to this version.

Why fractional zoom breaks the pan sync on base

  1. Wheel, pinch and keyboard zoom all calculate the new zoom from the current camera: (cz / initialZoom ± step) * 100. They pass that value to zoomChanger() and set the camera to currentZoomLevel * initialZoom (whiteboard/hooks.js:227-254, and the same in handleKeybindZoom in whiteboard/component.jsx). If cz isn't an exact multiple of initialZoom, the result is not a whole number. That happens when an earlier camera was based on the gap-adjusted zoom (calculateZoomWithGapValue) or on a different initialZoom after a layout change. Your 200.59 and 172.53 are examples.
  2. During a wheel zoom, isWheelZoomRef is true. The zoom-change effect therefore skips syncCameraOnPresenterZoom() (whiteboard/component.jsx:2097-2106), so the presenter's camera keeps the fractional value.
  3. zoomChanger() stores parseInt(200.59) = 200 (presentation/component.jsx:470 on base). The camera listener calculates tlCamPercent = Math.round(200.59) = 201 (whiteboard/component.jsx:1466-1468).
  4. While the wheel flag is set, the isWheelZoomRef branch (:1474-1480) calls zoomSlide() without checking anything, so the zoom itself reaches viewers. After the flag clears, each pan goes through the gate at :1482-1486, tlCamPercent === zoomValueRef.current. That is 201 !== 200, and :1470 also resets hasZoomSyncedRef, so every pan is dropped until the next zoom change. This matches your roundMatches: false / parseIntMatches: true logs and the viewer mismatch in your screenshots.
  5. When the fraction is below .5, both functions give the same number and the gate passes. That's why it looks intermittent, and why my 100/150/200% test matrix never hit it.

Why the fix is on the zoomChanger() side

tlCamPercent has to stay Math.round. When the slide has empty space around it (widthGap > 0), syncCameraOnPresenterZoom() sets the camera from the gap-adjusted base zoom. tlCamPercent divides by initialZoomRef.current, so floating-point error can leave the result just below the whole number. Your third case shows it: 199.99999999999997 with widthGap: 322. Only Math.round maps that back to 200.

Rounding the stored zoom the same way means both sides round the same value:

  • On the wheel path, zoomPercentage and nextCam.z / initialZoom * 100 are the same number, apart from rounding error in the last digit.
  • On the toolbar path, the input is already a whole number, so Math.round changes nothing there.

Math.round also converts numeric strings the same way parseInt did, so callers that pass a string still work.

Suggestions

  1. (Optional, same issue, different path.) getDerivedStateFromProps stores a fractional zoom directly, without going through zoomChanger(): stateChange.zoom = potentialZoom (presentation/component.jsx:120-126). That runs when a user becomes presenter on a zoomed slide. If potentialZoom isn't a whole number, zoomValueRef.current holds a fraction that a rounded tlCamPercent can never equal, so pans would be dropped the same way. Wrapping it in Math.round(...) would make the "stored zoom is always rounded" rule hold everywhere. I haven't reproduced this path; it comes from reading the code.
  2. (Nit.) A one-line comment in zoomChanger() would help the next person, for example: "must use the same rounding as tlCamPercent in whiteboard/component.jsx; the pan sync gate compares the two". Two places now depend on rounding the same way without anything saying so, and that's how this bug started.
  3. (Housekeeping.) CodeRabbit's "Linked Issues check" warning was based on the struck-through first approach (changing tlCamPercent to parseInt), so it's out of date and can be ignored. It might also help to replace the 215.73% example in the Motivation section with your new 200.59 → 200 / 201 example, since that one shows the exact case this PR fixes.

Known limitation (unchanged): if initialZoomRef changes between the zoom and the next pan (a resize or layout change), the two sides can still disagree. That's a separate problem and doesn't block this PR.

From a code-path review, this looks correct to me, and it fixes the case your data shows.

antobinary added a commit that referenced this pull request Oct 20, 2026
The two-finger gestures are sent with CDP Input.dispatchTouchEvent from
a touch-enabled desktop context, so the client gets trusted touch and
pointer events as on a tablet while keeping the desktop layout and zoom
toolbar; Chromium only. Cameras are read through the tldraw editor, the
per-frame zoom from the html layer's transform.

They check that a pinch in at 100 % stays at 100 % for everyone, that a
quick pinch out and a pinch past 400 % end with the viewer on the
presenter's view at no more than 400 %, that a slow pinch out is
published and keeps the point between the fingers under them, that the
zoom of presenter and viewer only moves in the pinch direction, that a
two-finger pan reaches viewers, that a viewer pinch moves no camera,
that a whiteboard user's two-finger tap undoes their last action and
keeps the pencil, and that the fingers leave no stroke behind.

On 4.0.x-develop the pinch-in, slow-pinch, flicker and two-finger-tap
tests fail; with #25671 and #25691 the pinch-in test passes and the
other three still fail.

Refs #26079
@antobinary

Copy link
Copy Markdown
Member

#26085

@antobinary antobinary closed this Oct 21, 2026
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.

[3.0 WB] Zoom, pan, & cursor position still fails to be followed on viewer's screen

5 participants