From 28a28d1cb6505542f2745613c0e4fd770941860d Mon Sep 17 00:00:00 2001 From: dotta Date: Wed, 8 Apr 2026 07:44:43 -0500 Subject: [PATCH] fix(ui): eliminate flash when auto-folding work sections on page load Replace useEffect with synchronous state derivation during render so the browser never paints the unfolded intermediate state. This prevents the visible "jump" when loading an issue page with already-completed work sections like "worked for 4 minutes". Co-Authored-By: Paperclip --- ui/src/components/IssueChatThread.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ui/src/components/IssueChatThread.tsx b/ui/src/components/IssueChatThread.tsx index ed409314..1372fa1c 100644 --- a/ui/src/components/IssueChatThread.tsx +++ b/ui/src/components/IssueChatThread.tsx @@ -820,23 +820,24 @@ function IssueChatAssistantMessage() { const hasCoT = message.content.some((p) => p.type === "reasoning" || p.type === "tool-call"); const isFoldable = !isRunning && hasCoT && !!chainOfThoughtLabel; const [folded, setFolded] = useState(isFoldable); - const previousMessageIdRef = useRef(message.id); - const previousIsFoldableRef = useRef(isFoldable); + const [prevFoldKey, setPrevFoldKey] = useState({ messageId: message.id, isFoldable }); - useEffect(() => { + // Derive fold state synchronously during render (not in useEffect) so the + // browser never paints the un-folded intermediate state — prevents the + // visible "jump" when loading a page with already-folded work sections. + if (message.id !== prevFoldKey.messageId || isFoldable !== prevFoldKey.isFoldable) { const nextFolded = resolveAssistantMessageFoldedState({ messageId: message.id, currentFolded: folded, isFoldable, - previousMessageId: previousMessageIdRef.current, - previousIsFoldable: previousIsFoldableRef.current, + previousMessageId: prevFoldKey.messageId, + previousIsFoldable: prevFoldKey.isFoldable, }); - previousMessageIdRef.current = message.id; - previousIsFoldableRef.current = isFoldable; + setPrevFoldKey({ messageId: message.id, isFoldable }); if (nextFolded !== folded) { setFolded(nextFolded); } - }, [folded, isFoldable, message.id]); + } const handleVote = async ( vote: FeedbackVoteValue,