Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix(web): clear the two React rule violations the whisper page landed with

Bingxi Zhao (Frank)a428264c442f
diff --git a/web/app/(workspace)/whisper/page.tsx b/web/app/(workspace)/whisper/page.tsx
index a59a73e59..7e4e0e965 100644
--- a/web/app/(workspace)/whisper/page.tsx
+++ b/web/app/(workspace)/whisper/page.tsx
@@ -139,7 +139,9 @@ export default function WhisperPage() {
setConnected(false);
});
clientRef.current = client;
- setConnected(false);
+ // No reset needed here: `connected` starts false and the client's onClose
+ // above owns clearing it. Setting it synchronously in the effect only
+ // cascaded a render.
client.connect();
// Poll readyState until open (UnifiedWSClient has no onOpen hook).
diff --git a/web/components/whisper/WhisperMessageList.tsx b/web/components/whisper/WhisperMessageList.tsx
index f670576fc..7e74bf294 100644
--- a/web/components/whisper/WhisperMessageList.tsx
+++ b/web/components/whisper/WhisperMessageList.tsx
@@ -30,7 +30,9 @@ function showSource(source?: string): boolean {
return source !== "whisper_visitor" && source !== "whisper_trainee";
}
-function useMarkdown(msg: WhisperMessage): boolean {
+// A plain predicate, not a React hook. Under a `use` prefix it read as one, and
+// calling it inside the map below tripped react-hooks/rules-of-hooks.
+function rendersMarkdown(msg: WhisperMessage): boolean {
return msg.role !== "user" && msg.role !== "system";
}
@@ -85,7 +87,7 @@ export default function WhisperMessageList({
>
<div
className={`max-w-[85%] rounded-2xl px-3.5 py-2.5 text-sm leading-6 ${bubbleClass(msg)} ${
- useMarkdown(msg) ? "" : "whitespace-pre-wrap"
+ rendersMarkdown(msg) ? "" : "whitespace-pre-wrap"
}`}
>
{showMeta && (
@@ -101,7 +103,7 @@ export default function WhisperMessageList({
{msg.localSeat && <span>· you ({msg.localSeat})</span>}
</div>
)}
- {useMarkdown(msg) ? (
+ {rendersMarkdown(msg) ? (
<MarkdownRenderer
content={msg.text}
variant="compact"