Repository navigation
fix: bn- table crash with static toolbar - #25076
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
|
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
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-html5/imports/ui/components/bn-shared-notes/component.tsx`:
- Around line 79-88: The appendTransaction hook sets a safe selection using
TextSelection.near but doesn't guard against re-entry; after you call
newState.tr.setSelection(safeSelection) the plugin is invoked again and will
create an identical transaction. Update appendTransaction (the appendTransaction
function in this file) to compare the proposed safeSelection to the current
selection (newState.selection) and return null if they are equal (e.g., compare
positions or use TextSelection.eq semantics) before returning the new
transaction, so you only dispatch when the selection actually changes.
🪄 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: 113079c8-6385-4afb-8493-1df83dda825b
📒 Files selected for processing (1)
bigbluebutton-html5/imports/ui/components/bn-shared-notes/component.tsx
| appendTransaction(_transactions, _oldState, newState) { | ||
| const { selection } = newState; | ||
| if (selection.$from.pos > 2 || selection.$to.pos > 2) return null; | ||
| const firstBlockContent = newState.doc.firstChild?.firstChild?.firstChild; | ||
| if (!firstBlockContent || firstBlockContent.type.name !== 'table') return null; | ||
| if (newState.doc.content.size < 1) return null; | ||
| const safeSelection = TextSelection.near(newState.doc.resolve(1), 1); | ||
| if (safeSelection.from === 0) return null; | ||
| return newState.tr.setSelection(safeSelection); | ||
| }, |
There was a problem hiding this comment.
❓ Verification inconclusive
ProseMirror Plugin appendTransaction recursive re-entry behavior documentation
ProseMirror's PluginSpec.appendTransaction method allows plugins to append additional transactions after an initial set of transactions are applied to the editor state. The official documentation describes its re-entry (recursive) behavior as follows: "Allows the plugin to append another transaction to be applied after the given array of transactions. When another plugin appends a transaction after this was called, it is called again with the new state and new transactions—but only the new transactions, i.e. it won't be passed transactions that it already saw."[1][2][3] This design enables iterative refinement where multiple plugins can chain appends, but prevents infinite recursion for a single plugin by only passing newly appended transactions in subsequent calls. Appended transactions are marked with an 'appendedTransaction' meta key referencing the root transaction (fixed in 2018 to avoid circular references).[4][5][6] No explicit depth limit or stack overflow guard is documented in the core implementation, but the mechanism relies on plugins conditionally returning transactions (e.g., only when specific conditions like schema violations are met) to terminate the chain.[7] Infinite loops can occur in edge cases like collaborative editing races or history interactions, requiring workarounds such as splitting transactions or using filterTransaction.[8][7] Primary sources: Official ProseMirror reference manual[1][3], prosemirror-state plugin.ts source code[2], and related GitHub issues/PRs on history and meta handling[4][8][5][6]. The repository has moved to https://code.haverbeke.berlin/prosemirror/prosemirror-state, but documentation remains at prosemirror.net.[9]
Citations:
- 1: https://prosemirror.net/docs/ref/
- 2: https://github.com/ProseMirror/prosemirror-state/blob/master/src/plugin.ts
- 3: https://prosemirror.net/docs/ref
- 4: Pass the root transaction to appendedTransaction meta ProseMirror/prosemirror-state#13
- 5: [prosemirror-history] appendTransaction to undo ProseMirror/prosemirror#819
- 6: Fix redoing after append transaction ProseMirror/prosemirror-history#3
- 7: https://discuss.prosemirror.net/t/amendtransaction/1532
- 8: History can get out of state if closing history in an appended transaction ProseMirror/prosemirror#984
- 9: https://github.com/prosemirror/prosemirror-state/
Guard against re-entry: compare the proposed selection to the current one.
ProseMirror's appendTransaction is re-invoked after the plugin appends a transaction. Per the official ProseMirror documentation: "When another plugin appends a transaction after this was called, it is called again with the new state and new transactions." This means after your plugin calls setSelection, the hook will be invoked again with the updated state. If TextSelection.near(doc.resolve(1), 1) still resolves to a position matching the current selection (which it will, after the first invocation), the plugin will dispatch an identical setSelection transaction again, creating redundant emissions. The current guard safeSelection.from === 0 only covers the degenerate case and does not prevent re-entry.
Add an equality check to stop re-entry:
Proposed fix
appendTransaction(_transactions, _oldState, newState) {
const { selection } = newState;
if (selection.$from.pos > 2 || selection.$to.pos > 2) return null;
const firstBlockContent = newState.doc.firstChild?.firstChild?.firstChild;
if (!firstBlockContent || firstBlockContent.type.name !== 'table') return null;
if (newState.doc.content.size < 1) return null;
const safeSelection = TextSelection.near(newState.doc.resolve(1), 1);
if (safeSelection.from === 0) return null;
+ if (safeSelection.eq(selection)) return null;
return newState.tr.setSelection(safeSelection);
},📝 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.
| appendTransaction(_transactions, _oldState, newState) { | |
| const { selection } = newState; | |
| if (selection.$from.pos > 2 || selection.$to.pos > 2) return null; | |
| const firstBlockContent = newState.doc.firstChild?.firstChild?.firstChild; | |
| if (!firstBlockContent || firstBlockContent.type.name !== 'table') return null; | |
| if (newState.doc.content.size < 1) return null; | |
| const safeSelection = TextSelection.near(newState.doc.resolve(1), 1); | |
| if (safeSelection.from === 0) return null; | |
| return newState.tr.setSelection(safeSelection); | |
| }, | |
| appendTransaction(_transactions, _oldState, newState) { | |
| const { selection } = newState; | |
| if (selection.$from.pos > 2 || selection.$to.pos > 2) return null; | |
| const firstBlockContent = newState.doc.firstChild?.firstChild?.firstChild; | |
| if (!firstBlockContent || firstBlockContent.type.name !== 'table') return null; | |
| if (newState.doc.content.size < 1) return null; | |
| const safeSelection = TextSelection.near(newState.doc.resolve(1), 1); | |
| if (safeSelection.from === 0) return null; | |
| if (safeSelection.eq(selection)) return null; | |
| return newState.tr.setSelection(safeSelection); | |
| }, |
🤖 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/bn-shared-notes/component.tsx`
around lines 79 - 88, The appendTransaction hook sets a safe selection using
TextSelection.near but doesn't guard against re-entry; after you call
newState.tr.setSelection(safeSelection) the plugin is invoked again and will
create an identical transaction. Update appendTransaction (the appendTransaction
function in this file) to compare the proposed safeSelection to the current
selection (newState.selection) and return null if they are equal (e.g., compare
positions or use TextSelection.eq semantics) before returning the new
transaction, so you only dispatch when the selection actually changes.
✅ Automated tests have passed! |
Co-authored-by: Guilherme Pereira Leme <[email protected]>
) Co-authored-by: Anton Georgiev <[email protected]>



What does this PR do?
The issue that generated this problem in BBB is described in BlockNote, see issue here.
This PR is just a temporary, but robust fix. (we'd still need to wait for the correct approach from BN).
Motivation
The error crashes the entire client.
How to test
See steps in the issue from BN
More
See video of the reproduction of the bug down here:
Bug:
bn-table-crash-bbb.mp4
Fixed:
bn-table-crash-fix-bbb.mp4