Skip to content

Commit fea5380

Browse files
perf(web): the find reveal ref compiles without manual memoization (pingdotgg#20555)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 7e850a0 commit fea5380

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContext, useCallback } from "react";
1+
import { createContext } from "react";
22

33
// While find is active, folded content stays mounted (hidden) so its text can be
44
// matched. Nothing opens until the selected match lies inside it.
@@ -9,12 +9,11 @@ export const MarkdownFindContext = createContext(false);
99
* match, like the browser's own find-in-page. `onReveal` must be stable.
1010
*/
1111
export function useFindRevealRef(onReveal: () => void) {
12-
return useCallback(
13-
(element: HTMLElement | null) => {
14-
if (!element) return;
15-
element.addEventListener("beforematch", onReveal);
16-
return () => element.removeEventListener("beforematch", onReveal);
17-
},
18-
[onReveal],
19-
);
12+
// The compiler skips hookless functions; a new ref callback each render would re-add the listener.
13+
"use memo";
14+
return (element: HTMLElement | null) => {
15+
if (!element) return;
16+
element.addEventListener("beforematch", onReveal);
17+
return () => element.removeEventListener("beforematch", onReveal);
18+
};
2019
}

0 commit comments

Comments
 (0)