@devries-cameron20 / t3code-1 / commits / 8eddd16067
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

refactor(web): find reveal refs stay cached without "use memo" (#20818)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 17, 2026 at 00:34 UTC 8eddd16067aabcc1d7f09b05d28814132bd27162
4 files changed +13 -14
apps/web/src/components/ChatMarkdown.tsx
+4 -4
@@ -1,4 +1,4 @@
1 -import { MarkdownFindContext, useFindRevealRef } from "./chat/markdownFindContext";
1 +import { MarkdownFindContext, findRevealRef } from "./chat/markdownFindContext";
2 import {
3 buildFileLinkParentSuffixByPath,
4 fileLinkLabel,
@@ -668,7 +668,7 @@ function MarkdownDetails({
668 const revealForFind = () => setIsOpen(true);
669 // Base UI only listens for `beforematch` on a panel mounted at its first
670 // render; a closed panel mounts later, when find starts, so listen here.
671 - const findRevealRef = useFindRevealRef(revealForFind);
671 + const revealRef = findRevealRef(revealForFind);
672 const childNodes = Children.toArray(children);
673 const summaryIndex = childNodes.findIndex(
674 (child) => isValidElement(child) && child.type === "summary",
@@ -698,7 +698,7 @@ function MarkdownDetails({
698 />
699 <span>{summary}</span>
700 </CollapsibleTrigger>
701 - <CollapsiblePanel ref={findRevealRef} hiddenUntilFound={searching}>
701 + <CollapsiblePanel ref={revealRef} hiddenUntilFound={searching}>
702 <div
703 className="pb-3 ps-6 text-foreground/[calc(80%+var(--appearance-contrast-boost)/5)]"
704 data-markdown-details-content=""
@@ -984,7 +984,7 @@ function MarkdownMermaidCodeBlock({
984 const [showCode, setShowCode] = useState(false);
985 const searching = use(MarkdownFindContext);
986 const revealSource = () => setShowCode(true);
987 - const sourceRevealRef = useFindRevealRef(revealSource);
987 + const sourceRevealRef = findRevealRef(revealSource);
988 const showDiagram = !showCode && !isStreaming && code.trim().length > 0;
989 const toggleLabel = showCode ? "Show diagram" : "Show code";
990 return (
apps/web/src/components/chat/MessagesTimeline.tsx
+3 -3
@@ -1,7 +1,7 @@
1 import { ThreadFindTimelineContext } from "./ThreadFindProvider";
2 import { shallow } from "zustand/vanilla/shallow";
3 import { shouldPreserveAssistantLineBreaks } from "@t3tools/shared/markdownPipeline";
4 -import { MarkdownFindContext, useFindRevealRef } from "./markdownFindContext";
4 +import { MarkdownFindContext, findRevealRef } from "./markdownFindContext";
5 import { useChatCanvas } from "./ChatCanvasContext";
6 import { WorkLogBlock, WorkLogButton, WorkLogDetails, WorkLogList, WorkLogRow } from "./WorkLog";
7 import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
@@ -4509,7 +4509,7 @@ const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(prop
4509 }) {
4510 const [expanded, setExpanded] = useState(false);
4511 const revealForFind = () => setExpanded(true);
4512 - const findRevealRef = useFindRevealRef(revealForFind);
4512 + const revealRef = findRevealRef(revealForFind);
4513 const hasVisibleBody = props.text.trim().length > 0;
4514 const canCollapse = hasVisibleBody && shouldCollapseUserMessage(props.text);
4515 const isCollapsed = canCollapse && !expanded;
@@ -4519,7 +4519,7 @@ const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(prop
4519 <div>
4520 {hasVisibleBody ? (
4521 <div
4522 - ref={findRevealRef}
4522 + ref={revealRef}
4523 className={cn("relative", isCollapsed && "max-h-44 overflow-hidden")}
4524 data-user-message-body="true"
4525 data-thread-find-text="true"
apps/web/src/components/chat/ProposedPlanCard.tsx
+3 -3
@@ -1,6 +1,6 @@
1 import { proposedPlanTitle, stripDisplayedPlanMarkdown } from "@t3tools/shared/proposedPlanText";
2 import { memo, useState, useId } from "react";
3 -import { useFindRevealRef } from "./markdownFindContext";
3 +import { findRevealRef } from "./markdownFindContext";
4 import {
5 isAtomCommandInterrupted,
6 squashAtomCommandFailure,
@@ -85,7 +85,7 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
85 // While finding, the full plan stays mounted but clipped, so a match past the
86 // preview can be counted and then opened only once it is selected.
87 const showPreview = isCollapsed && !findActive;
88 - const findRevealRef = useFindRevealRef(() => setExpanded(true));
88 + const revealRef = findRevealRef(() => setExpanded(true));
89 const downloadFilename = buildProposedPlanMarkdownFilename(planMarkdown);
90 const saveContents = normalizePlanMarkdownForExport(planMarkdown);
91
@@ -191,7 +191,7 @@ export const ProposedPlanCard = memo(function ProposedPlanCard({
191 </div>
192 <div className="mt-4">
193 <div
194 - ref={findRevealRef}
194 + ref={revealRef}
195 className={cn("relative", isCollapsed && "max-h-104 overflow-hidden")}
196 data-thread-find-text="true"
197 data-thread-find-fold={isCollapsed ? "" : undefined}
apps/web/src/components/chat/markdownFindContext.ts
+3 -4
@@ -6,11 +6,10 @@ export const MarkdownFindContext = createContext(false);
6
7 /**
8 * Find dispatches `beforematch` on hidden or clipped ancestors of the selected
9 - * match, like the browser's own find-in-page. `onReveal` must be stable.
9 + * match, like the browser's own find-in-page. Callers create the ref during render
10 + * from a stable `onReveal`, so the compiler caches it and React attaches it once.
11 */
11 -export function useFindRevealRef(onReveal: () => void) {
12 - // The compiler skips hookless functions; a new ref callback each render would re-add the listener.
13 - "use memo";
12 +export function findRevealRef(onReveal: () => void) {
13 return (element: HTMLElement | null) => {
14 if (!element) return;
15 element.addEventListener("beforematch", onReveal);