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.

feat(notebooks): show conflict modal on 410 error (#58213)

Alex Lider9bf44b34b6a0
diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx
index 659143166049..5886028f3f88 100644
--- a/frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx
+++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx
@@ -131,7 +131,7 @@ const Component = ({
if (isDataTableNode(modifiedQuery) && isEventsQuery(modifiedQuery.source)) {
modifiedQuery.source.fixedProperties = canvasFiltersOverride
- updateAttributes({ ...attributes, isDefaultFilterApplied: true })
+ updateAttributes({ isDefaultFilterApplied: true })
}
return modifiedQuery
@@ -282,12 +282,12 @@ export const Settings = ({
!isDefaultFilterApplied
) {
modifiedQuery.source.properties = canvasFiltersOverride
- updateAttributes({ ...attributes, isDefaultFilterApplied: true })
+ updateAttributes({ isDefaultFilterApplied: true })
}
if (isDataTableNode(modifiedQuery) && isEventsQuery(modifiedQuery.source) && !isDefaultFilterApplied) {
modifiedQuery.source.fixedProperties = canvasFiltersOverride
- updateAttributes({ ...attributes, isDefaultFilterApplied: true })
+ updateAttributes({ isDefaultFilterApplied: true })
}
return modifiedQuery
diff --git a/frontend/src/scenes/notebooks/Nodes/utils.tsx b/frontend/src/scenes/notebooks/Nodes/utils.tsx
index 83a82435c0dc..b6b64c87adcb 100644
--- a/frontend/src/scenes/notebooks/Nodes/utils.tsx
+++ b/frontend/src/scenes/notebooks/Nodes/utils.tsx
@@ -265,9 +265,13 @@ export function useSyncedAttributes<T extends CustomNotebookNodeAttributes>(
{} as Record<string, any>
)
- const hasChanges = Object.keys(stringifiedAttrs).some(
- (key) => previousNodeAttrs.current?.[key] !== stringifiedAttrs[key]
- )
+ // Compare in stringified form — prosemirror state may hold the value as an object,
+ // stringifiedAttrs as a string. Without this, no-op updates dispatch a transaction.
+ const hasChanges = Object.keys(stringifiedAttrs).some((key) => {
+ const prev = previousNodeAttrs.current?.[key]
+ const prevStringified = prev && typeof prev === 'object' ? JSON.stringify(prev) : prev
+ return prevStringified !== stringifiedAttrs[key]
+ })
if (!hasChanges) {
return
diff --git a/frontend/src/scenes/notebooks/Notebook/Notebook.tsx b/frontend/src/scenes/notebooks/Notebook/Notebook.tsx
index 25968be8dfd1..c44a7733bb7e 100644
--- a/frontend/src/scenes/notebooks/Notebook/Notebook.tsx
+++ b/frontend/src/scenes/notebooks/Notebook/Notebook.tsx
@@ -18,6 +18,7 @@ import { SCRATCHPAD_NOTEBOOK } from '~/models/notebooksModel'
import { AddExperimentsToNotebookModal } from '../AddExperimentsToNotebookModal/AddExperimentsToNotebookModal'
import { AddInsightsToNotebookModal } from '../AddInsightsToNotebookModal/AddInsightsToNotebookModal'
import { Editor } from './Editor'
+import { NotebookCollabConflictModal } from './NotebookCollabConflictModal'
import { NotebookColumnLeft } from './NotebookColumnLeft'
import { NotebookColumnRight } from './NotebookColumnRight'
import { NotebookConflictWarning } from './NotebookConflictWarning'
@@ -126,6 +127,7 @@ export function Notebook({
</LemonBanner>
)}
<NotebookHistoryWarning />
+ <NotebookCollabConflictModal />
{shortId === SCRATCHPAD_NOTEBOOK.short_id ? (
<LemonBanner
type="info"
diff --git a/frontend/src/scenes/notebooks/Notebook/NotebookCollabConflictModal.tsx b/frontend/src/scenes/notebooks/Notebook/NotebookCollabConflictModal.tsx
new file mode 100644
index 000000000000..12f475a13b81
--- /dev/null
+++ b/frontend/src/scenes/notebooks/Notebook/NotebookCollabConflictModal.tsx
@@ -0,0 +1,50 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonButton, LemonModal } from '@posthog/lemon-ui'
+
+import { notebookLogic } from './notebookLogic'
+import { NotebookPreview } from './NotebookPreview'
+
+export function NotebookCollabConflictModal(): JSX.Element {
+ const { collabConflict } = useValues(notebookLogic)
+ const { dismissCollabConflict, discardLocalChanges, copyUnsavedToNewNotebook } = useActions(notebookLogic)
+
+ return (
+ <LemonModal
+ isOpen={!!collabConflict}
+ onClose={dismissCollabConflict}
+ title="We couldn't sync your changes"
+ description="The notebook has changed too much since you started typing. We can't reconcile the changes automatically."
+ footer={
+ <>
+ <LemonButton type="secondary" onClick={copyUnsavedToNewNotebook}>
+ Copy unsaved version to a new notebook
+ </LemonButton>
+ <LemonButton type="primary" onClick={discardLocalChanges}>
+ Discard unsaved changes and reload
+ </LemonButton>
+ </>
+ }
+ width={1200}
+ >
+ <div className="grid grid-cols-2 border rounded overflow-hidden">
+ <div className="min-w-0 border-r">
+ <div className="p-2 border-b text-xs font-medium text-secondary bg-surface-secondary">
+ Last saved version
+ </div>
+ <div className="p-3 max-h-[30rem] overflow-y-auto overflow-x-hidden break-words">
+ <NotebookPreview content={collabConflict?.serverContent ?? null} />
+ </div>
+ </div>
+ <div className="min-w-0">
+ <div className="p-2 border-b text-xs font-medium text-secondary bg-surface-secondary">
+ Your unsaved changes
+ </div>
+ <div className="p-3 max-h-[30rem] overflow-y-auto overflow-x-hidden break-words">
+ <NotebookPreview content={collabConflict?.localContent ?? null} />
+ </div>
+ </div>
+ </div>
+ </LemonModal>
+ )
+}
diff --git a/frontend/src/scenes/notebooks/Notebook/NotebookPreview.tsx b/frontend/src/scenes/notebooks/Notebook/NotebookPreview.tsx
new file mode 100644
index 000000000000..62a370554d27
--- /dev/null
+++ b/frontend/src/scenes/notebooks/Notebook/NotebookPreview.tsx
@@ -0,0 +1,165 @@
+import { Fragment } from 'react'
+
+import {
+ IconChat,
+ IconFlask,
+ IconGraph,
+ IconHogQL,
+ IconImage,
+ IconNotebook,
+ IconPython,
+ IconRewindPlay,
+ IconSquareRoot,
+} from '@posthog/icons'
+import { Link } from '@posthog/lemon-ui'
+
+import { JSONContent, RichContentNodeType } from 'lib/components/RichContentEditor/types'
+
+import { NotebookNodeType } from '../types'
+import { KNOWN_NODES } from '../utils'
+
+// Icons for the most common embed types.
+// Anything not listed here gets the generic IconNotebook fallback.
+const NODE_ICONS: Partial<Record<NotebookNodeType, JSX.Element>> = {
+ [NotebookNodeType.Query]: <IconGraph />,
+ [NotebookNodeType.HogQLSQL]: <IconHogQL />,
+ [NotebookNodeType.DuckSQL]: <IconHogQL />,
+ [NotebookNodeType.Python]: <IconPython />,
+ [NotebookNodeType.Latex]: <IconSquareRoot />,
+ [NotebookNodeType.Recording]: <IconRewindPlay />,
+ [NotebookNodeType.Image]: <IconImage />,
+ [NotebookNodeType.Experiment]: <IconFlask />,
+ [NotebookNodeType.Survey]: <IconChat />,
+}
+
+const MARK_WRAPPERS: Record<string, (children: JSX.Element, attrs?: Record<string, any>) => JSX.Element> = {
+ bold: (c) => <strong>{c}</strong>,
+ italic: (c) => <em>{c}</em>,
+ code: (c) => <code>{c}</code>,
+ underline: (c) => <u>{c}</u>,
+ strike: (c) => <s>{c}</s>,
+ comment: (c) => <mark className="bg-fill-highlight-100">{c}</mark>,
+ link: (c, attrs) => (
+ <Link to={attrs?.href ?? '#'} target="_blank">
+ {c}
+ </Link>
+ ),
+}
+
+// Read-only renderer for a notebook ProseMirror doc
+// used to preview notebook content without mounting a full Tiptap editor.
+export function NotebookPreview({ content }: { content: JSONContent | null | undefined }): JSX.Element {
+ if (!content) {
+ return <p className="text-secondary italic">Empty notebook</p>
+ }
+ return <div className="prose prose-sm max-w-none">{renderNode(content, 'root')}</div>
+}
+
+function renderNode(node: JSONContent, key: string): JSX.Element | null {
+ // Mention is the one inline ph-* node — render as a span so it sits in a paragraph.
+ if (node.type === RichContentNodeType.Mention) {
+ return (
+ <span key={key} className="bg-fill-highlight-100 px-1 rounded font-medium">
+ @{node.attrs?.id ?? 'member'}
+ </span>
+ )
+ }
+ if (node.type?.startsWith('ph-')) {
+ return <EmbedPlaceholder key={key} icon={pickIcon(node.type)} label={describeEmbed(node.type)} />
+ }
+
+ switch (node.type) {
+ case 'text':
+ return <Fragment key={key}>{applyMarks(<>{node.text}</>, node.marks)}</Fragment>
+ case 'hardBreak':
+ return <br key={key} />
+ case 'doc':
+ return <Fragment key={key}>{renderChildren(node, key)}</Fragment>
+ case 'heading':
+ return renderHeading(node, key)
+ case 'paragraph':
+ return <p key={key}>{renderChildren(node, key)}</p>
+ case 'bulletList':
+ return <ul key={key}>{renderListItems(node, key)}</ul>
+ case 'orderedList':
+ return <ol key={key}>{renderListItems(node, key)}</ol>
+ case 'taskList':
+ return (
+ <ul key={key} className="list-none pl-0">
+ {renderTaskItems(node, key)}
+ </ul>
+ )
+ case 'table':
+ return (
+ <table key={key} className="border-collapse">
+ <tbody>{renderChildren(node, key)}</tbody>
+ </table>
+ )
+ case 'tableRow':
+ return <tr key={key}>{renderChildren(node, key)}</tr>
+ case 'tableHeader':
+ return <th key={key}>{renderChildren(node, key)}</th>
+ case 'tableCell':
+ return <td key={key}>{renderChildren(node, key)}</td>
+ case 'codeBlock':
+ return (
+ <pre key={key}>
+ <code>{renderChildren(node, key)}</code>
+ </pre>
+ )
+ case 'blockquote':
+ return <blockquote key={key}>{renderChildren(node, key)}</blockquote>
+ case 'horizontalRule':
+ return <hr key={key} />
+ default:
+ // Unknown node — recurse into children to avoid silently dropping content
+ return node.content ? <Fragment key={key}>{renderChildren(node, key)}</Fragment> : null
+ }
+}
+
+function renderHeading(node: JSONContent, key: string): JSX.Element {
+ const level = Math.min(Math.max(node.attrs?.level ?? 1, 1), 6) as 1 | 2 | 3 | 4 | 5 | 6
+ const Tag = `h${level}` as const
+ return <Tag key={key}>{renderChildren(node, key)}</Tag>
+}
+
+function renderChildren(node: JSONContent, key: string): (JSX.Element | null)[] {
+ return (node.content ?? []).map((child, i) => renderNode(child, `${key}-${i}`))
+}
+
+function renderListItems(node: JSONContent, key: string): JSX.Element[] {
+ return (node.content ?? []).map((item, i) => <li key={`${key}-${i}`}>{renderChildren(item, `${key}-${i}`)}</li>)
+}
+
+function renderTaskItems(node: JSONContent, key: string): JSX.Element[] {
+ return (node.content ?? []).map((item, i) => (
+ <li key={`${key}-${i}`} className="flex items-start gap-2">
+ <input type="checkbox" checked={!!item.attrs?.checked} disabled className="mt-1" />
+ <div>{renderChildren(item, `${key}-${i}`)}</div>
+ </li>
+ ))
+}
+
+function applyMarks(element: JSX.Element, marks: JSONContent['marks']): JSX.Element {
+ return (marks ?? []).reduce((wrapped, mark) => {
+ const wrap = MARK_WRAPPERS[mark.type]
+ return wrap ? wrap(wrapped, mark.attrs) : wrapped
+ }, element)
+}
+
+function describeEmbed(type: string): string {
+ return KNOWN_NODES[type]?.titlePlaceholder ?? type
+}
+
+function pickIcon(type: string): JSX.Element {
+ return NODE_ICONS[type as NotebookNodeType] ?? <IconNotebook />
+}
+
+function EmbedPlaceholder({ icon, label }: { icon: JSX.Element; label: string }): JSX.Element {
+ return (
+ <div className="my-2 px-3 py-2 border rounded flex items-center gap-2 text-default text-sm">
+ <span className="text-secondary text-lg">{icon}</span>
+ <span>{label}</span>
+ </div>
+ )
+}
diff --git a/frontend/src/scenes/notebooks/Notebook/notebookCollabLogic.test.ts b/frontend/src/scenes/notebooks/Notebook/notebookCollabLogic.test.ts
index a1e112496d0a..eea56df00221 100644
--- a/frontend/src/scenes/notebooks/Notebook/notebookCollabLogic.test.ts
+++ b/frontend/src/scenes/notebooks/Notebook/notebookCollabLogic.test.ts
@@ -136,7 +136,7 @@ describe('notebookCollabLogic', () => {
expect(tr.docChanged).toBe(true)
})
- it('swallows errors from malformed steps instead of throwing', () => {
+ it('throws on malformed steps so the caller can surface the conflict modal', () => {
const editor = createMockEditor(0)
expect(() =>
@@ -145,7 +145,7 @@ describe('notebookCollabLogic', () => {
clientId: REMOTE_CLIENT_ID,
version: 1,
})
- ).not.toThrow()
+ ).toThrow()
expect(editor.view.dispatch).not.toHaveBeenCalled()
})
})
diff --git a/frontend/src/scenes/notebooks/Notebook/notebookCollabLogic.ts b/frontend/src/scenes/notebooks/Notebook/notebookCollabLogic.ts
index 6ef5dc307f93..ff8e1210aa67 100644
--- a/frontend/src/scenes/notebooks/Notebook/notebookCollabLogic.ts
+++ b/frontend/src/scenes/notebooks/Notebook/notebookCollabLogic.ts
@@ -4,10 +4,8 @@ import { Step } from '@tiptap/pm/transform'
import { actions, beforeUnmount, kea, key, listeners, path, props, reducers } from 'kea'
import posthog from 'posthog-js'
-import { lemonToast } from '@posthog/lemon-ui'
-
import api from 'lib/api'
-import { TTEditor } from 'lib/components/RichContentEditor/types'
+import { JSONContent, TTEditor } from 'lib/components/RichContentEditor/types'
import { uuid } from 'lib/utils'
import type { notebookCollabLogicType } from './notebookCollabLogicType'
@@ -41,6 +39,7 @@ export type RemoteStep = {
* Idempotent step apply. The same step may arrive via SSE *and* via the 409
* conflict body on a concurrent save; whichever lands first wins, the second
* skips by version. Presence is always propagated so the caret stays in sync.
+ * Throws if the step itself can't be applied — caller decides how to surface it.
*/
export function applyRemoteStep(editor: TTEditor, remote: RemoteStep): void {
const expected = getVersion(editor.state) + 1
@@ -66,20 +65,15 @@ export function applyRemoteStep(editor: TTEditor, remote: RemoteStep): void {
return
}
- try {
- const step = Step.fromJSON(editor.state.schema, remote.step)
- let tr = receiveTransaction(editor.state, [step], [remote.clientId], {
- mapSelectionBackward: true,
- })
- const meta = presenceMeta()
- if (meta) {
- tr = tr.setMeta(REMOTE_PRESENCE_META, meta)
- }
- editor.view.dispatch(tr)
- } catch (e) {
- posthog.captureException(e as Error, { action: 'notebook collab apply remote step' })
- lemonToast.error('Failed to sync notebook changes. Please reload the page.')
+ const step = Step.fromJSON(editor.state.schema, remote.step)
+ let tr = receiveTransaction(editor.state, [step], [remote.clientId], {
+ mapSelectionBackward: true,
+ })
+ const meta = presenceMeta()
+ if (meta) {
+ tr = tr.setMeta(REMOTE_PRESENCE_META, meta)
}
+ editor.view.dispatch(tr)
}
export const notebookCollabLogic = kea<notebookCollabLogicType>([
@@ -94,6 +88,8 @@ export const notebookCollabLogic = kea<notebookCollabLogicType>([
ackLocalSteps: (steps: Record<string, any>[], clientID: string) => ({ steps, clientID }),
/** Apply steps received from SSE or a 409 body. Idempotent by version. */
applyRemoteSteps: (steps: RemoteStep[]) => ({ steps }),
+ /** Bubbles up to notebookLogic when receiveTransaction throws — the conflict modal opens. */
+ rebaseFailed: (params: { localContent: JSONContent; localText: string }) => params,
connectStream: true,
disconnectStream: true,
}),
@@ -145,11 +141,19 @@ export const notebookCollabLogic = kea<notebookCollabLogicType>([
if (!editor) {
return
}
+ const localContent = editor.getJSON()
+ const localText = editor.getText()
for (const remote of steps) {
if (remote.clientId === values.clientID) {
continue
}
- applyRemoteStep(editor, remote)
+ try {
+ applyRemoteStep(editor, remote)
+ } catch (e) {
+ posthog.captureException(e as Error, { action: 'notebook collab apply remote step' })
+ actions.rebaseFailed({ localContent, localText })
+ return
+ }
}
},
@@ -182,16 +186,23 @@ export const notebookCollabLogic = kea<notebookCollabLogicType>([
if (!editor) {
return
}
- applyRemoteStep(editor, {
- step: parsed.step,
- clientId: parsed.client_id,
- version,
- presence: {
- userId: parsed.user_id,
- userName: parsed.user_name,
- head: parsed.cursor_head,
- },
- })
+ const localContent = editor.getJSON()
+ const localText = editor.getText()
+ try {
+ applyRemoteStep(editor, {
+ step: parsed.step,
+ clientId: parsed.client_id,
+ version,
+ presence: {
+ userId: parsed.user_id,
+ userName: parsed.user_name,
+ head: parsed.cursor_head,
+ },
+ })
+ } catch (e) {
+ posthog.captureException(e as Error, { action: 'notebook collab apply remote step' })
+ actions.rebaseFailed({ localContent, localText })
+ }
}
const onError = (error: any): void => {
diff --git a/frontend/src/scenes/notebooks/Notebook/notebookLogic.ts b/frontend/src/scenes/notebooks/Notebook/notebookLogic.ts
index 263f51b56f27..b7a83b70378e 100644
--- a/frontend/src/scenes/notebooks/Notebook/notebookLogic.ts
+++ b/frontend/src/scenes/notebooks/Notebook/notebookLogic.ts
@@ -168,7 +168,7 @@ export const notebookLogic = kea<notebookLogicType>([
}),
['setItemContext', 'maybeLoadComments', 'setSelectedComment', 'setCommentContexts'],
notebookCollabLogic({ shortId: props.shortId }),
- ['ackLocalSteps', 'applyRemoteSteps'],
+ ['ackLocalSteps', 'applyRemoteSteps', 'rebaseFailed'],
],
})),
actions({
@@ -225,6 +225,11 @@ export const notebookLogic = kea<notebookLogicType>([
openShareModal: true,
closeShareModal: true,
setAccessDeniedToNotebook: true,
+ showCollabConflict: (params: { serverContent: JSONContent; localContent: JSONContent; localText: string }) =>
+ params,
+ dismissCollabConflict: true,
+ discardLocalChanges: true,
+ copyUnsavedToNewNotebook: true,
}),
reducers(({ props }) => ({
isShareModalOpen: [
@@ -269,6 +274,17 @@ export const notebookLogic = kea<notebookLogicType>([
loadNotebookSuccess: () => false,
},
],
+ collabConflict: [
+ null as {
+ serverContent: JSONContent
+ localContent: JSONContent
+ localText: string
+ } | null,
+ {
+ showCollabConflict: (_, params) => params,
+ dismissCollabConflict: () => null,
+ },
+ ],
editingNodeIds: [
{} as Record<string, true>,
{
@@ -387,8 +403,13 @@ export const notebookLogic = kea<notebookLogicType>([
const notebook = await migrate(response, { skipApiUpgrade: !!values.isShared })
- if (notebook.content && (!values.notebook || values.notebook.version !== notebook.version)) {
- // If this is the first load we need to override the content fully
+ if (
+ !values.collabEnabled &&
+ notebook.content &&
+ (!values.notebook || values.notebook.version !== notebook.version)
+ ) {
+ // Push fresh server content into the editor on polling refresh (no-op on first load).
+ // Collab notebooks update via SSE, not setContent.
values.editor?.setContent(notebook.content)
}
@@ -400,6 +421,13 @@ export const notebookLogic = kea<notebookLogicType>([
return values.notebook
}
+ // While the stale-conflict modal is open, the user's local content has diverged
+ // from the server beyond what we can merge. Don't keep retrying saves until
+ // they choose to discard or force-save — otherwise we'd loop on 410s.
+ if (values.collabConflict) {
+ return values.notebook
+ }
+
if (values.collabEnabled && values.ttEditor) {
const sendable = sendableSteps(values.ttEditor.state)
if (!sendable) {
@@ -428,8 +456,8 @@ export const notebookLogic = kea<notebookLogicType>([
return response
} catch (error: any) {
if (error.status === 409 && error.data?.steps) {
- // Apply the missed range (deduped by version against SSE), then retry
- // PM-collab rebases our pending steps against the new state
+ // prosemirror-collab rebases our pending steps over the missed range.
+ // If receiveTransaction throws, `rebaseFailed` opens the conflict modal.
const steps = error.data.steps as Record<string, any>[]
const clientIds = error.data.client_ids as string[]
const serverVersion = error.data.version as number
@@ -441,6 +469,9 @@ export const notebookLogic = kea<notebookLogicType>([
version: firstMissedVersion + i,
}))
)
+ if (values.collabConflict) {
+ return values.notebook
+ }
actions.saveNotebook({
content: values.editor?.getJSON() ?? notebook.content,
title: notebook.title,
@@ -448,8 +479,11 @@ export const notebookLogic = kea<notebookLogicType>([
return values.notebook
}
if (error.status === 410) {
- actions.clearLocalContent()
- actions.loadNotebook()
+ // Stream trimmed
+ actions.rebaseFailed({
+ localContent: values.editor?.getJSON() ?? notebook.content ?? {},
+ localText: values.editor?.getText() ?? '',
+ })
return values.notebook
}
throw error
@@ -1054,6 +1088,51 @@ export const notebookLogic = kea<notebookLogicType>([
downloadFile(file)
},
+ discardLocalChanges: () => {
+ // Reload remounts the editor so it re-initialises with the server's content.
+ actions.clearLocalContent()
+ window.location.reload()
+ },
+
+ rebaseFailed: async ({ localContent, localText }) => {
+ // prosemirror-collab couldn't apply a remote step; the modal lets the user copy or discard.
+ if (!values.notebook) {
+ return
+ }
+ // Fetch fresh server content for the side-by-side preview of the changes.
+ let serverContent: JSONContent = {}
+ try {
+ const fresh = await api.notebooks.get(values.notebook.short_id, undefined, {})
+ serverContent = (fresh.content as JSONContent) ?? {}
+ } catch (e) {
+ posthog.captureException(e as Error, { action: 'notebook collab fetch server content' })
+ lemonToast.warning('Could not load the latest saved version.')
+ }
+ actions.showCollabConflict({ serverContent, localContent, localText })
+ },
+
+ copyUnsavedToNewNotebook: async () => {
+ // Save unsaved edits to a fresh notebook, then navigate to it.
+ if (!values.notebook || !values.collabConflict) {
+ return
+ }
+ try {
+ const sourceTitle = values.notebook.title || 'Untitled'
+ const newTitle = `${sourceTitle} (copy)`
+ const created = await api.notebooks.create({
+ content: updateContentHeading(values.collabConflict.localContent, newTitle),
+ text_content: values.collabConflict.localText,
+ title: newTitle,
+ })
+ lemonToast.success('Saved your unsaved changes to a new notebook.')
+ actions.dismissCollabConflict()
+ actions.clearLocalContent()
+ await openNotebook(created.short_id, NotebookTarget.Scene)
+ } catch {
+ lemonToast.error('Could not copy your changes to a new notebook.')
+ }
+ },
+
onEditorSelectionUpdate: () => {
if (!values.editor) {
return
diff --git a/products/notebooks/backend/api/notebook.py b/products/notebooks/backend/api/notebook.py
index 98026846b5cc..8ddb923b3f3a 100644
--- a/products/notebooks/backend/api/notebook.py
+++ b/products/notebooks/backend/api/notebook.py
@@ -809,10 +809,8 @@ class NotebookViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, ForbidD
)
if result.status == "stale":
- return Response(
- {"code": "conflict_stale", "detail": "Reload the notebook."},
- status=410,
- )
+ # Stream was trimmed (MAXLEN/TTL).
+ return Response({"code": "conflict_stale"}, status=410)
# Carries the missed steps so the client can reconcile without depending on SSE
assert result.steps_since is not None # status == "conflict" guarantees this
diff --git a/products/notebooks/backend/test/test_collab_api.py b/products/notebooks/backend/test/test_collab_api.py
index 9d124f3a811a..3308ea2b0a66 100644
--- a/products/notebooks/backend/test/test_collab_api.py
+++ b/products/notebooks/backend/test/test_collab_api.py
@@ -164,7 +164,7 @@ class TestNotebookCollabSaveAPI(APIBaseTest):
response = self._collab_save(
notebook,
- version=0,
+ version=notebook["version"],
steps=[{"stepType": "replace", "from": 0, "to": 0}],
)
assert response.status_code == status.HTTP_410_GONE