Merge pull request #35579 from overleaf/mj-theme-race

[web] Avoid race condition in theme selection

GitOrigin-RevId: 2252e316d267ddd1e9c5f8e09a1c0a2c4e35b706
This commit is contained in:
Mathias Jakobsen
2026-09-17 11:31:30 +00:00
committed by Copybot
parent 4f9ada1ecb
commit bbe1c2126a
@@ -150,10 +150,20 @@ function useCodeMirrorScope(view: EditorView) {
activeOverallTheme,
})
)
// The editor theme is loaded asynchronously, so if we have another update
// fire before it finishes loading, there's a race of which one to apply.
// For example the print dialog will quickly change the theme to light,
// then back to dark which can result in the late-resolving light theme to
// be applied regardless of current active overall theme.
let stale = false
setEditorTheme(editorTheme).then(spec => {
view.dispatch(spec)
if (!stale) {
view.dispatch(spec)
}
})
return () => {
stale = true
}
}, [view, fontFamily, fontSize, lineHeight, activeOverallTheme, editorTheme])
const settingsRef = useRef({