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): render the composer on a fresh comment thread (#83540)

posthog[bot]b1cf426d4a0a
diff --git a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts
index 81ea1581d610..edf481809966 100644
--- a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts
+++ b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts
@@ -4561,6 +4561,56 @@ Body text`)
<Query query={{"kind":"DataTableNode"}} />`)
})
+ it('opens a selection-anchored thread with its composer in the edit panel', () => {
+ const { container } = render(
+ createElement(MarkdownNotebook, {
+ value: withNotebookTitle('Numbers look off here'),
+ registry: createDiscussionCommentTestRegistry(),
+ })
+ )
+ const paragraph = getBodyTextBlock(container)
+
+ selectTextAcrossNodes(getFirstTextNode(paragraph), 8, getFirstTextNode(paragraph), 'Numbers look'.length, true)
+ fireEvent.click(container.querySelector('button[aria-label="Comment on selection"]') as HTMLButtonElement)
+
+ // Insertion opens the panel through the transient cache, so the composer lands in the edit
+ // panel (ready to type) rather than the read-only view panel — and no prop is persisted.
+ expect(
+ container.querySelector(
+ '.MarkdownNotebook__component-panel--filters [data-attr="notebook-discussion-comment-input"]'
+ )
+ ).not.toBeNull()
+ expect(
+ container.querySelector(
+ '.MarkdownNotebook__component-panel--results [data-attr="notebook-discussion-comment-input"]'
+ )
+ ).toBeNull()
+ })
+
+ it('opens a gutter-inserted thread with its composer in the edit panel', () => {
+ const { container } = render(
+ createElement(MarkdownNotebook, {
+ value: withNotebookTitle('<Query query={{"kind":"DataTableNode"}} />'),
+ registry: createDiscussionCommentTestRegistry(),
+ })
+ )
+
+ fireEvent.click(
+ container.querySelector('[data-attr="markdown-notebook-block-comment-button"]') as HTMLButtonElement
+ )
+
+ expect(
+ container.querySelector(
+ '.MarkdownNotebook__component-panel--filters [data-attr="notebook-discussion-comment-input"]'
+ )
+ ).not.toBeNull()
+ expect(
+ container.querySelector(
+ '.MarkdownNotebook__component-panel--results [data-attr="notebook-discussion-comment-input"]'
+ )
+ ).toBeNull()
+ })
+
it('reuses an existing block comment thread above a component from the gutter button', async () => {
const onChange = jest.fn()
const { container } = render(
diff --git a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.tsx b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.tsx
index 4e4556bfacda..08980ab9337f 100644
--- a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.tsx
+++ b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.tsx
@@ -3947,6 +3947,9 @@ function MarkdownNotebookEditor({
})
markNotebookNodeFreshlyInserted(commentNode.id)
+ // Open the composer through the transient panel cache instead of a persisted prop, so the
+ // open state stays local to this session and never leaks into the shared document markdown.
+ setLocalComponentPanels(commentNode.id, { filters: true, results: true })
floatingToolbarPositionLockRef.current = null
setFloatingToolbar(null)
window.getSelection()?.removeAllRanges()
@@ -4061,6 +4064,9 @@ function MarkdownNotebookEditor({
props: { replies: [] },
}
markNotebookNodeFreshlyInserted(commentNode.id)
+ // Open the composer through the transient panel cache instead of a persisted prop, so the
+ // open state stays local to this session and never leaks into the shared document markdown.
+ setLocalComponentPanels(commentNode.id, { filters: true, results: true })
commitDocument({
...currentDocument,
nodes: [...nodes.slice(0, insertIndex), commentNode, ...nodes.slice(insertIndex)],
diff --git a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx
index 0557312dfaf5..c8366575bc0b 100644
--- a/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx
+++ b/frontend/src/scenes/notebooks/Notebook/markdownNotebookRegistry.test.tsx
@@ -6,7 +6,11 @@ import {
mergeMarkdownNotebookRegistries,
omitInsertCommands,
} from 'lib/components/MarkdownNotebook'
-import { getInsertedComponentPanelVisibility } from 'lib/components/MarkdownNotebook/componentPanels'
+import {
+ type ComponentPanelVisibility,
+ getInsertedComponentPanelVisibility,
+} from 'lib/components/MarkdownNotebook/componentPanels'
+import { NotebookComponentShell } from 'lib/components/MarkdownNotebook/NotebookComponentShell'
import type { NotebookComponentBlockNode } from 'lib/components/MarkdownNotebook/types'
import { FEATURE_FLAGS } from 'lib/constants'
import { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'
@@ -109,6 +113,50 @@ describe('markdownNotebookRegistry', () => {
})
})
+ describe('discussion comment composer', () => {
+ const renderCommentShell = (componentPanels: ComponentPanelVisibility): ReturnType<typeof render> => {
+ // No `showFilters` in props: composer visibility is driven by the transient panel
+ // state, so the open state never has to be written into the shared document markdown.
+ const node: NotebookComponentBlockNode = {
+ id: 'comment-node',
+ type: 'component',
+ tagName: 'Comment',
+ props: { replies: [] },
+ }
+ return render(
+ <NotebookComponentShell
+ node={node}
+ mode="edit"
+ componentPanels={componentPanels}
+ persistComponentPanelVisibility={false}
+ isSelected={false}
+ registry={NOTEBOOK_MARKDOWN_REGISTRY}
+ toggleComponentPanel={jest.fn()}
+ setLocalComponentPanels={jest.fn()}
+ rememberComponentPanels={jest.fn()}
+ setBlockRef={jest.fn()}
+ updateNode={jest.fn()}
+ deleteNode={jest.fn()}
+ deleteSelectedNotebookBlocks={jest.fn(() => false)}
+ insertParagraphAfterNode={jest.fn()}
+ moveFocusToAdjacentNode={jest.fn(() => false)}
+ />
+ )
+ }
+
+ // The edit panel is what makes the composer editable, so a thread renders its composer
+ // when that panel is open and the read-only view branch (no composer) when it is closed.
+ // Insertion opens the panel transiently, so the composer never depends on a persisted prop.
+ it.each([
+ ['renders the composer when the edit panel is open', { filters: true, results: true }, true],
+ ['renders no composer when the edit panel is closed', { filters: false, results: true }, false],
+ ])('%s', (_label, componentPanels, expectComposer) => {
+ const { container } = renderCommentShell(componentPanels)
+ const composer = container.querySelector('[data-attr="notebook-discussion-comment-input"]')
+ expect(composer !== null).toBe(expectComposer)
+ })
+ })
+
describe('insert menu SQL commands', () => {
// Exactly one SQL entry either way, and it stays in the menu's top group across the
// flag flip so SQL doesn't move on people when the revamped cell takes over.