: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(monaco): replace body:has() find widget anchor with body marker class (#69736)
Georgiy Tarasov280e3885ff76
diff --git a/frontend/src/lib/monaco/CodeEditorImpl.scss b/frontend/src/lib/monaco/CodeEditorImpl.scssindex da6708dc9410..772b1c4752e7 100644--- a/frontend/src/lib/monaco/CodeEditorImpl.scss+++ b/frontend/src/lib/monaco/CodeEditorImpl.scss@@ -20,7 +20,10 @@// to overlap the button. Force a single-row layout so the tooltip stays// short and clear of the button. Scoped to when the find widget is open so// tooltips on other action bars are unaffected.-body:has(.monaco-editor .find-widget.visible) .workbench-hover-container {+// `.has-monaco-find-widget-open` is toggled on <body> by findWidgetBodyClass.ts and stands in+// for `body:has(.monaco-editor .find-widget.visible)`. Do not reintroduce near-root `:has()`+// anchors: they make any class change anywhere cost a full-document style recalc.+body.has-monaco-find-widget-open .workbench-hover-container {pointer-events: none !important;&,diff --git a/frontend/src/lib/monaco/CodeEditorImpl.tsx b/frontend/src/lib/monaco/CodeEditorImpl.tsxindex 8c79fcc7fbb3..7b7343f94b11 100644--- a/frontend/src/lib/monaco/CodeEditorImpl.tsx+++ b/frontend/src/lib/monaco/CodeEditorImpl.tsx@@ -13,6 +13,7 @@ import { Spinner } from 'lib/lemon-ui/Spinner'import { codeEditorLogic } from 'lib/monaco/codeEditorLogic'import { codeEditorLogicType } from 'lib/monaco/codeEditorLogicType'import { findNextFocusableElement, findPreviousFocusableElement } from 'lib/monaco/domUtils'+import { trackFindWidgetVisibility } from 'lib/monaco/findWidgetBodyClass'import { initCodeownersLanguage } from 'lib/monaco/languages/codeowners'import { initHogLanguage } from 'lib/monaco/languages/hog'import { initHogJsonLanguage } from 'lib/monaco/languages/hogJson'@@ -416,6 +417,7 @@ export function CodeEditor({setMonacoAndEditor([monaco, editor])initEditor(monaco, editor, editorProps, options ?? {}, builtCodeEditorLogic)remeasureFontsWhenReady(monaco)+ monacoDisposables.current.push(trackFindWidgetVisibility(editor))// Override Monaco's suggestion widget styling to prevent truncationconst styleId = 'monaco-suggestion-widget-fix'@@ -525,6 +527,8 @@ export function CodeEditor({editorRef.current = modifiedEditordiffEditorRef.current = difftrackEditorModels(modifiedEditor, monaco)+ monacoDisposables.current.push(trackFindWidgetVisibility(modifiedEditor))+ monacoDisposables.current.push(trackFindWidgetVisibility(diff.getOriginalEditor()))const original = diff.getOriginalEditor().getModel()if (original) {editorModelsRef.current.add(original)diff --git a/frontend/src/lib/monaco/findWidgetBodyClass.ts b/frontend/src/lib/monaco/findWidgetBodyClass.tsnew file mode 100644index 000000000000..3d4ace4a4cc0--- /dev/null+++ b/frontend/src/lib/monaco/findWidgetBodyClass.ts@@ -0,0 +1,50 @@+import { IDisposable, editor as importedEditor } from 'monaco-editor'++// Mirrors the find widget's visibility onto <body> so CodeEditorImpl.scss can style Monaco's+// body-level hover tooltips without a `body:has()` anchor. Near-root `:has()` selectors make+// Blink flag the whole document as :has-invalidation-suspect at load, after which any class+// change anywhere costs a full-document style recalc (see the same pattern in Notebook.scss).+const FIND_WIDGET_OPEN_BODY_CLASS = 'has-monaco-find-widget-open'++// Counts editors with an open find widget, so the body class survives multiple editors+let openFindWidgetCount = 0++interface FindReplaceStateLike {+ readonly isRevealed: boolean+ onFindReplaceStateChange(listener: (event: { isRevealed: boolean }) => void): IDisposable+}++interface FindControllerLike extends importedEditor.IEditorContribution {+ getState(): FindReplaceStateLike+}++export function trackFindWidgetVisibility(codeEditor: importedEditor.IStandaloneCodeEditor): IDisposable {+ const findController = codeEditor.getContribution<FindControllerLike>('editor.contrib.findController')+ const state = typeof findController?.getState === 'function' ? findController.getState() : null+ if (!state || typeof state.onFindReplaceStateChange !== 'function') {+ // Internal contribution shape changed: degrade to the tooltip flicker workaround not applying+ return { dispose: () => {} }+ }+ let revealed = false+ const setRevealed = (nextRevealed: boolean): void => {+ if (nextRevealed === revealed) {+ return+ }+ revealed = nextRevealed+ openFindWidgetCount += revealed ? 1 : -1+ document.body.classList.toggle(FIND_WIDGET_OPEN_BODY_CLASS, openFindWidgetCount > 0)+ }+ setRevealed(state.isRevealed)+ const listener = state.onFindReplaceStateChange((event) => {+ // The event carries change flags per field, the current value lives on the state+ if (event.isRevealed) {+ setRevealed(state.isRevealed)+ }+ })+ return {+ dispose: () => {+ listener.dispose()+ setRevealed(false)+ },+ }+}