Repository navigation
Fix(html5): cursor appearing on wrong position to viewers - #24884
Conversation
WalkthroughThe PR refactors whiteboard cursor handling: 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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
useCursorto publish cursor updates viarequestAnimationFrameinstead of state/effect-driven publishing. - Fix cursor publish guard to allow
0coordinates (top/left edges) by checking fornull/undefinedinstead 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; |
There was a problem hiding this comment.
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).
| 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; |
| const throttledPublishCursorUpdate = useMemo(() => { | ||
| return throttle( | ||
| { interval: WHITEBOARD_CONFIG.cursorInterval }, | ||
| publishCursorUpdate, | ||
| ), [publishCursorUpdate]); | ||
| ); | ||
| }, [publishCursorUpdate]); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx
| const updateCursorPosition = useCursor( | ||
| publishCursorUpdate, | ||
| whiteboardIdRef.current, | ||
| ); |
There was a problem hiding this comment.
🧩 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.jsRepository: 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.
| 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.
|
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
bigbluebutton-html5/imports/ui/components/whiteboard/component.jsxbigbluebutton-html5/imports/ui/components/whiteboard/hooks.jsbigbluebutton-html5/imports/ui/core/initial-values/meetingClientSettings.tsbigbluebutton-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
| 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]); |
There was a problem hiding this comment.
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).
✅ Automated tests have passed! |



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