Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(notebooks): guard floating suggestions against destroyed tiptap editor (#59051)

Christiaan Hendriksen4aef9e93925a
diff --git a/frontend/src/lib/components/RichContentEditor/utils.ts b/frontend/src/lib/components/RichContentEditor/utils.ts
index bba7a51732e1..df142c552820 100644
--- a/frontend/src/lib/components/RichContentEditor/utils.ts
+++ b/frontend/src/lib/components/RichContentEditor/utils.ts
@@ -77,8 +77,11 @@ export function createEditor(editor: TTEditor): RichContentEditorType {
}
},
pasteContent: (position: number, text: string) => {
- editor?.chain().focus().setTextSelection(position).run()
- editor?.view.pasteText(text)
+ if (editor.isDestroyed) {
+ return
+ }
+ editor.chain().focus().setTextSelection(position).run()
+ editor.view.pasteText(text)
},
findNode: (position: number) => findNode(editor, position),
findNodePositionByAttrs: (attrs: Record<string, any>) => findNodePositionByAttrs(editor, attrs),
@@ -91,6 +94,9 @@ export function createEditor(editor: TTEditor): RichContentEditorType {
},
scrollToPosition(position) {
queueMicrotask(() => {
+ if (editor.isDestroyed) {
+ return
+ }
const { node } = editor.view.domAtPos(position)
const element =
node.nodeType === Node.TEXT_NODE
diff --git a/frontend/src/scenes/notebooks/Notebook/TableMenu.tsx b/frontend/src/scenes/notebooks/Notebook/TableMenu.tsx
index 4f8522db09c7..4cfc039bcf59 100644
--- a/frontend/src/scenes/notebooks/Notebook/TableMenu.tsx
+++ b/frontend/src/scenes/notebooks/Notebook/TableMenu.tsx
@@ -131,6 +131,11 @@ export function TableMenu(): JSX.Element | null {
return
}
+ // view.dom hits the v3 throwing Proxy.
+ if (ttEditor.isDestroyed) {
+ return
+ }
+
const target = e.target as HTMLElement
// If mouse is over a grip wrapper, keep current state
@@ -167,7 +172,7 @@ export function TableMenu(): JSX.Element | null {
/** Returns a 2D array [row][col] of ProseMirror cell positions for the hovered table */
const getTableCellPositions = useCallback((): number[][] => {
- if (!ttEditor || !hoveredCell) {
+ if (!ttEditor || !hoveredCell || ttEditor.isDestroyed) {
return []
}
const tablePos = ttEditor.view.posAtDOM(hoveredCell.table, 0) - 1
diff --git a/frontend/src/scenes/notebooks/Notebook/notebookCollabLogic.ts b/frontend/src/scenes/notebooks/Notebook/notebookCollabLogic.ts
index ff8e1210aa67..6b98850f856c 100644
--- a/frontend/src/scenes/notebooks/Notebook/notebookCollabLogic.ts
+++ b/frontend/src/scenes/notebooks/Notebook/notebookCollabLogic.ts
@@ -117,7 +117,7 @@ export const notebookCollabLogic = kea<notebookCollabLogicType>([
ackLocalSteps: ({ steps, clientID }) => {
const editor = values.ttEditor
- if (!editor || !steps.length) {
+ if (!editor || editor.isDestroyed || !steps.length) {
return
}
try {
@@ -138,7 +138,7 @@ export const notebookCollabLogic = kea<notebookCollabLogicType>([
applyRemoteSteps: ({ steps }) => {
const editor = values.ttEditor
- if (!editor) {
+ if (!editor || editor.isDestroyed) {
return
}
const localContent = editor.getJSON()
@@ -183,7 +183,7 @@ export const notebookCollabLogic = kea<notebookCollabLogicType>([
return
}
const editor = values.ttEditor
- if (!editor) {
+ if (!editor || editor.isDestroyed) {
return
}
const localContent = editor.getJSON()
diff --git a/frontend/src/scenes/notebooks/Suggestions/FloatingSuggestions.tsx b/frontend/src/scenes/notebooks/Suggestions/FloatingSuggestions.tsx
index 1386b70aea0b..a3e27c83436f 100644
--- a/frontend/src/scenes/notebooks/Suggestions/FloatingSuggestions.tsx
+++ b/frontend/src/scenes/notebooks/Suggestions/FloatingSuggestions.tsx
@@ -22,6 +22,10 @@ export function FloatingSuggestions(): JSX.Element | null {
const { Component } = activeSuggestion
const handleUpdate = (): void => {
+ if (ttEditor.isDestroyed) {
+ return
+ }
+
const selection = window.getSelection()
if (selection && selection.anchorNode && selection.anchorNode.parentElement) {