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): cap the height of Python cells (#81120)

Sinan Kucukkoseler71131aa6ed9a
diff --git a/frontend/src/lib/monaco/CodeEditorResizable.tsx b/frontend/src/lib/monaco/CodeEditorResizable.tsx
index c6cee235222d..89dacd7c28f8 100644
--- a/frontend/src/lib/monaco/CodeEditorResizable.tsx
+++ b/frontend/src/lib/monaco/CodeEditorResizable.tsx
@@ -53,7 +53,9 @@ export function CodeEditorResizeable({
// eslint-disable-next-line react/forbid-dom-props
style={{
minHeight,
- maxHeight,
+ // `maxHeight` caps how tall the editor grows on its own. A drag is a deliberate
+ // choice, so it overrides the cap instead of being clamped by it.
+ maxHeight: manualHeight ?? maxHeight,
height: manualHeight ?? height,
}}
>
diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx
index 3b8b87bd2189..c52013b66527 100644
--- a/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx
+++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodePythonV2.tsx
@@ -34,6 +34,12 @@ export type NotebookNodePythonV2Attributes = {
runStatus?: NotebookNodeRunTerminalStatus | null
}
+const PYTHON_EDITOR_MIN_HEIGHT = 160
+// About 20 lines at Monaco's 18px line height. An MCP-written cell is often far longer than that,
+// and an editor that grows with the code pushes the output and the next cell off the screen.
+// Past the cap the editor scrolls, and the drag handle expands it.
+const PYTHON_EDITOR_MAX_HEIGHT = 360
+
const toDataframeResult = (result: NotebookNodeSQLV2Result): NotebookDataframeResult => {
const columns = result.columns ?? []
const firstPage = result.first_page ?? []
@@ -288,14 +294,20 @@ const Settings = ({
{isRunning ? 'Cancel' : 'Run'}
</LemonButton>
</div>
- <div className="min-h-0 flex-1">
+ <div
+ className="min-h-0 flex-1"
+ // The editor owns pointer drags in here. Without this the resize handle drags the
+ // node around the markdown notebook instead of resizing the editor.
+ onMouseDown={(event) => event.stopPropagation()}
+ onDragStart={(event) => event.stopPropagation()}
+ >
<CodeEditorResizeable
language="python"
value={typeof attributes.code === 'string' ? attributes.code : ''}
onChange={(value) => updateAttributes({ code: value ?? '' })}
onPressCmdEnter={() => runRef.current()}
- allowManualResize={false}
- minHeight={160}
+ minHeight={PYTHON_EDITOR_MIN_HEIGHT}
+ maxHeight={PYTHON_EDITOR_MAX_HEIGHT}
embedded
/>
</div>