diff --git a/src/renderer/src/components/editor/useEditorPanelContentState.ts b/src/renderer/src/components/editor/useEditorPanelContentState.ts index 7d76617b708..14a4375d196 100644 --- a/src/renderer/src/components/editor/useEditorPanelContentState.ts +++ b/src/renderer/src/components/editor/useEditorPanelContentState.ts @@ -1,7 +1,7 @@ /* oxlint-disable max-lines -- Why: content loading, retry, and external-change subscriptions share in-flight caches and state setters; splitting them would make the hook coordination harder to audit. */ -import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react' import type { OpenFile } from '@/store/slices/editor' import { getConnectionIdForFile, isWorktreeConnectionResolved } from '@/lib/connection-context' import { joinPath } from '@/lib/path' @@ -133,7 +133,7 @@ export function useEditorPanelContentState({ const activeContentFileId = selectedConflictReviewFile?.id ?? activeFile?.id ?? null const activeContentFileIdRef = useRef(activeContentFileId) - useEffect(() => { + useLayoutEffect(() => { // Why: event-driven readers must only observe state from committed renders. diffContentsRef.current = diffContents openFilesRef.current = openFiles diff --git a/src/renderer/src/components/editor/useEditorPanelExternalContentEvents.test.tsx b/src/renderer/src/components/editor/useEditorPanelExternalContentEvents.test.tsx index a7d9db6b968..12f5471e54c 100644 --- a/src/renderer/src/components/editor/useEditorPanelExternalContentEvents.test.tsx +++ b/src/renderer/src/components/editor/useEditorPanelExternalContentEvents.test.tsx @@ -1,6 +1,6 @@ // @vitest-environment happy-dom -import { act, useEffect, useRef, useState } from 'react' +import { act, useLayoutEffect, useRef, useState } from 'react' import { createRoot, type Root } from 'react-dom/client' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { OpenFile } from '@/store/slices/editor' @@ -30,7 +30,7 @@ function ExternalContentProbe({ activeFileId, calls, isVisible, openFiles }: Pro const [, setFileContents] = useState>({}) const [, setDiffContents] = useState>({}) - useEffect(() => { + useLayoutEffect(() => { activeContentFileIdRef.current = activeFileId isVisibleRef.current = isVisible openFilesRef.current = openFiles