Skip to content

Fix(html5): Presenter whiteboard camera position moving on window resizing - #24968

Merged
ramonlsouza merged 5 commits into
bigbluebutton:v3.0.x-developfrom
Tainan404:fix-wb-resize
May 12, 2026
Merged

ramonlsouza merged 5 commits into
bigbluebutton:v3.0.x-developfrom
Tainan404:fix-wb-resize

Conversation

@Tainan404

Copy link
Copy Markdown
Member

What does this PR do?

This PR fixes two bugs where the whiteboard "camera" failed to adapt to browser window resizing. Key updates include:

  • Resize Alignment: The viewport now recalculates position and zoom automatically when the window size changes, preventing misalignment.
  • Zoom Persistence: Fixed an issue where manual zoom levels were lost during resizing; the system now remembers the current zoom level and keeps the slide position locked.
  • Code Cleanup: Removed redundant calculations to ensure only the zoom scales during a resize, while the position remains stable.

Closes Issue(s)

Closes #24949

How to test

  • Open a presentation and manually zoom in using the mouse wheel.

  • Resize the browser window. (Shrink and expand)

  • Expected Result: The slide should maintain its specific zoom level and relative alignment without snapping back to the default view or shifting off-center.

More

Without zoom

resize-normal.webm

With Zoom

resize-zoom.webm

…a resizes by tracking api-source setCamera calls and dropping the incorrect x/y reposition formula in syncCameraWithPresentationArea
…nt, visual baseline, and zoomed-state preservation after container resize
@github-actions

Copy link
Copy Markdown

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

@coderabbitai

coderabbitai Bot commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR updates the whiteboard client and adds end-to-end Playwright tests for resize recovery. In the client whiteboard component, zoom-calculation helpers are stored in refs, a per-page actual zoom ratio cache/ref is maintained for presenter-origin camera updates, presenter-side restore now merges only camera.z (no x/y recenter), RAF polling depends on presentation area width/height, and per-page zoom cache is cleaned on unmount. A new exported test class WhiteboardResize (extending DrawShape) implements four resize/validation flows (cameraResync, cameraResyncVisual, cameraResyncZoomedVisual, cameraResyncAfterMinimizeRestore) and the spec adds a typed runResizeTest helper plus four tests invoking those flows.

Sequence Diagram(s)

sequenceDiagram
    participant Presenter
    participant Whiteboard
    participant Server
    participant Viewer

    Presenter->>Whiteboard: resize presentation area (moderator action)
    Whiteboard->>Whiteboard: recompute baseZoom (refs) and update pageActualZoomRatioRef
    Whiteboard->>Server: publish camera update (z, source: api)
    Server->>Viewer: broadcast camera update
    Viewer->>Whiteboard: receive camera update
    Whiteboard->>Whiteboard: compute stored zoom ratio (nextCam.z / baseZoom) and store per-page
    Whiteboard->>Whiteboard: apply camera.z only (no x/y recenter for presenter restore)
    Note right of Whiteboard: RAF polling reacts to presentationAreaWidth/Height changes
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

component: whiteboard

Suggested reviewers

  • ramonlsouza
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main fix: addressing presenter whiteboard camera position issues during window resizing.
Description check ✅ Passed The description is directly related to the changeset, explaining the bugs fixed, the key updates made, test procedures, and linking to the relevant issue.
Linked Issues check ✅ Passed The PR code changes address issue #24949 by implementing zoom persistence and correct camera position recalculation during resize events to prevent slide misalignment.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing whiteboard camera alignment on resize, adding tests, and supporting infrastructure for the fix.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@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

🧹 Nitpick comments (2)
bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts (2)

63-65: Hard-coded 5 s sleeps will make these tests slow and still flaky.

Each method accumulates 10–15 s of waitForTimeout (mount settle + post-shrink + post-expand), which both slows CI down and still leaves a race with the "35 stable frames + polling" chain mentioned in the comment at Line 114-115 on a slow runner. Consider replacing with an assertion-based wait that polls until the invariant holds (e.g., await expect.poll(() => getCameraZoom(...), { timeout: 15_000 }).toBeGreaterThan(0) before capturing, and for the post-expand step: await expect.poll(() => getWrapperWidth(...)).toBe(modInitialWidth)). That way the test exits as soon as the layout is settled and only blows up to the timeout on genuine regressions.

Also applies to: 107-116, 194-195, 267-268, 279-280

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

In `@bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts` around lines
63 - 65, Replace hard-coded waitForTimeout sleeps in whiteboardResize tests with
assertion-based polling that waits for the actual layout invariants to settle:
instead of await this.modPage.page.waitForTimeout(5000) and other sleeps, poll
using Playwright expect.poll on helper getters like getCameraZoom(modPage) to be
> 0 before taking a capture, and poll getWrapperWidth(modPage) to equal
modInitialWidth after expand/shrink. Update all occurrences that sleep (the
mount-settle, post-shrink, post-expand waits referenced in the comment) to use
expect.poll with a sensible timeout (e.g., 15_000) so the test proceeds as soon
as invariants hold and only fails on real regressions.

202-238: React fiber walk is fragile — consider exposing a test hook instead.

Walking the fiber tree via __reactFiber$... to find the useRef whose .current has setCamera, getCamera, and getViewportScreenBounds relies on React's internal hook memory layout, which is not a stable API.

Two realistic breakage sources:

  • React 18→19 (or future minor upgrades) can change memoizedState structure or __reactFiber$... naming — documented in past React transitions.
  • Another component mounting a useRef with a setCamera method would cause the walk to latch onto the wrong ref.

A safer approach: expose a narrow test hook (e.g., window.__BBB_TEST__.tlEditor = editorRef.current behind a NODE_ENV !== 'production' guard) so the test can directly call setCamera without fiber introspection. The setEditor prop is already passing the editor to the parent component, making this a straightforward addition.

Not a blocker — the current code works and is well-documented. Just flag for future maintenance.

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

In `@bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts` around lines
202 - 238, The test's React fiber walk (searching the DOM node
'whiteboard-element' for keys starting with '__reactFiber' and inspecting
hook.memoizedState to find a ref with
setCamera/getCamera/getViewportScreenBounds) is fragile; instead, add a narrow
test hook in the app code that exposes the editor ref in non-production (e.g.,
set window.__BBB_TEST__.tlEditor = editorRef.current when setEditor is called or
when tlEditorRef is available), then update the test to call
window.__BBB_TEST__.tlEditor.setCamera(...) directly; ensure the hook is guarded
by NODE_ENV !== 'production' and tied to the existing setEditor/ tlEditorRef so
you don't change runtime behavior other than the test-only exposure.
🤖 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-tests/playwright/whiteboard/whiteboardResize.ts`:
- Around line 270-275: The added writes of full-page screenshots into
modShrunkPath and userShrunkPath are dead code because cameraResyncZoomedVisual
never asserts them; either remove the fs.writeFileSync calls for
modShrunkPath/userShrunkPath to avoid wasted I/O, or add explicit Playwright
assertions using toHaveScreenshot (e.g., mirror cameraResyncVisual style) that
reference the corresponding 'mod-whiteboard-resize-zoomed-shrunk' and
'user-whiteboard-resize-zoomed-shrunk' baselines so the shrunk state is actually
validated.
- Around line 252-259: The snapshot files are being saved to hardcoded
platform-specific filenames (modInitialPath, userInitialPath) which can diverge
from Playwright's toHaveScreenshot paths; thread the TestInfo from runResizeTest
into this function and replace the manual path construction
(snapshotDir/mod-whiteboard-resize-zoomed-initial-...png and user-...png) with
calls to testInfo.snapshotPath('mod-whiteboard-resize-zoomed-initial.png') and
testInfo.snapshotPath('user-whiteboard-resize-zoomed-initial.png') before
writing the screenshots returned by this.modPage.page.screenshot() and
this.userPage.page.screenshot(), so the saved baselines match Playwright's
platform-aware snapshot resolution.

---

Nitpick comments:
In `@bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts`:
- Around line 63-65: Replace hard-coded waitForTimeout sleeps in
whiteboardResize tests with assertion-based polling that waits for the actual
layout invariants to settle: instead of await
this.modPage.page.waitForTimeout(5000) and other sleeps, poll using Playwright
expect.poll on helper getters like getCameraZoom(modPage) to be > 0 before
taking a capture, and poll getWrapperWidth(modPage) to equal modInitialWidth
after expand/shrink. Update all occurrences that sleep (the mount-settle,
post-shrink, post-expand waits referenced in the comment) to use expect.poll
with a sensible timeout (e.g., 15_000) so the test proceeds as soon as
invariants hold and only fails on real regressions.
- Around line 202-238: The test's React fiber walk (searching the DOM node
'whiteboard-element' for keys starting with '__reactFiber' and inspecting
hook.memoizedState to find a ref with
setCamera/getCamera/getViewportScreenBounds) is fragile; instead, add a narrow
test hook in the app code that exposes the editor ref in non-production (e.g.,
set window.__BBB_TEST__.tlEditor = editorRef.current when setEditor is called or
when tlEditorRef is available), then update the test to call
window.__BBB_TEST__.tlEditor.setCamera(...) directly; ensure the hook is guarded
by NODE_ENV !== 'production' and tied to the existing setEditor/ tlEditorRef so
you don't change runtime behavior other than the test-only exposure.
🪄 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: 4687abd1-8b7f-46ea-b3fc-d4d245d627c9

📥 Commits

Reviewing files that changed from the base of the PR and between fcb3e62 and cbfc9fb.

⛔ Files ignored due to path filters (8)
  • bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts-snapshots/mod-whiteboard-resize-initial-Chromium-linux.png is excluded by !**/*.png
  • bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts-snapshots/mod-whiteboard-resize-shrunk-Chromium-linux.png is excluded by !**/*.png
  • bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts-snapshots/mod-whiteboard-resize-zoomed-initial-Chromium-linux.png is excluded by !**/*.png
  • bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts-snapshots/mod-whiteboard-resize-zoomed-shrunk-Chromium-linux.png is excluded by !**/*.png
  • bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts-snapshots/user-whiteboard-resize-initial-Chromium-linux.png is excluded by !**/*.png
  • bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts-snapshots/user-whiteboard-resize-shrunk-Chromium-linux.png is excluded by !**/*.png
  • bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts-snapshots/user-whiteboard-resize-zoomed-initial-Chromium-linux.png is excluded by !**/*.png
  • bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts-snapshots/user-whiteboard-resize-zoomed-shrunk-Chromium-linux.png is excluded by !**/*.png
📒 Files selected for processing (3)
  • bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx
  • bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts
  • bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts

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

🧹 Nitpick comments (2)
bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx (2)

1470-1488: De‑duplicate the pageActualZoomRatioRef update with the user‑source listener.

The new api/presenter branch here computes baseZ and writes pageActualZoomRatioRef.current[pKey] = nextCam.z / baseZ using exactly the same logic as the user‑source listener at Lines 1385‑1394. Consider extracting a small helper (e.g. updateStoredZoomRatio(nextCamZ)) and calling it from both listeners so the ratio formula (and the baseZ > 0 guard) lives in one place. This also makes it easier later if you ever need to harden the baseZ fallback against the HUNDRED_PERCENT sentinel returned by calculateZoomValue on invalid dimensions — both call sites would get it at once.

♻️ Sketch of the helper extraction
+  const updateStoredZoomRatio = (nextCamZ) => {
+    const baseZ = calculateZoomValueRef.current?.(
+      currentPresentationPageRef.current?.scaledWidth,
+      currentPresentationPageRef.current?.scaledHeight,
+    );
+    if (baseZ > 0) {
+      const pageKey = `${presentationIdRef.current}_${curPageIdRef.current}`;
+      pageActualZoomRatioRef.current[pageKey] = nextCamZ / baseZ;
+    }
+  };

Then replace both blocks (user listener around Lines 1385‑1394 and the new api branch) with updateStoredZoomRatio(nextCam.z);.

Based on learnings: "NaN or Inf values have been observed in pan/zoom related fields due to unusual window sizes." Centralizing the ratio computation makes the guard easier to strengthen later (e.g. bailing out when baseZ === HUNDRED_PERCENT fallback is returned).

🤖 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 1470 - 1488, Extract a helper like updateStoredZoomRatio(nextCamZ) that
(1) reads currentPresentationPageRef.current.scaledWidth/height, (2) calls
calculateZoomValueRef.current(...) to get baseZ, (3) guards baseZ (baseZ > 0 and
reject the HUNDRED_PERCENT sentinel if applicable), and (4) computes pKey =
`${presentationIdRef.current}_${curPageIdRef.current}` and assigns
pageActualZoomRatioRef.current[pKey] = nextCamZ / baseZ; replace the duplicated
ratio-setting blocks in both the user-source listener and the api/presenter
branch (the code using calculateZoomValueRef, pKey, and pageActualZoomRatioRef)
with a call to updateStoredZoomRatio(nextCam.z); keep the existing
updateCursorZoomRef.current?.() calls as they are.

2082-2082: Remove presentationWidth and presentationHeight from the effect dependencies.

The syncCameraWithPresentationArea() function only checks and uses presentationAreaWidth and presentationAreaHeight — it never references presentationWidth or presentationHeight. Since both pairs co-change on window resize (the former are derived from the latter), including the slide dimensions in the deps array causes this effect to fire twice per resize event. The cancelAnimationFrame guards make this safe, but it's redundant work that can delay the final camera settle. Keep only the area dimensions in the deps.

🤖 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` at line
2082, Remove presentationWidth and presentationHeight from the effect dependency
array that calls syncCameraWithPresentationArea(): the function only uses
presentationAreaWidth and presentationAreaHeight, so update the deps to include
presentationAreaWidth, presentationAreaHeight, curPageId, and presentationId
(remove presentationWidth and presentationHeight) to avoid duplicate runs on
resize; ensure you keep the existing cancelAnimationFrame guard and invocation
of syncCameraWithPresentationArea() unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx`:
- Around line 1470-1488: Extract a helper like updateStoredZoomRatio(nextCamZ)
that (1) reads currentPresentationPageRef.current.scaledWidth/height, (2) calls
calculateZoomValueRef.current(...) to get baseZ, (3) guards baseZ (baseZ > 0 and
reject the HUNDRED_PERCENT sentinel if applicable), and (4) computes pKey =
`${presentationIdRef.current}_${curPageIdRef.current}` and assigns
pageActualZoomRatioRef.current[pKey] = nextCamZ / baseZ; replace the duplicated
ratio-setting blocks in both the user-source listener and the api/presenter
branch (the code using calculateZoomValueRef, pKey, and pageActualZoomRatioRef)
with a call to updateStoredZoomRatio(nextCam.z); keep the existing
updateCursorZoomRef.current?.() calls as they are.
- Line 2082: Remove presentationWidth and presentationHeight from the effect
dependency array that calls syncCameraWithPresentationArea(): the function only
uses presentationAreaWidth and presentationAreaHeight, so update the deps to
include presentationAreaWidth, presentationAreaHeight, curPageId, and
presentationId (remove presentationWidth and presentationHeight) to avoid
duplicate runs on resize; ensure you keep the existing cancelAnimationFrame
guard and invocation of syncCameraWithPresentationArea() unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 98a1d55f-0623-4277-821a-6c207d38f154

📥 Commits

Reviewing files that changed from the base of the PR and between cbfc9fb and 3d0040f.

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

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

Fixes presenter whiteboard “camera” drift on browser resize by refreshing zoom calculations and persisting the effective zoom ratio, and adds Playwright coverage to detect regressions (including visual checks).

Changes:

  • Update whiteboard camera sync logic to use ref-backed zoom calculators (avoids stale closure values during resize) and to persist zoom ratio when camera updates come from API-driven changes.
  • Simplify camera updates during resize by updating zoom based on stored ratios / toolbar zoom.
  • Add new Playwright resize tests (ratio-based + visual regression) and commit new snapshot baselines.

Reviewed changes

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

File Description
bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx Adjusts zoom calculation plumbing and camera sync behavior during mount/resize; records zoom ratio from more camera update sources.
bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts Adds automated resize/zoom regression tests (ratio assertions + screenshot comparisons).
bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts Wires the new resize tests into the existing whiteboard Playwright suite.
bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts-snapshots/mod-whiteboard-resize-zoomed-shrunk-Chromium-linux.png Adds a new snapshot baseline for the zoomed+shrunk scenario.

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

@ramonlsouza ramonlsouza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While testing, I found another way to reproduce the issue (and it happens even with the changes made in this pull request:

  • increase zoom
  • minimize presentation
  • restore presentation
Screencast.from.2026-04-27.09-44-05.mp4

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx (2)

2253-2265: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Remove the orphan pageActualZoomRatioMap cleanup on line 2260.

This removeItem call has no corresponding setItem anywhere in the codebase. Unlike pageZoomMap and initialViewBoxWidth/Height (which follow a complete read→write→cleanup pattern), the zoom ratio is persisted only in the module-level _pageZoomRatioCache object for cross-mount preservation, not in localStorage. The removeItem is dead code and should be removed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx` around
lines 2253 - 2265, The cleanup in the React.useEffect contains an orphan
localStorage.removeItem('pageActualZoomRatioMap'); remove that single call from
the effect's return cleanup so only the valid keys (initialViewBoxWidth,
initialViewBoxHeight, pageZoomMap) are cleared; locate the useEffect in the
whiteboard component (the block that sets setTldrawIsMounting(true) and
references isMountedRef.current and mountedTimeoutIdRef.current) and delete the
removeItem('pageActualZoomRatioMap') line.

1485-1503: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Two listeners now both populate pageActualZoomRatioRef — but one path is missing.

The user-source listener (line 1379) updates pageActualZoomRatioRef.current[pageKey] when a presenter manually pans or zooms. This new api-source listener (lines 1485–1510) does the same for source === 'api' changes from setCamera() calls (e.g., syncCameraOnPresenterZoom).

However, syncCameraWithPresentationArea (line 1861) uses mergeRemoteChanges to push camera updates, which tldraw classifies as source: 'remote'—not 'api'. Neither the user-source listener nor the new api-source listener will catch these updates, so the cached zoom ratio will silently lag behind actual presenter camera changes from resize/restore flows.

Add || source === 'remote' to the condition at line 1489, or add a third listener for remote camera updates.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx` around
lines 1485 - 1503, The listener registered via editor.store.listen that updates
pageActualZoomRatioRef (using camKey, calculateZoomValueRef,
currentPresentationPageRef, presentationIdRef, curPageIdRef and calling
updateCursorZoomRef) only handles source === 'api'; update the condition to also
treat source === 'remote' (i.e., change if (source === 'api' &&
isPresenterRef.current && isMountedRef.current) to include || source ===
'remote') so syncCameraWithPresentationArea/mergeRemoteChanges updates are
captured and the cached zoom ratio stays in sync.
🧹 Nitpick comments (4)
bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx (1)

122-125: 💤 Low value

Module-level cache persists across all whiteboard remounts in the tab.

_pageZoomRatioCache is a module-level singleton, so its entries accumulate for the entire lifetime of the tab/JS module. The unmount cleanup at line 2253-2265 only clears localStorage and never resets this object, so:

  • Entries grow unbounded across slide/presentation/meeting changes (small in practice, but no upper bound).
  • If two whiteboard component instances ever exist concurrently or if the module is reused after setTldrawIsMounting(true), both share the same cache.

Cache keys include presentationIdRef.current, so cross-presentation contamination is unlikely, but consider clearing entries belonging to the unmounted presentation on cleanup (or pruning on presentationId change) to keep the working set bounded.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx` around
lines 122 - 125, _module-level _pageZoomRatioCache currently accumulates entries
for the lifetime of the tab because cleanup only clears localStorage; modify the
Whiteboard component's unmount/cleanup (the same place that calls
setTldrawIsMounting(true) and clears localStorage) to also remove keys from
_pageZoomRatioCache that belong to the unmounted presentation (use
presentationIdRef.current or the presentationId prop to identify entries), or
alternatively prune entries when presentationId changes in the
componentDidUpdate / useEffect handler dealing with presentationId — this bounds
memory and prevents cross-presentation sharing while keeping the cache behavior
intact.
bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts (2)

203-241: ⚡ Quick win

Deduplicate the React-fiber-walking zoom helper.

Both cameraResyncZoomedVisual and cameraResyncAfterMinimizeRestore contain a near-identical ~35 line page.evaluate block that walks the fiber tree to find the tldraw editor and applies a 2× viewport-centered zoom. Extract this into a private method (e.g. applyDirectFiberZoom(page, factor = 2)) so future changes to the fiber-walk strategy or zoom math only need to be made in one place.

Also applies to: 303-336

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts` around lines
203 - 241, The duplicated React-fiber-walking + zooming page.evaluate block used
in cameraResyncZoomedVisual and cameraResyncAfterMinimizeRestore should be
extracted into a private helper (suggested name
applyDirectFiberZoom(modPage.page, factor = 2)) that accepts the Playwright Page
and zoom factor, performs the same fiber walk, computes newZ = cam.z * factor
and applies the viewport-centered camera set (returning boolean success);
replace both inlined blocks with a call to this helper and assert its boolean
result. Ensure the new helper mirrors the existing logic (checks
`#whiteboard-element`, finds '__reactFiber' key, walks fiber.memoizedState/hooks,
verifies ms.current.setCamera) and forwards { immediate: true } when calling
setCamera so behavior remains identical.

65-65: ⚡ Quick win

Long fixed waitForTimeout calls make these tests slow and timing-fragile.

This file relies on roughly a dozen waitForTimeout(5000) / waitForTimeout(3000) / waitForTimeout(2000) calls (≈ 50+ s of pure sleep per scenario) to wait for the camera-mount polling chain, the React re-render after setViewportSize, and the post-restore remount. Replace at least the longest waits with assertions tied to the state you actually need:

  • After mount: poll getCameraZoom(...) > 0 and getWrapperWidth(...) > 0.
  • After a viewport change: wait for getWrapperWidth to equal the expected new value.
  • After minimize/restore: await this.modPage.page.locator(e.whiteboard).waitFor({ state: 'visible' }) plus a poll on getCameraZoom.

This would meaningfully cut runtime and reduce CI flakiness without changing what's being verified.

Also applies to: 109-109, 116-116, 196-196, 244-244, 269-269, 274-274, 294-294, 341-341, 358-358, 363-363, 392-392, 405-405, 414-414

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts` at line 65,
Replace long fixed sleeps (e.g., await this.modPage.page.waitForTimeout(5000))
with deterministic waits tied to UI state: after initial mount poll until
getCameraZoom(...) > 0 and getWrapperWidth(...) > 0; after viewport changes wait
for getWrapperWidth(...) to equal the expected width following setViewportSize;
after minimize/restore use await
this.modPage.page.locator(e.whiteboard).waitFor({ state: 'visible' }) and then
poll getCameraZoom(...) to be > 0; update all occurrences (including the listed
waitForTimeout calls) to use these assertions/polls so tests are faster and less
flaky.
bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts (1)

12-23: ⚡ Quick win

Thread testInfo into the resize[method]() call.

runResizeTest already takes testInfo and uses it for initModPage/initUserPage, but does not forward it to the actual scenario. Passing it (await resize[method](testInfo)) — and accepting an optional testInfo: TestInfo parameter on the methods that write snapshots — lets cameraResyncZoomedVisual resolve baselines via testInfo.snapshotPath(...) instead of hardcoded -Chromium-linux.png paths, matching how Playwright's own toHaveScreenshot resolves them across platforms.

Proposed change
-  await resize[method]();
+  await resize[method](testInfo);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts` around lines 12
- 23, runResizeTest currently initializes WhiteboardResize with testInfo but
does not pass testInfo into the scenario methods; update runResizeTest to call
await resize[method](testInfo) and modify the WhiteboardResize methods
(cameraResync, cameraResyncVisual, cameraResyncZoomedVisual,
cameraResyncAfterMinimizeRestore) to accept an optional testInfo?: TestInfo
parameter and use testInfo.snapshotPath(...) when creating or resolving
screenshot baselines instead of hardcoded "-Chromium-linux.png" names so
cross-platform snapshot resolution works correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx`:
- Around line 2253-2265: The cleanup in the React.useEffect contains an orphan
localStorage.removeItem('pageActualZoomRatioMap'); remove that single call from
the effect's return cleanup so only the valid keys (initialViewBoxWidth,
initialViewBoxHeight, pageZoomMap) are cleared; locate the useEffect in the
whiteboard component (the block that sets setTldrawIsMounting(true) and
references isMountedRef.current and mountedTimeoutIdRef.current) and delete the
removeItem('pageActualZoomRatioMap') line.
- Around line 1485-1503: The listener registered via editor.store.listen that
updates pageActualZoomRatioRef (using camKey, calculateZoomValueRef,
currentPresentationPageRef, presentationIdRef, curPageIdRef and calling
updateCursorZoomRef) only handles source === 'api'; update the condition to also
treat source === 'remote' (i.e., change if (source === 'api' &&
isPresenterRef.current && isMountedRef.current) to include || source ===
'remote') so syncCameraWithPresentationArea/mergeRemoteChanges updates are
captured and the cached zoom ratio stays in sync.

---

Nitpick comments:
In `@bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx`:
- Around line 122-125: _module-level _pageZoomRatioCache currently accumulates
entries for the lifetime of the tab because cleanup only clears localStorage;
modify the Whiteboard component's unmount/cleanup (the same place that calls
setTldrawIsMounting(true) and clears localStorage) to also remove keys from
_pageZoomRatioCache that belong to the unmounted presentation (use
presentationIdRef.current or the presentationId prop to identify entries), or
alternatively prune entries when presentationId changes in the
componentDidUpdate / useEffect handler dealing with presentationId — this bounds
memory and prevents cross-presentation sharing while keeping the cache behavior
intact.

In `@bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts`:
- Around line 12-23: runResizeTest currently initializes WhiteboardResize with
testInfo but does not pass testInfo into the scenario methods; update
runResizeTest to call await resize[method](testInfo) and modify the
WhiteboardResize methods (cameraResync, cameraResyncVisual,
cameraResyncZoomedVisual, cameraResyncAfterMinimizeRestore) to accept an
optional testInfo?: TestInfo parameter and use testInfo.snapshotPath(...) when
creating or resolving screenshot baselines instead of hardcoded
"-Chromium-linux.png" names so cross-platform snapshot resolution works
correctly.

In `@bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts`:
- Around line 203-241: The duplicated React-fiber-walking + zooming
page.evaluate block used in cameraResyncZoomedVisual and
cameraResyncAfterMinimizeRestore should be extracted into a private helper
(suggested name applyDirectFiberZoom(modPage.page, factor = 2)) that accepts the
Playwright Page and zoom factor, performs the same fiber walk, computes newZ =
cam.z * factor and applies the viewport-centered camera set (returning boolean
success); replace both inlined blocks with a call to this helper and assert its
boolean result. Ensure the new helper mirrors the existing logic (checks
`#whiteboard-element`, finds '__reactFiber' key, walks fiber.memoizedState/hooks,
verifies ms.current.setCamera) and forwards { immediate: true } when calling
setCamera so behavior remains identical.
- Line 65: Replace long fixed sleeps (e.g., await
this.modPage.page.waitForTimeout(5000)) with deterministic waits tied to UI
state: after initial mount poll until getCameraZoom(...) > 0 and
getWrapperWidth(...) > 0; after viewport changes wait for getWrapperWidth(...)
to equal the expected width following setViewportSize; after minimize/restore
use await this.modPage.page.locator(e.whiteboard).waitFor({ state: 'visible' })
and then poll getCameraZoom(...) to be > 0; update all occurrences (including
the listed waitForTimeout calls) to use these assertions/polls so tests are
faster and less flaky.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0f30680a-bee6-4f5f-9aad-827ff61e5bd9

📥 Commits

Reviewing files that changed from the base of the PR and between 3d0040f and bec91d5.

⛔ Files ignored due to path filters (2)
  • bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts-snapshots/mod-whiteboard-resize-zoomed-initial-Chromium-linux.png is excluded by !**/*.png
  • bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts-snapshots/user-whiteboard-resize-zoomed-initial-Chromium-linux.png is excluded by !**/*.png
📒 Files selected for processing (3)
  • bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx
  • bigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts
  • bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts

@Tainan404
Tainan404 requested a review from ramonlsouza May 6, 2026 20:45

@ramonlsouza ramonlsouza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

zoom is now working as expected after minimizing+restoring, but zoom % in toolbar is still resetting to 100%

Screencast.from.2026-05-07.10-26-16.mp4

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
3.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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

♻️ Duplicate comments (1)
bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts (1)

264-291: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Hardcoded -Chromium-linux.png suffix still diverges from toHaveScreenshot's platform-aware path.

The baselines written at Lines 267-268 hardcode -Chromium-linux.png, but the comparison at Lines 290-291 uses toHaveScreenshot('mod-whiteboard-resize-zoomed-initial.png', …) whose resolved path is built by Playwright from the current platform/project. On Linux/Chromium the two paths happen to align; on macOS/Windows the write goes to a stale path and toHaveScreenshot creates and reads a different baseline, defeating the “same-run baseline” design noted in the comment at Lines 258-263.

Thread testInfo from the spec's runResizeTest helper into this method and resolve the path via testInfo.snapshotPath(name) so the written file is exactly the file toHaveScreenshot will read.

🔧 Suggested fix
-  async cameraResyncZoomedVisual() {
+  async cameraResyncZoomedVisual(testInfo: import('@playwright/test').TestInfo) {
     ...
-    const snapshotDir = path.join(__dirname, 'whiteboard.spec.ts-snapshots');
-    fs.mkdirSync(snapshotDir, { recursive: true });
-
-    const modInitialPath = path.join(snapshotDir, 'mod-whiteboard-resize-zoomed-initial-Chromium-linux.png');
-    const userInitialPath = path.join(snapshotDir, 'user-whiteboard-resize-zoomed-initial-Chromium-linux.png');
+    const modInitialPath = testInfo.snapshotPath('mod-whiteboard-resize-zoomed-initial.png');
+    const userInitialPath = testInfo.snapshotPath('user-whiteboard-resize-zoomed-initial.png');
+    fs.mkdirSync(path.dirname(modInitialPath), { recursive: true });
+    fs.mkdirSync(path.dirname(userInitialPath), { recursive: true });

     fs.writeFileSync(modInitialPath, await this.modPage.page.screenshot());
     fs.writeFileSync(userInitialPath, await this.userPage.page.screenshot());
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts` around lines
264 - 291, The snapshot write uses hardcoded '-Chromium-linux.png' suffixes
which won't match Playwright's platform-aware paths used by toHaveScreenshot;
update the whiteboard resize test to accept and use the testInfo from the spec
helper (thread testInfo from runResizeTest into this function) and replace the
manual path construction for modInitialPath and userInitialPath with calls to
testInfo.snapshotPath('mod-whiteboard-resize-zoomed-initial.png') and
testInfo.snapshotPath('user-whiteboard-resize-zoomed-initial.png') respectively
so the written baseline files are the exact files toHaveScreenshot will read
(references: this.modPage.page, this.userPage.page, runResizeTest,
testInfo.snapshotPath).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts`:
- Around line 264-291: The snapshot write uses hardcoded '-Chromium-linux.png'
suffixes which won't match Playwright's platform-aware paths used by
toHaveScreenshot; update the whiteboard resize test to accept and use the
testInfo from the spec helper (thread testInfo from runResizeTest into this
function) and replace the manual path construction for modInitialPath and
userInitialPath with calls to
testInfo.snapshotPath('mod-whiteboard-resize-zoomed-initial.png') and
testInfo.snapshotPath('user-whiteboard-resize-zoomed-initial.png') respectively
so the written baseline files are the exact files toHaveScreenshot will read
(references: this.modPage.page, this.userPage.page, runResizeTest,
testInfo.snapshotPath).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8a21b52f-f872-4c33-9b6c-5ff9268dd85b

📥 Commits

Reviewing files that changed from the base of the PR and between bec91d5 and a938531.

📒 Files selected for processing (2)
  • bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx
  • bigbluebutton-tests/playwright/whiteboard/whiteboardResize.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx

@antobinary antobinary mentioned this pull request May 12, 2026
12 of 17 tasks
@antobinary
antobinary requested a review from ramonlsouza May 12, 2026 15:17

@ramonlsouza ramonlsouza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

24968.mp4

@github-actions

Copy link
Copy Markdown

✅ Automated tests have passed!

@ramonlsouza
ramonlsouza merged commit 2c6d156 into bigbluebutton:v3.0.x-develop May 12, 2026
81 of 85 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] BBB whiteboard not recovering well after resize

4 participants