: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(diff-editor): release monaco diff editor models before disposal (#58693)
posthog[bot]77194bec49d7
diff --git a/frontend/src/lib/components/MonacoDiffEditor.tsx b/frontend/src/lib/components/MonacoDiffEditor.tsxindex ab955b4dcfc9..a560b1650f07 100644--- a/frontend/src/lib/components/MonacoDiffEditor.tsx+++ b/frontend/src/lib/components/MonacoDiffEditor.tsx@@ -109,24 +109,27 @@ function MonacoDiffEditor(})// Get initial content height- setTimeout(() => {+ const initialHeightTimer = setTimeout(() => {if (editorRef.current) {const modEditor = editorRef.current.getModifiedEditor()setContentHeight(modEditor.getContentHeight())}}, 100)- // Cleanup+ // Cleanup — order matters: detach the models from the DiffEditorWidget via setModel(null)+ // before disposing anything, so Monaco's internal onWillDispose listeners don't fire+ // against models that are about to be torn down ("TextModel got disposed before+ // DiffEditorWidget model got reset").return () => {- const model = editorRef.current?.getModel()- if (editorRef.current && model) {- const { original: originalEditor, modified } = model- editorRef.current.dispose()- originalEditor.dispose()- modified.dispose()- }+ clearTimeout(initialHeightTimer)subscriptionRef.current?.dispose()- contentSizeListener?.dispose()+ contentSizeListener.dispose()+ editorRef.current?.setModel(null)+ editorRef.current?.dispose()+ originalModel.dispose()+ modifiedModel.dispose()+ editorRef.current = null+ subscriptionRef.current = null}})