mirror of
https://github.com/outline/outline.git
synced 2026-12-03 01:59:03 +03:00
fix: Crash when a remote edit arrives during a column resize (#13452)
Every remote change is applied as a full document replacement, which invalidates the column resize handle while the drag is still active. Releasing the pointer then resolved position -1 and threw. Cancel the drag when the handle no longer points at a cell. Fixes OUTLINE-CLOUD-B3R
This commit is contained in:
1 parent
628615f9bc
commit
cdc10b4564
3 files changed
+102
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import type { Transaction, EditorState } from "prosemirror-state";
|
||||
import { Plugin } from "prosemirror-state";
|
||||
import { columnResizingPluginKey } from "prosemirror-tables";
|
||||
|
||||
/**
|
||||
* A ProseMirror plugin that cancels an in-progress column resize once the drag
|
||||
* handle no longer points at a cell. The handle is invalidated whenever the
|
||||
* document is replaced under the pointer, such as by a collaborative edit from
|
||||
* another user, and resizing with an invalid handle throws.
|
||||
*/
|
||||
export class TableColumnResizePlugin extends Plugin {
|
||||
constructor() {
|
||||
super({
|
||||
appendTransaction: (
|
||||
transactions: readonly Transaction[],
|
||||
_oldState: EditorState,
|
||||
newState: EditorState
|
||||
) => {
|
||||
if (!transactions.some((transaction) => transaction.docChanged)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const resizeState = columnResizingPluginKey.getState(newState);
|
||||
if (!resizeState?.dragging || resizeState.activeHandle > -1) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return newState.tr.setMeta(columnResizingPluginKey, {
|
||||
setDragging: null,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user