Skip to content
TypeScript

perf(web): the find reveal ref compiles without manual memoization (#20555)

Julius Marmingefea5380159fe
diff --git a/apps/web/src/components/chat/markdownFindContext.ts b/apps/web/src/components/chat/markdownFindContext.ts
index 64754cc6b3c..0f9ad661a91 100644
--- a/apps/web/src/components/chat/markdownFindContext.ts
+++ b/apps/web/src/components/chat/markdownFindContext.ts
@@ -1,4 +1,4 @@
-import { createContext, useCallback } from "react";
+import { createContext } from "react";
// While find is active, folded content stays mounted (hidden) so its text can be
// matched. Nothing opens until the selected match lies inside it.
@@ -9,12 +9,11 @@ export const MarkdownFindContext = createContext(false);
* match, like the browser's own find-in-page. `onReveal` must be stable.
*/
export function useFindRevealRef(onReveal: () => void) {
- return useCallback(
- (element: HTMLElement | null) => {
- if (!element) return;
- element.addEventListener("beforematch", onReveal);
- return () => element.removeEventListener("beforematch", onReveal);
- },
- [onReveal],
- );
+ // The compiler skips hookless functions; a new ref callback each render would re-add the listener.
+ "use memo";
+ return (element: HTMLElement | null) => {
+ if (!element) return;
+ element.addEventListener("beforematch", onReveal);
+ return () => element.removeEventListener("beforematch", onReveal);
+ };
}