Fix TDZ crash: move useEffect hooks to after runLint declaration

useEffect(() => {...}, [runLint]) evaluated [runLint] immediately,
but runLint was declared with const on the next line — temporal dead
zone. Moved both effects to after the useCallback closes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
chris 2026-05-24 21:52:39 -04:00
parent 91071270a4
commit e5b9f643e1

View File

@ -153,11 +153,6 @@ const Editor = forwardRef(function Editor(
}, [editor, content]) }, [editor, content])
// Lint check // Lint check
// Keep ref in sync so the onUpdate closure (which never re-captures) always
// calls the latest version of runLint.
useEffect(() => { runLintRef.current = runLint }, [runLint])
useEffect(() => () => clearTimeout(lintDebounce.current), [])
const runLint = useCallback(async () => { const runLint = useCallback(async () => {
if (!editor || lintStatusRef.current === 'checking') return if (!editor || lintStatusRef.current === 'checking') return
lintStatusRef.current = 'checking' lintStatusRef.current = 'checking'
@ -208,6 +203,11 @@ const Editor = forwardRef(function Editor(
} }
}, [editor]) }, [editor])
// Keep ref in sync so the stale onUpdate closure always calls the latest runLint
useEffect(() => { runLintRef.current = runLint }, [runLint])
// Clean up the debounce timer on unmount
useEffect(() => () => clearTimeout(lintDebounce.current), [])
// Popover on clicking a lint mark // Popover on clicking a lint mark
function handleEditorClick(e) { function handleEditorClick(e) {
if (!editor) return if (!editor) return