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): hide synthetic empty title row in read-only notebooks (#70420)

Thomas Obermüller71d2672fc0a7
diff --git a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts
index 99d1f9dd8bcc..a8db7f51526f 100644
--- a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts
+++ b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts
@@ -2493,6 +2493,18 @@ Intro paragraph
expect(container.querySelectorAll('[data-placeholder="Start writing..."]')).toHaveLength(0)
})
+ it('hides the synthetic empty title row in view mode', () => {
+ const { container } = render(
+ createElement(MarkdownNotebook, {
+ value: '<Query query={{"kind":"DataTableNode"}} />',
+ mode: 'view',
+ })
+ )
+
+ expect(container.querySelectorAll('[data-placeholder="Untitled notebook"]')).toHaveLength(0)
+ expect(container.querySelectorAll('.MarkdownNotebook__text-block--title')).toHaveLength(0)
+ })
+
it('records keystrokes, mouse events, and commits into a downloadable debug log', async () => {
const { createObjectURL, anchorClick, restore } = stubNotebookLogDownload()
diff --git a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.tsx b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.tsx
index 43f1f06e0d95..016700dff0e5 100644
--- a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.tsx
+++ b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.tsx
@@ -76,6 +76,7 @@ import {
setsEqual,
textBlocksShareContinuationStyle,
updateNotebookCodeBlockText,
+ withoutLeadingEmptyTitleGroup,
writeSystemClipboardText,
} from './documentModel'
import {
@@ -5598,10 +5599,11 @@ function MarkdownNotebookEditor({
canvasRef.current?.focus()
}
- const renderedNodeGroups = getMarkdownNotebookVisualGroups(
+ const allNodeGroups = getMarkdownNotebookVisualGroups(
renderedNodes,
insertMenu?.detached ? insertMenu.nodeId : undefined
)
+ const renderedNodeGroups = mode === 'edit' ? allNodeGroups : withoutLeadingEmptyTitleGroup(allNodeGroups)
// The insert menu never takes focus (typing keeps filtering), so the canvas points at the
// selected option via aria-activedescendant.
diff --git a/frontend/src/lib/components/MarkdownNotebook/documentModel.ts b/frontend/src/lib/components/MarkdownNotebook/documentModel.ts
index fb237c4ae392..fa07a2cdd1d7 100644
--- a/frontend/src/lib/components/MarkdownNotebook/documentModel.ts
+++ b/frontend/src/lib/components/MarkdownNotebook/documentModel.ts
@@ -115,6 +115,22 @@ export function getMarkdownNotebookVisualGroups(
return groups
}
+// ensureEditableNotebookDocument prepends an empty `# ` title row so editors always have a
+// title to type into. Viewers can't type, so in view mode that synthetic row would render as
+// a bare "Untitled notebook" placeholder card (e.g. profile canvases whose content starts
+// with a component) — drop it from the rendered groups instead.
+export function withoutLeadingEmptyTitleGroup(groups: MarkdownNotebookVisualGroup[]): MarkdownNotebookVisualGroup[] {
+ const firstGroup = groups[0]
+ if (!firstGroup || firstGroup.type !== 'text') {
+ return groups
+ }
+ const [firstItem, ...restItems] = firstGroup.items
+ if (!firstItem || firstItem.index !== 0 || !isTextBlockNode(firstItem.node) || nodeHasContent(firstItem.node)) {
+ return groups
+ }
+ return restItems.length ? [{ ...firstGroup, items: restItems }, ...groups.slice(1)] : groups.slice(1)
+}
+
export function isTextBlockNode(node: NotebookBlockNode): node is NotebookTextBlockNode {
return node.type === 'paragraph' || node.type === 'heading' || node.type === 'blockquote'
}