Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 10 additions & 2 deletions apps/quill/client/components/playground-view.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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),
Comment on lines +262 to +264

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Hide stale rubric scores during streaming

When a user runs the playground again after a previous result, useDeferredValue can keep returning the prior output while visibleOutput is already streaming the new response. The render guard for <RubricSnapshot> still uses visibleOutput.length > 0, so the UI can display scores/details computed from the previous answer under the new streaming text until the deferred update catches up, which is especially likely when these expensive renders are being interrupted. Consider gating the snapshot on the deferred text being current, or clearing/hiding the rubric while the deferred value is stale.

Useful? React with 👍 / 👎.

[deferredVisibleOutput]
);
Comment on lines +258 to +266
const { score, details } = useMemo(
() =>
guide
Expand Down
Loading