Skip to content

[3.0 WB] Viewer's cursor misaligned upon zooming slide or changing window size - #24820

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

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

Conversation

@hiroshisuga

@hiroshisuga hiroshisuga commented Mar 29, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

This is not a PR, but a small hack to show there are still some problems on the cursor (red circle) position in the viewer's screen.

Closes Issue(s)

Related to #24595 .

Motivation

Even before the PR #24595, I noticed that the presenter's cursor on the viewer's screen is misaligned when the presenter zooms the slide. See the screenshot below (tested on the demo server).
image
This is a viewer's screen showing the position of presenter's cursor, which is, in the presenter's screen, perfectly positioned at the center of the letter 'o'. You see the red circle is positioned slightly on the right (this bahaviour has been improved by the PR #24595, but it's another story).

Now, when the presenter zooms the slide by wheel, the misalignment becomes more obvious.
image

And when the viewer enlarges the window after turning back the slide zoom to 100%, another misalignment emerges.
image

Then when the PR #24595 is applied, the problem becomes worse, while the problem is partially fixed when there is no zooming. See below the cursor positioned at outside of the letter 'o'.
image

So my conclusion is there are at least two different bugs behind this problem, namely:

  1. the slide zoom is not considered
  2. the size change of the viewer's screen (presentation container) is not considered

To nail down the problem, I generated this draft PR. With this hack, I can probably fix the problem 1, but I can only partially fix the problem 2.

What I did is basically pass the slide zoom value and the presentation container zoom value to the styles.js and compensate the cursor offset. For the problem 1, I was able to (probably completely) eliminate by simply dividing the cursor offset by the slide zoom value (so I skip to show the evidence). But I could only improve the problem 2 by an empirical, dirty hack .

const leftOffset = (-18 * scaleRatio + 27 * (containerZoom - 0.38)) / slideZoom;
const topOffset = (-10 * scaleRatio + 15 * (containerZoom - 0.38)) / slideZoom;

This hack works more or less well. I guess not many users would realise the problem. However this is obviously not the final solution.

That's where I have been so far. I will post if I found something more. Hopefully it will help.

@coderabbitai

coderabbitai Bot commented Mar 29, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

The whiteboard component now computes two zoom values and passes them to the styled tldraw wrapper: slideZoom (current tldraw camera zoom normalized by the initial zoom) and containerZoom (from calculateZoomValue using the current presentation page’s scaled dimensions). The styled .tl-collaborator__cursor interpolation now accepts containerZoom and slideZoom and uses them in the cursor left/top offset calculations instead of the previous fixed-offset formulas.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main issue addressed: viewer cursor misalignment when zooming slides or changing window size, directly matching the PR's core purpose.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description is directly related to the changeset, explaining the cursor misalignment problem and the zoom-related fixes being attempted.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@hiroshisuga hiroshisuga changed the title [3.0 WB] Viewer's cursor mispositioned upon zooming slide or presentation [3.0 WB] Viewer's cursor misaligned upon zooming slide or changing window size Mar 29, 2026
@hiroshisuga
hiroshisuga marked this pull request as ready for review March 29, 2026 11:30

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
bigbluebutton-html5/imports/ui/components/whiteboard/styles.js (1)

67-75: Extract the calibration constants before this formula hardens.

-18, 13, -10, 7, and 0.38 are now part of the cursor-alignment behavior, but they read like unexplained magic numbers. Hoisting them into named constants with a short note about what each term compensates for will make the next calibration pass much safer.

♻️ Suggested cleanup
+const CURSOR_OFFSET_BASELINE_ZOOM = 0.38;
+const CURSOR_LEFT_POINTER_COEFFICIENT = -18;
+const CURSOR_LEFT_CONTAINER_COEFFICIENT = 13;
+const CURSOR_TOP_POINTER_COEFFICIENT = -10;
+const CURSOR_TOP_CONTAINER_COEFFICIENT = 7;
+
 ${({ isPresenter, isMultiUserActive, pointerDiameter = 5, containerZoom, slideZoom }) => {
   const numericDiameter = Number(pointerDiameter);
   const safeDiameter = Number.isFinite(numericDiameter) && numericDiameter > 0
     ? numericDiameter
     : 5;
   const scale = safeDiameter / 100;
   const scaleRatio = safeDiameter / 5;
-  const leftOffset = (-18 * scaleRatio + 13 * (containerZoom - 0.38)) / slideZoom;
-  const topOffset = (-10 * scaleRatio + 7 * (containerZoom - 0.38)) / slideZoom;
+  const leftOffset = (
+    CURSOR_LEFT_POINTER_COEFFICIENT * scaleRatio
+    + CURSOR_LEFT_CONTAINER_COEFFICIENT * (containerZoom - CURSOR_OFFSET_BASELINE_ZOOM)
+  ) / slideZoom;
+  const topOffset = (
+    CURSOR_TOP_POINTER_COEFFICIENT * scaleRatio
+    + CURSOR_TOP_CONTAINER_COEFFICIENT * (containerZoom - CURSOR_OFFSET_BASELINE_ZOOM)
+  ) / slideZoom;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bigbluebutton-html5/imports/ui/components/whiteboard/styles.js` around lines
67 - 75, The computed leftOffset/topOffset block uses unexplained magic numbers
(-18, 13, -10, 7, 0.38); extract those into clearly named constants immediately
above the calculation inside the same styled-function (the arrow function that
receives isPresenter, isMultiUserActive, pointerDiameter, containerZoom,
slideZoom) — e.g. CURSOR_BASE_X, CONTAINER_X_ADJUST, CURSOR_BASE_Y,
CONTAINER_Y_ADJUST, ZOOM_BASE_OFFSET — and replace the raw literals in the
scale/scaleRatio/leftOffset/topOffset expressions; add a one-line comment for
each constant stating what it compensates for (cursor graphic baseline,
container centering tweak, vertical baseline, vertical tweak, zoom baseline) to
make future calibration straightforward.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx`:
- Around line 2207-2209: Replace the ref-based calculations that produce
slideZoom and containerZoom with render-safe React state: stop reading
initialZoomRef.current and currentPresentationPageRef.current directly in the
render; instead create state variables (e.g., slideZoomState,
containerZoomState) initialized to safe defaults and update them inside a
useEffect that runs when tlEditorRef.current camera z, initialZoomRef (baseline
zoom) and the prop currentPresentationPage change; compute slideZoom from
tlEditorRef.current.getCamera().z divided by the baseline zoom state (guarding
against null/zero) and compute containerZoom by calling
calculateZoomValue(currentPresentationPage.scaledWidth,
currentPresentationPage.scaledHeight) using the prop, then use these state
values wherever slideZoom and containerZoom were used (e.g., styles.js
leftOffset/topOffset) so cursor offsets never receive NaN or stale values.

---

Nitpick comments:
In `@bigbluebutton-html5/imports/ui/components/whiteboard/styles.js`:
- Around line 67-75: The computed leftOffset/topOffset block uses unexplained
magic numbers (-18, 13, -10, 7, 0.38); extract those into clearly named
constants immediately above the calculation inside the same styled-function (the
arrow function that receives isPresenter, isMultiUserActive, pointerDiameter,
containerZoom, slideZoom) — e.g. CURSOR_BASE_X, CONTAINER_X_ADJUST,
CURSOR_BASE_Y, CONTAINER_Y_ADJUST, ZOOM_BASE_OFFSET — and replace the raw
literals in the scale/scaleRatio/leftOffset/topOffset expressions; add a
one-line comment for each constant stating what it compensates for (cursor
graphic baseline, container centering tweak, vertical baseline, vertical tweak,
zoom baseline) to make future calibration straightforward.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6ac824f0-1bd1-4786-926e-09ab51aed051

📥 Commits

Reviewing files that changed from the base of the PR and between 70b07a5 and 4b4e5fc.

📒 Files selected for processing (2)
  • bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx
  • bigbluebutton-html5/imports/ui/components/whiteboard/styles.js

Comment on lines +2207 to +2209
const slideZoom = tlEditorRef.current?.getCamera().z / initialZoomRef.current;
const { scaledWidth, scaledHeight } = currentPresentationPageRef.current;
const containerZoom = calculateZoomValue(scaledWidth, scaledHeight);

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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let me examine the target lines and surrounding context
cat -n bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx | sed -n '2200,2250p'

Repository: bigbluebutton/bigbluebutton

Length of output: 1988


🏁 Script executed:

# Check the initialization and updates of initialZoomRef
cat -n bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx | sed -n '340,390p'

Repository: bigbluebutton/bigbluebutton

Length of output: 1986


🏁 Script executed:

# Check the currentPresentationPageRef initialization and updates
rg -n "currentPresentationPageRef" bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx -A 2 -B 2

Repository: bigbluebutton/bigbluebutton

Length of output: 5723


🏁 Script executed:

# Check the calculateZoomValue function
rg -n "calculateZoomValue" bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx -A 10 -B 2

Repository: bigbluebutton/bigbluebutton

Length of output: 4331


🏁 Script executed:

# Check the Styled.TldrawV2GlobalStyle usage in styles.js
rg -n "TldrawV2GlobalStyle\|slideZoom\|containerZoom" bigbluebutton-html5/imports/ui/components/whiteboard/styles.js -A 5 -B 5

Repository: bigbluebutton/bigbluebutton

Length of output: 53


🏁 Script executed:

# Check how camera zoom is updated
rg -n "syncCameraOnPresenterZoom\|syncCameraWithPresentationArea" bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx -A 15

Repository: bigbluebutton/bigbluebutton

Length of output: 53


🏁 Script executed:

find bigbluebutton-html5 -name "styles.js" -path "*whiteboard*" 2>/dev/null | head -20

Repository: bigbluebutton/bigbluebutton

Length of output: 133


🏁 Script executed:

# Search for where slideZoom and containerZoom are used
rg "slideZoom|containerZoom" bigbluebutton-html5/imports/ui/components/whiteboard/ -l

Repository: bigbluebutton/bigbluebutton

Length of output: 200


🏁 Script executed:

# Look for initialization of initialZoomRef
rg -n "initialZoomRef\s*=" bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx | head -20

Repository: bigbluebutton/bigbluebutton

Length of output: 113


🏁 Script executed:

# Check what prop is actually used in render - check if there's currentPresentationPage prop
rg -n "currentPresentationPage[^R]" bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx | head -30

Repository: bigbluebutton/bigbluebutton

Length of output: 881


🏁 Script executed:

# Check the styles.js file to see how slideZoom and containerZoom are used
cat -n bigbluebutton-html5/imports/ui/components/whiteboard/styles.js | grep -A 10 -B 10 "slideZoom\|containerZoom"

Repository: bigbluebutton/bigbluebutton

Length of output: 1237


🏁 Script executed:

# Get the full context around the TldrawV2GlobalStyle definition
cat -n bigbluebutton-html5/imports/ui/components/whiteboard/styles.js | head -100

Repository: bigbluebutton/bigbluebutton

Length of output: 3168


🏁 Script executed:

# Check if there are any safety checks or guards when using these props
rg -n "slideZoom|containerZoom" bigbluebutton-html5/imports/ui/components/whiteboard/styles.js -A 5 -B 5

Repository: bigbluebutton/bigbluebutton

Length of output: 859


Use render-safe state instead of refs for slideZoom and containerZoom to prevent stale or invalid cursor positioning.

Line 2207 divides by initialZoomRef.current, which is initialized as null and only updated asynchronously via debounce, producing NaN on the first render. Line 2208 destructures from currentPresentationPageRef.current, which is not updated until after commit, so the ref can be null or stale when this code runs—this directly causes the destructuring to fail or pass invalid data.

These invalid values flow directly into styles.js (lines 74–75), where they are used to calculate leftOffset and topOffset for collaborator cursors. When slideZoom is NaN, the cursor positions become invalid and remain broken until the next render that coincidentally receives valid values.

The currentPresentationPage prop is already available; use it directly instead of the ref. For initialZoomRef, move the zoom calculation into a React state that updates whenever the camera or baseline zoom changes, ensuring cursor offsets are always computed from consistent, valid data.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx` around
lines 2207 - 2209, Replace the ref-based calculations that produce slideZoom and
containerZoom with render-safe React state: stop reading initialZoomRef.current
and currentPresentationPageRef.current directly in the render; instead create
state variables (e.g., slideZoomState, containerZoomState) initialized to safe
defaults and update them inside a useEffect that runs when tlEditorRef.current
camera z, initialZoomRef (baseline zoom) and the prop currentPresentationPage
change; compute slideZoom from tlEditorRef.current.getCamera().z divided by the
baseline zoom state (guarding against null/zero) and compute containerZoom by
calling calculateZoomValue(currentPresentationPage.scaledWidth,
currentPresentationPage.scaledHeight) using the prop, then use these state
values wherever slideZoom and containerZoom were used (e.g., styles.js
leftOffset/topOffset) so cursor offsets never receive NaN or stale values.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bigbluebutton-html5/imports/ui/components/whiteboard/styles.js`:
- Around line 74-75: The current leftOffset/topOffset calculations in styles.js
use containerZoom (fit ratio) and scaleRatio/slideZoom, which cannot account for
post-resize translations; instead compute the actual screen transform (scale +
translation) in the whiteboard component that owns the camera/page transform
(where containerZoom is derived) and pass a final hotspot delta (e.g.,
hotspotOffsetX and hotspotOffsetY) into the styles rather than relying on the
heuristic formula. Update the producer (component.jsx) to derive the
page-to-screen transform matrix or camera translation+scale after resize and
expose the final x/y deltas, then replace leftOffset/topOffset usage in
styles.js to use those passed-in hotspot deltas so the hotspot aligns correctly
after resize/translation.
- Around line 67-75: Sanitize containerZoom and slideZoom before using them in
the styled interpolation: coerce containerZoom and slideZoom to numbers,
validate with Number.isFinite, and provide safe fallbacks (e.g.,
containerZoomFallback = Number.isFinite(Number(containerZoom)) ?
Number(containerZoom) : 1; slideZoomFallback =
Number.isFinite(Number(slideZoom)) && Number(slideZoom) !== 0 ?
Number(slideZoom) : 1) and then use these safe values when computing scaleRatio,
leftOffset and topOffset so you never divide by zero or produce NaN/Infinity in
the CSS.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 010976f3-fb2c-4add-ac33-1f1c9e490f5d

📥 Commits

Reviewing files that changed from the base of the PR and between 4b4e5fc and 66689eb.

📒 Files selected for processing (1)
  • bigbluebutton-html5/imports/ui/components/whiteboard/styles.js

Comment on lines +67 to +75
${({ isPresenter, isMultiUserActive, pointerDiameter = 5, containerZoom, slideZoom }) => {
const numericDiameter = Number(pointerDiameter);
const safeDiameter = Number.isFinite(numericDiameter) && numericDiameter > 0
? numericDiameter
: 5;
const scale = safeDiameter / 100;
const scaleRatio = safeDiameter / 5;
const leftOffset = -18 * scaleRatio;
const topOffset = -10 * scaleRatio;
const leftOffset = (-18 * scaleRatio + 27 * (containerZoom - 0.38)) / slideZoom;
const topOffset = (-10 * scaleRatio + 15 * (containerZoom - 0.38)) / slideZoom;

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.

⚠️ Potential issue | 🟠 Major

Guard non-finite zoom props before emitting CSS.

pointerDiameter is sanitized, but containerZoom and slideZoom are not. bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx:360-377 initializes initialZoomRef.current from live page dimensions without a zero/NaN guard, so a transient zero-sized page during mount or resize can turn Lines 74-75 into NaNpx / Infinitypx and leave the cursor mispositioned or unstyled.

Proposed fix
   const scale = safeDiameter / 100;
   const scaleRatio = safeDiameter / 5;
-  const leftOffset = (-18 * scaleRatio + 27 * (containerZoom - 0.38)) / slideZoom;
-  const topOffset = (-10 * scaleRatio + 15 * (containerZoom - 0.38)) / slideZoom;
+  const baseContainerZoom = 0.38;
+  const numericContainerZoom = Number(containerZoom);
+  const numericSlideZoom = Number(slideZoom);
+  const safeContainerZoom = Number.isFinite(numericContainerZoom)
+    ? numericContainerZoom
+    : baseContainerZoom;
+  const safeSlideZoom = Number.isFinite(numericSlideZoom) && numericSlideZoom > 0
+    ? numericSlideZoom
+    : 1;
+  const leftOffset = (-18 * scaleRatio + 27 * (safeContainerZoom - baseContainerZoom)) / safeSlideZoom;
+  const topOffset = (-10 * scaleRatio + 15 * (safeContainerZoom - baseContainerZoom)) / safeSlideZoom;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bigbluebutton-html5/imports/ui/components/whiteboard/styles.js` around lines
67 - 75, Sanitize containerZoom and slideZoom before using them in the styled
interpolation: coerce containerZoom and slideZoom to numbers, validate with
Number.isFinite, and provide safe fallbacks (e.g., containerZoomFallback =
Number.isFinite(Number(containerZoom)) ? Number(containerZoom) : 1;
slideZoomFallback = Number.isFinite(Number(slideZoom)) && Number(slideZoom) !==
0 ? Number(slideZoom) : 1) and then use these safe values when computing
scaleRatio, leftOffset and topOffset so you never divide by zero or produce
NaN/Infinity in the CSS.

Comment on lines +74 to +75
const leftOffset = (-18 * scaleRatio + 27 * (containerZoom - 0.38)) / slideZoom;
const topOffset = (-10 * scaleRatio + 15 * (containerZoom - 0.38)) / slideZoom;

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.

⚠️ Potential issue | 🟠 Major

A scale-only correction cannot fix resize drift.

containerZoom from bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx:877-888 is only a fit ratio. After a window resize the page can also translate inside the presentation area, so the cursor delta depends on more than scale. That matches the remaining right-bottom → aligned → left-up drift described in the PR objective. Please derive the hotspot offset from the actual page/camera screen transform and pass the final x/y delta here instead of tuning more linear coefficients in CSS.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bigbluebutton-html5/imports/ui/components/whiteboard/styles.js` around lines
74 - 75, The current leftOffset/topOffset calculations in styles.js use
containerZoom (fit ratio) and scaleRatio/slideZoom, which cannot account for
post-resize translations; instead compute the actual screen transform (scale +
translation) in the whiteboard component that owns the camera/page transform
(where containerZoom is derived) and pass a final hotspot delta (e.g.,
hotspotOffsetX and hotspotOffsetY) into the styles rather than relying on the
heuristic formula. Update the producer (component.jsx) to derive the
page-to-screen transform matrix or camera translation+scale after resize and
expose the final x/y deltas, then replace leftOffset/topOffset usage in
styles.js to use those passed-in hotspot deltas so the hotspot aligns correctly
after resize/translation.

@github-actions

Copy link
Copy Markdown

✅ Automated tests have passed!

@github-actions

Copy link
Copy Markdown

This pull request has conflicts ☹
Please resolve those so we can review the pull request.
Thanks.

@hiroshisuga

Copy link
Copy Markdown
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants