Repository navigation
fix(whiteboard): prevent crash when slide changes while a viewer is editing - #25345
Conversation
…diting When the presenter changed the slide while a viewer was mid-edit on the whiteboard (select.editing_shape), the [curPageId] effect mutated the tldraw store (cleanupStore + setCurrentPage) and removed the shape being edited without first taking the editor out of editing_shape. The editor was left with a dangling editingShapeId, so the viewer's next pointer-down hit tldraw's "Expected an editing shape!" assertion and tripped the error boundary. Commit the in-progress edit via editor.complete() before the store mutation so tldraw runs EditingShape.onExit while the shape still exists. The call is guarded by getEditingShape() so a normal slide change (no active edit) never resets the presenter's current tool. Add a Playwright regression test (extends MultiUsers) that drives the race and asserts the viewer never throws "Expected an editing shape!" and the whiteboard stays mounted. Fixes bigbluebutton#25332
WalkthroughIn Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@bigbluebutton-tests/playwright/whiteboard/slideChangeWhileEditing.ts`:
- Around line 41-50: The text-entry step in slideChangeWhileEditing is still
racing the editor mount because keyboard.type('Hello') runs before the editing
textarea is guaranteed to exist. In slideChangeWhileEditing, wait for
e.wbEditingTextArea to be present before typing, then keep the existing checks
for e.wbTextTrue and e.wbEditingTextArea after the input to confirm the editor
entered the expected state.
🪄 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: d564d768-543f-4c05-aeaa-a0fde4741f2c
📒 Files selected for processing (4)
bigbluebutton-html5/imports/ui/components/whiteboard/component.jsxbigbluebutton-tests/playwright/core/elements.tsbigbluebutton-tests/playwright/whiteboard/slideChangeWhileEditing.tsbigbluebutton-tests/playwright/whiteboard/whiteboard.spec.ts
| await this.userPage.page.mouse.click(textX, textY); | ||
| await this.userPage.page.waitForTimeout(300); | ||
| await this.userPage.page.keyboard.type('Hello'); | ||
|
|
||
| // Deterministic precondition: the text shape exists (wbTextTrue) AND the editor | ||
| // is actively editing it (tldraw only renders the editing textarea while | ||
| // isEditing is true). Asserting both avoids racing the slide change against an | ||
| // edit that has not actually entered editing_shape yet. | ||
| await this.userPage.hasElement(e.wbTextTrue, 'viewer should have a text shape with content'); | ||
| await this.userPage.hasElement(e.wbEditingTextArea, 'viewer should be actively editing the text shape'); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate the test and the helper methods it relies on.
git ls-files | rg '^bigbluebutton-tests/playwright/whiteboard/slideChangeWhileEditing\.ts$|^bigbluebutton-tests/playwright/.*\.ts$' >/tmp/files.txt
printf '--- candidate files ---\n'
cat /tmp/files.txt
printf '\n--- outline: slideChangeWhileEditing.ts ---\n'
ast-grep outline bigbluebutton-tests/playwright/whiteboard/slideChangeWhileEditing.ts --view expanded || true
printf '\n--- search for wbEditingTextArea and hasElement definitions/usages ---\n'
rg -n "wbEditingTextArea|hasElement\\(" bigbluebutton-tests/playwright -S
printf '\n--- relevant file excerpt ---\n'
nl -ba bigbluebutton-tests/playwright/whiteboard/slideChangeWhileEditing.ts | sed -n '1,120p'Repository: bigbluebutton/bigbluebutton
Length of output: 256
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Show the target file and helper definitions with line numbers.
echo '--- target file ---'
nl -ba bigbluebutton-tests/playwright/whiteboard/slideChangeWhileEditing.ts | sed -n '1,140p'
echo
echo '--- wbEditingTextArea / hasElement references ---'
rg -n "wbEditingTextArea|hasElement\\(" bigbluebutton-tests/playwright -S
echo
echo '--- outline: target file ---'
ast-grep outline bigbluebutton-tests/playwright/whiteboard/slideChangeWhileEditing.ts --view expanded || trueRepository: bigbluebutton/bigbluebutton
Length of output: 225
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- target file ---'
sed -n '1,140p' bigbluebutton-tests/playwright/whiteboard/slideChangeWhileEditing.ts
echo
echo '--- wbEditingTextArea / hasElement references ---'
rg -n "wbEditingTextArea|hasElement\\(" bigbluebutton-tests/playwright -S
echo
echo '--- file list for helper targets ---'
git ls-files bigbluebutton-tests/playwright | rg 'whiteboard|helper|page|util|common'Repository: bigbluebutton/bigbluebutton
Length of output: 50384
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- hasElement implementation(s) ---'
rg -n "async hasElement|hasElement\\(" bigbluebutton-tests/playwright -g '!**/node_modules/**' -g '!**/dist/**' -S | head -n 80
echo
echo '--- elements definitions for wbEditingTextArea / wbTextTrue ---'
rg -n "wbEditingTextArea|wbTextTrue" bigbluebutton-tests/playwright/core bigbluebutton-tests/playwright -S | head -n 40
echo
echo '--- likely base class files ---'
git ls-files bigbluebutton-tests/playwright | rg '(^bigbluebutton-tests/playwright/(core|user)/.*\.ts$|elements\.ts$|util\.ts$)'Repository: bigbluebutton/bigbluebutton
Length of output: 16468
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- core/page.ts outline ---'
ast-grep outline bigbluebutton-tests/playwright/core/page.ts --view expanded || true
echo
echo '--- core/page.ts relevant excerpt ---'
sed -n '1,260p' bigbluebutton-tests/playwright/core/page.ts
echo
echo '--- hasElement / waitAndClick usages in core and whiteboard helpers ---'
rg -n "async hasElement|hasElement\\(|waitAndClick\\(" bigbluebutton-tests/playwright/core bigbluebutton-tests/playwright/whiteboard -SRepository: bigbluebutton/bigbluebutton
Length of output: 25169
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- hasElement implementation ---'
sed -n '340,380p' bigbluebutton-tests/playwright/core/page.ts
echo
echo '--- waitAndClick implementation ---'
sed -n '312,334p' bigbluebutton-tests/playwright/core/page.ts
echo
echo '--- Frame.hasElement implementation ---'
sed -n '520,545p' bigbluebutton-tests/playwright/core/page.tsRepository: bigbluebutton/bigbluebutton
Length of output: 3136
Wait for the editing textarea before typing. The 300ms sleep still leaves keyboard.type('Hello') racing the mount of e.wbEditingTextArea; the later hasElement() checks only assert the state after the fact. Gate the typing step on the textarea first.
🤖 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/slideChangeWhileEditing.ts` around
lines 41 - 50, The text-entry step in slideChangeWhileEditing is still racing
the editor mount because keyboard.type('Hello') runs before the editing textarea
is guaranteed to exist. In slideChangeWhileEditing, wait for e.wbEditingTextArea
to be present before typing, then keep the existing checks for e.wbTextTrue and
e.wbEditingTextArea after the input to confirm the editor entered the expected
state.
✅ Automated tests have passed! |



What's happening
When multi-user whiteboard is on and a viewer is actively editing a text/shape (mid-interaction, before committing), a presenter changing the slide used to crash the viewer's whiteboard with
Expected an editing shape!. Only the editing viewer was affected; everyone else was fine, and the viewer could recover by minimising and restoring the presentation panel.Closes #25332
Why it crashes
The
[curPageId]effect incomponent.jsxhandles slide changes by mutating the tldraw store: it removes shapes that belong to the old page (cleanupStore), switches the current page (setCurrentPage), and clears history — all inside one batch. The problem: it does this without first taking the editor out of theselect.editing_shapestate. So the shape being edited gets removed from under the editor while the state machine is still parked inediting_shapewith a danglingeditingShapeId. The viewer's next pointer-down then callsgetEditingShape(), getsundefined, and tldraw throwsExpected an editing shape!— which trips the error boundary and shows the recovery dialog.The fix
Exit the editing interaction before the store mutation:
complete()dispatches thecompleteevent →EditingShape.onComplete→ the parent state node transitions toidle→onExitruns and clearseditingShapeIdcleanly, while the shape still exists. This mirrors the approach PR #21727 took for the same class of bug inhooks.js(setEditingShape(null)alone doesn't leave theediting_shapestate node, so the next pointer-down still throws —complete()does).The guard on
getEditingShape()is deliberate: without it, an unconditionalcomplete()/tool reset would also fire on a plain slide change and reset the presenter's active tool. With the guard, a normal slide change (no active edit) is completely unaffected.Behavioural note (intentional)
When the presenter changes the slide while a viewer is mid-edit, the in-progress (uncommitted) annotation on the old slide is discarded. This is expected: the slide change destroys the old page's editable surface anyway, so the annotation couldn't have been committed regardless. The alternative (auto-committing partial edits on slide change) would land half-finished text/shapes on the board, which is worse.
Second callsite
There's another
editor.setCurrentPage(...)inhandleTldrawMount(~L1567). It runs only at mount time, when no interactive edit can exist yet (the editor was just constructed), so guarding it would be dead code. Left unguarded on purpose.Non-regression test
New e2e test
bigbluebutton-tests/playwright/whiteboard/slideChangeWhileEditing.ts(registered inwhiteboard.spec.ts):editing_shape(text tool → click canvas → type — without clicking away, which would commit and leave the editing state).wbTextTrueandwbEditingTextArea(the textarea tldraw only renders while actively editing), so the test never races the slide change against an edit that hasn't actually enteredediting_shape.pageerrorlistener on the viewer page (the one that crashes), then the presenter advances the slide.Expected an editing shapeerrors and that the whiteboard stays mounted.Red-then-green proof
0f013afd): the test fails — the viewer pageerror is captured (6 errors), the whiteboard falls into the "Reset data" recovery dialog, slide content is gone.db1253f):2 passed (24s), same sequence, 0 errors, clean Page 2, whiteboard mounted.The existing
Skip slideregression test also continues to pass.Visual evidence
Each MP4 below is the full repro sequence (~30s, low-res to keep the upload small). The same scripted flow runs against the pre-fix bundle (crash) and the fixed bundle (no crash).
Timeline of what to look for in each MP4:
editing_shape).[curPageId]effect fires on the viewer).Expected an editing shape!crash); slide content gone.Click either GIF to open the full MP4 with controls.