Skip to content

fix: table error in collaboration mode #1536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Plugin, PluginKey, PluginView } from "prosemirror-state";
import {
CellSelection,
addColumnAfter,
addColumnBefore,
addRowAfter,
addRowBefore,
CellSelection,
deleteColumn,
deleteRow,
mergeCells,
splitCell,
} from "prosemirror-tables";
import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
import {
RelativeCellIndices,
addRowsOrColumns,
areInSameColumn,
canColumnBeDraggedInto,
Expand All @@ -22,7 +23,6 @@ import {
getDimensionsOfTable,
moveColumn,
moveRow,
RelativeCellIndices,
} from "../../api/blockManipulation/tables/tables.js";
import { nodeToBlock } from "../../api/nodeConversions/nodeToBlock.js";
import { getNodeById } from "../../api/nodeUtil.js";
Expand Down Expand Up @@ -539,7 +539,12 @@ export class TableHandlesView<

// Hide handles if the table block has been removed.
this.state.block = this.editor.getBlock(this.state.block.id)!;
if (!this.state.block) {
if (
!this.state.block ||
// when collaborating, the table element might be replaced and out of date
// because yjs replaces the element when for example you change the color via the side menu
!this.tableElement?.isConnected
) {
this.state.show = false;
this.state.showAddOrRemoveRowsButton = false;
this.state.showAddOrRemoveColumnsButton = false;
Expand Down Expand Up @@ -569,6 +574,7 @@ export class TableHandlesView<

// Update bounding boxes.
const tableBody = this.tableElement!.querySelector("tbody");

if (!tableBody) {
throw new Error(
"Table block does not contain a 'tbody' HTML element. This should never happen."
Expand Down
Loading