Skip to content

Commit 8e9195b

Browse files
authored
fix: table error in collaboration mode
1 parent 161d6dd commit 8e9195b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { Plugin, PluginKey, PluginView } from "prosemirror-state";
22
import {
3+
CellSelection,
34
addColumnAfter,
45
addColumnBefore,
56
addRowAfter,
67
addRowBefore,
7-
CellSelection,
88
deleteColumn,
99
deleteRow,
1010
mergeCells,
1111
splitCell,
1212
} from "prosemirror-tables";
1313
import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
1414
import {
15+
RelativeCellIndices,
1516
addRowsOrColumns,
1617
areInSameColumn,
1718
canColumnBeDraggedInto,
@@ -22,7 +23,6 @@ import {
2223
getDimensionsOfTable,
2324
moveColumn,
2425
moveRow,
25-
RelativeCellIndices,
2626
} from "../../api/blockManipulation/tables/tables.js";
2727
import { nodeToBlock } from "../../api/nodeConversions/nodeToBlock.js";
2828
import { getNodeById } from "../../api/nodeUtil.js";
@@ -539,7 +539,12 @@ export class TableHandlesView<
539539

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

570575
// Update bounding boxes.
571576
const tableBody = this.tableElement!.querySelector("tbody");
577+
572578
if (!tableBody) {
573579
throw new Error(
574580
"Table block does not contain a 'tbody' HTML element. This should never happen."

0 commit comments

Comments
 (0)