: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(notebooks): replace near-root :has() anchors with body marker class (#69733)
Georgiy Tarasov8d115300eec8
diff --git a/frontend/src/scenes/notebooks/Notebook/Notebook.scss b/frontend/src/scenes/notebooks/Notebook/Notebook.scssindex 7c25dd3970e9..5ee23b2648b4 100644--- a/frontend/src/scenes/notebooks/Notebook/Notebook.scss+++ b/frontend/src/scenes/notebooks/Notebook/Notebook.scss@@ -652,18 +652,22 @@margin: 0 auto;}-body:has(.Notebook--markdown-v2),-.Navigation3000:has(.Notebook--markdown-v2),-.main-content-container:has(.Notebook--markdown-v2) > main {+// `.has-markdown-v2-notebook` is toggled on <body> by Notebook.tsx and stands in for+// `body:has(.Notebook--markdown-v2)`. Do not reintroduce near-root `:has()` anchors here:+// they make Blink flag the whole document as :has-invalidation-suspect, after which any+// class change anywhere costs a full-page style recalc (200ms+ per keystroke on large threads).+body.has-markdown-v2-notebook,+body.has-markdown-v2-notebook .Navigation3000,+body.has-markdown-v2-notebook .main-content-container > main {--notebook-markdown-v2-page-background: var(--color-bg-primary);--scene-layout-background: var(--notebook-markdown-v2-page-background);background: var(--notebook-markdown-v2-page-background);}-[theme='dark']:has(.Notebook--markdown-v2),-[theme='dark'] .Navigation3000:has(.Notebook--markdown-v2),-[theme='dark'] .main-content-container:has(.Notebook--markdown-v2) > main {+body[theme='dark'].has-markdown-v2-notebook,+body[theme='dark'].has-markdown-v2-notebook .Navigation3000,+body[theme='dark'].has-markdown-v2-notebook .main-content-container > main {--notebook-markdown-v2-page-background: var(--color-bg-surface-primary);}diff --git a/frontend/src/scenes/notebooks/Notebook/Notebook.tsx b/frontend/src/scenes/notebooks/Notebook/Notebook.tsxindex 0be51dc285b5..600c13894039 100644--- a/frontend/src/scenes/notebooks/Notebook/Notebook.tsx+++ b/frontend/src/scenes/notebooks/Notebook/Notebook.tsx@@ -2,7 +2,7 @@ import './Notebook.scss'import clsx from 'clsx'import { BindLogic, useActions, useValues } from 'kea'-import { useEffect } from 'react'+import { useEffect, useLayoutEffect } from 'react'import { commandLogic } from 'lib/components/Command/commandLogic'import { NotFound } from 'lib/components/NotFound'@@ -33,6 +33,10 @@ import { NotebookMergeConflictDetails } from './NotebookMergeConflictDetails'import { notebookSettingsLogic } from './notebookSettingsLogic'import { openUpgradeToMarkdownNotebookDialog } from './notebookUpgradeDialog'+// Counts mounted markdown-v2 notebooks so the <body> marker class survives overlapping mounts+// (e.g. one in the scene and one in the side panel)+let markdownNotebookMountCount = 0+export type NotebookProps = NotebookLogicProps & {initialAutofocus?: EditorFocusPositioninitialContent?: JSONContent@@ -116,6 +120,22 @@ export function Notebook({}, [size]) // oxlint-disable-line exhaustive-depsconst isMarkdownNotebook = isMarkdownNotebookContent(content)++ // Marker class replacing `body:has(.Notebook--markdown-v2)` in Notebook.scss: a near-root+ // `:has()` anchor makes every DOM class change cost a whole-document style recalc in Blink+ useLayoutEffect(() => {+ if (!isMarkdownNotebook) {+ return+ }+ if (++markdownNotebookMountCount === 1) {+ document.body.classList.add('has-markdown-v2-notebook')+ }+ return () => {+ if (--markdownNotebookMountCount === 0) {+ document.body.classList.remove('has-markdown-v2-notebook')+ }+ }+ }, [isMarkdownNotebook])const isContentWidthExpanded = isMarkdownNotebook ? isMarkdownExpanded : isExpandedconst canUpgradeToMarkdownNotebooks = !!featureFlags[FEATURE_FLAGS.MARKDOWN_NOTEBOOKS]const upgradeToMarkdownNotebook = (): void => {