diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..117e794 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-06-01 - Prevent main thread blocking during fake text streaming +**Learning:** During rapid state updates like fake text streaming (e.g. interval ~24ms), passing the rapidly changing state directly to expensive synchronous evaluation functions (like deterministic scoring/analyzing) causes severe main thread blocking and unresponsiveness. +**Action:** Use React's `useDeferredValue` to wrap the rapidly updating stream state before passing it to expensive synchronous functions. This allows React to prioritize UI updates and interrupt the expensive rendering. diff --git a/apps/quill/client/components/playground-view.tsx b/apps/quill/client/components/playground-view.tsx index 511226b..65abeda 100644 --- a/apps/quill/client/components/playground-view.tsx +++ b/apps/quill/client/components/playground-view.tsx @@ -1,6 +1,6 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { AnimatePresence, motion } from "framer-motion"; -import { useEffect, useMemo, useRef, useState } from "react"; +import { useDeferredValue, useEffect, useMemo, useRef, useState } from "react"; import { USE_CASE_PRESETS } from "../../src/lib/presets"; import { analyzeText, scoreDeterministic } from "../../src/lib/rubric"; import type { Guide, UseCase } from "../../src/lib/types"; @@ -255,7 +255,15 @@ export function PlaygroundView({ }; }, [output]); - const snapshot = useMemo(() => analyzeText(visibleOutput), [visibleOutput]); + // ⚡ Bolt: Wrap visibleOutput with useDeferredValue before passing it to the expensive + // synchronous analyzeText computation. This prevents the main thread from blocking + // during the rapid character-by-character fake streaming (~24ms intervals), keeping + // the UI responsive. + const deferredVisibleOutput = useDeferredValue(visibleOutput); + const snapshot = useMemo( + () => analyzeText(deferredVisibleOutput), + [deferredVisibleOutput] + ); const { score, details } = useMemo( () => guide