Skip to content

Fix(html5): cursor appearing on wrong position to viewers - #24884

Merged
antobinary merged 3 commits into
bigbluebutton:v3.0.x-developfrom
Tainan404:i-24809
Apr 15, 2026
Merged

antobinary merged 3 commits into
bigbluebutton:v3.0.x-developfrom
Tainan404:i-24809

Conversation

@Tainan404

Copy link
Copy Markdown
Member

What does this PR do?

FIx, bug where last presenter's cursor position was being sent, also decrease the time between each throttle to make cursor movment smoother for viewers (this change is possible, since cursors aren't handle on akka->hasura anymore, but directly on a service on middleware).

Closes Issue(s)

Closes #24809

How to test

  • Join a mod and a viewer
  • move mouse on whiteboard as a presenter

@coderabbitai

coderabbitai Bot commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

The PR refactors whiteboard cursor handling: useCursor no longer keeps cursor position in React state and now returns a single updateCursorPosition callback that stages coordinates in a ref and publishes at most once per animation frame via requestAnimationFrame (with unmount flush/cancel). Callsites were updated to stop reading local cursorPosition and to pass only updateCursorPosition into mouse-event handlers. Publishing validation was changed to allow zero coordinates, and the default whiteboard.cursorInterval was changed from 150 → 100.

Sequence Diagram(s)

sequenceDiagram
    participant Presenter as Presenter (Mouse)
    participant UI as Whiteboard UI Component
    participant Hook as useCursor (staging + rAF)
    participant Server as publishCursorUpdate (server/bus)
    participant Viewers as Remote Clients

    Presenter->>UI: mouse move events
    UI->>Hook: updateCursorPosition(x,y)
    Hook->>Hook: pendingRef <- (x,y)
    Hook->>Hook: requestAnimationFrame (schedule if none)
    Hook->>Server: publishCursorUpdate(x,y) on rAF
    Server->>Viewers: broadcast cursor update
    Viewers->>Viewers: render remote cursor
    Note right of Hook: on unmount -> cancel rAF and flush pendingRef
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main bug fix: cursor appearing on wrong position to viewers, which aligns with the primary objective to fix cursor position synchronization issues.
Description check ✅ Passed The description explains the bug fix (cursor position synchronization) and mentions decreasing throttle timing, relating to the changeset and referenced issue #24809.
Linked Issues check ✅ Passed The changes address issue #24809 by fixing cursor position synchronization via state removal, ref-based batching, and reduced throttle interval (150→100ms), enabling real-time cursor updates for viewers.
Out of Scope Changes check ✅ Passed All changes directly address cursor position synchronization and throttling performance: hook refactoring for batching, container validation fix for zero values, and configuration interval reduction are all in-scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

Copilot AI 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.

Pull request overview

This PR updates the HTML5 whiteboard cursor publishing path to avoid viewers seeing stale/incorrect cursor coordinates and to make cursor updates smoother.

Changes:

  • Reduce whiteboard cursor publish throttle interval from 150ms to 100ms (config + initial values).
  • Rework useCursor to publish cursor updates via requestAnimationFrame instead of state/effect-driven publishing.
  • Fix cursor publish guard to allow 0 coordinates (top/left edges) by checking for null/undefined instead of falsy.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
bigbluebutton-html5/private/config/settings.yml Lowers public.whiteboard.cursorInterval to 100ms.
bigbluebutton-html5/imports/ui/core/initial-values/meetingClientSettings.ts Keeps initial client settings in sync with the new cursorInterval.
bigbluebutton-html5/imports/ui/components/whiteboard/hooks.js Reworks useCursor to RAF-batch cursor publishing to reduce frame-lag.
bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx Adjusts cursor publish validation and keeps throttled cursor publisher setup.
bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx Adapts to the updated useCursor API (now returns only the updater fn).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const { whiteboardId, xPercent, yPercent } = payload;

if (!whiteboardId || !xPercent || !yPercent || !(hasWBAccess || isPresenter)) return;
if (!whiteboardId || xPercent == null || yPercent == null || !(hasWBAccess || isPresenter)) return;

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

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

The guard now allows NaN/Infinity (they are not null/undefined), which would violate the GraphQL Float! variables and can cause Apollo serialization/runtime errors. Consider validating coordinates with Number.isFinite(xPercent/yPercent) (while still allowing -1 for the hidden-cursor sentinel).

Suggested change
if (!whiteboardId || xPercent == null || yPercent == null || !(hasWBAccess || isPresenter)) return;
const isValidXPercent = xPercent === -1 || Number.isFinite(xPercent);
const isValidYPercent = yPercent === -1 || Number.isFinite(yPercent);
if (!whiteboardId || !isValidXPercent || !isValidYPercent || !(hasWBAccess || isPresenter)) return;

Copilot uses AI. Check for mistakes.
Comment on lines +246 to +251
const throttledPublishCursorUpdate = useMemo(() => {
return throttle(
{ interval: WHITEBOARD_CONFIG.cursorInterval },
publishCursorUpdate,
), [publishCursorUpdate]);
);
}, [publishCursorUpdate]);

Copilot AI Apr 10, 2026

Copy link

Choose a reason for hiding this comment

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

The indentation of the throttle() call is inconsistent with the surrounding formatting and is likely to be rewritten by the formatter / fail linting rules. Please reformat this block (align the arguments and closing paren).

Copilot uses AI. Check for mistakes.
@antobinary antobinary changed the title Fix(html5): cursor appearing on woring position to viewers Fix(html5): cursor appearing on wrong position to viewers Apr 10, 2026
@antobinary antobinary added this to the Release 3.0 milestone Apr 10, 2026

@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

🤖 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 866-869: The hook is being passed a stale ref snapshot
(whiteboardIdRef.current) instead of the live prop; change the call to pass the
live whiteboardId prop directly so useCursor(publishCursorUpdate, whiteboardId)
receives up-to-date board IDs and can synchronize its internal whiteboardIdRef
correctly; update the invocation that currently reads
useCursor(publishCursorUpdate, whiteboardIdRef.current) to pass the prop name
(whiteboardId) and keep publishCursorUpdate as the first argument.
🪄 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: 533c1e9e-823e-45d9-99fe-fbd8b7e159a5

📥 Commits

Reviewing files that changed from the base of the PR and between ed6ded1 and a4cba1e.

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

Comment on lines +866 to 869
const updateCursorPosition = useCursor(
publishCursorUpdate,
whiteboardIdRef.current,
);

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:

#!/bin/bash
# Read-only check: confirm the component passes a ref snapshot while the hook
# expects its `whiteboardId` argument to change when the board changes.
sed -n '396,398p' bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx
sed -n '866,869p' bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx
sed -n '1,25p' bigbluebutton-html5/imports/ui/components/whiteboard/hooks.js

Repository: bigbluebutton/bigbluebutton

Length of output: 1162


Pass whiteboardId directly to useCursor.

Line 868 passes a ref snapshot instead of the live prop. When the whiteboard ID changes, the component's whiteboardIdRef.current is synchronized later in a useEffect (Lines 396-398). This means the hook receives the previous snapshot and won't propagate the board change to its internal ref until a subsequent re-render occurs, causing cursor updates to route to the old whiteboard. The hook in hooks.js synchronizes its own whiteboardIdRef based on its whiteboardId argument, so it should receive the live prop directly.

Suggested fix
  const updateCursorPosition = useCursor(
    publishCursorUpdate,
-    whiteboardIdRef.current,
+    whiteboardId,
  );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const updateCursorPosition = useCursor(
publishCursorUpdate,
whiteboardIdRef.current,
);
const updateCursorPosition = useCursor(
publishCursorUpdate,
whiteboardId,
);
🤖 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 866 - 869, The hook is being passed a stale ref snapshot
(whiteboardIdRef.current) instead of the live prop; change the call to pass the
live whiteboardId prop directly so useCursor(publishCursorUpdate, whiteboardId)
receives up-to-date board IDs and can synchronize its internal whiteboardIdRef
correctly; update the invocation that currently reads
useCursor(publishCursorUpdate, whiteboardIdRef.current) to pass the prop name
(whiteboardId) and keep publishCursorUpdate as the first argument.

@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: 1

🤖 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/hooks.js`:
- Around line 12-17: A queued cursor sample may lose its original whiteboardId
if the board changes before publish; update the queuing logic (where pendingRef
is set and where rafRef schedules work—refer to pendingRef, rafRef,
whiteboardIdRef, publishRef and the publishCursorUpdate call sites) to push an
immutable payload object { whiteboardId: whiteboardIdRef.current, xPercent,
yPercent } into pendingRef and then, when publishing, pass that payload through
publishRef.current unchanged (use payload.whiteboardId rather than reading
current whiteboardId), ensuring each sample keeps the board id it was captured
with; apply the same change to the other queuing/publishing blocks referenced in
the comment (around the lines noted).
🪄 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: 6a6970be-e451-4701-8d13-31708bd42a6e

📥 Commits

Reviewing files that changed from the base of the PR and between a4cba1e and ec06153.

📒 Files selected for processing (4)
  • bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx
  • bigbluebutton-html5/imports/ui/components/whiteboard/hooks.js
  • bigbluebutton-html5/imports/ui/core/initial-values/meetingClientSettings.ts
  • bigbluebutton-html5/private/config/settings.yml
✅ Files skipped from review due to trivial changes (2)
  • bigbluebutton-html5/imports/ui/core/initial-values/meetingClientSettings.ts
  • bigbluebutton-html5/private/config/settings.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx

Comment on lines +12 to +17
const whiteboardIdRef = React.useRef(whiteboardId);
const pendingRef = React.useRef(null);
const rafRef = React.useRef(null);

useEffect(() => { publishRef.current = publishCursorUpdate; }, [publishCursorUpdate]);
useEffect(() => { whiteboardIdRef.current = whiteboardId; }, [whiteboardId]);

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 | 🟡 Minor

Capture whiteboardId when the cursor sample is queued.

A queued point can cross a whiteboard switch here: if whiteboardId changes after Line 35 stages the coordinates but before Line 24 or Line 40 publishes them, the old point is emitted to the new board. Queue { whiteboardId, xPercent, yPercent } and publish that payload unchanged so each sample stays attached to the board it came from.

Suggested fix
   const publishRef = React.useRef(publishCursorUpdate);
-  const whiteboardIdRef = React.useRef(whiteboardId);
   const pendingRef = React.useRef(null);
   const rafRef = React.useRef(null);

   useEffect(() => { publishRef.current = publishCursorUpdate; }, [publishCursorUpdate]);
-  useEffect(() => { whiteboardIdRef.current = whiteboardId; }, [whiteboardId]);

   useEffect(() => () => {
     if (rafRef.current) {
       cancelAnimationFrame(rafRef.current);
       rafRef.current = null;
       if (pendingRef.current) {
-        publishRef.current({
-          whiteboardId: whiteboardIdRef.current,
-          ...pendingRef.current,
-        });
+        publishRef.current(pendingRef.current);
         pendingRef.current = null;
       }
     }
   }, []);

   const updateCursorPosition = React.useCallback((newX, newY) => {
     if (newX === undefined || newX === null || newY === undefined || newY === null) return;
-    pendingRef.current = { xPercent: newX, yPercent: newY };
+    pendingRef.current = { whiteboardId, xPercent: newX, yPercent: newY };
     if (!rafRef.current) {
       rafRef.current = requestAnimationFrame(() => {
         rafRef.current = null;
         if (pendingRef.current) {
-          publishRef.current({
-            whiteboardId: whiteboardIdRef.current,
-            ...pendingRef.current,
-          });
+          publishRef.current(pendingRef.current);
           pendingRef.current = null;
         }
       });
     }
-  }, []);
+  }, [whiteboardId]);

Also applies to: 23-27, 35-48

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

In `@bigbluebutton-html5/imports/ui/components/whiteboard/hooks.js` around lines
12 - 17, A queued cursor sample may lose its original whiteboardId if the board
changes before publish; update the queuing logic (where pendingRef is set and
where rafRef schedules work—refer to pendingRef, rafRef, whiteboardIdRef,
publishRef and the publishCursorUpdate call sites) to push an immutable payload
object { whiteboardId: whiteboardIdRef.current, xPercent, yPercent } into
pendingRef and then, when publishing, pass that payload through
publishRef.current unchanged (use payload.whiteboardId rather than reading
current whiteboardId), ensuring each sample keeps the board id it was captured
with; apply the same change to the other queuing/publishing blocks referenced in
the comment (around the lines noted).

@github-actions

Copy link
Copy Markdown

✅ Automated tests have passed!

@antobinary
antobinary merged commit b524015 into bigbluebutton:v3.0.x-develop Apr 15, 2026
35 checks passed
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] Viewer's cursor delays one frame

4 participants