@@ -54,6 +54,7 @@ import {
5454} from "lucide-react" ;
5555import {
5656 lazy ,
57+ memo ,
5758 Suspense ,
5859 type MouseEvent as ReactMouseEvent ,
5960 useEffect ,
@@ -68,6 +69,7 @@ import { type DraftId, useComposerDraftStore } from "~/composerDraftStore";
6869import { type PullRequestDetailTab , useRightPanelStore } from "~/rightPanelStore" ;
6970import { useEnvironmentSettings } from "~/hooks/useSettings" ;
7071import { useNewThreadHandler } from "~/hooks/useHandleNewThread" ;
72+ import { useStableCallback } from "~/hooks/useStableCallback" ;
7173import { useCopyToClipboard } from "~/hooks/useCopyToClipboard" ;
7274import { isCommandPaletteOpen } from "~/commandPaletteBus" ;
7375import {
@@ -245,7 +247,9 @@ const TABS: ReadonlyArray<{ value: PullRequestDetailTab; label: string }> = [
245247
246248// The diff viewer pulls in its worker pool, so load it only when the reader approaches Code.
247249const loadCodeTab = ( ) => import ( "./PullRequestCodeTab" ) ;
248- const PullRequestCodeTab = lazy ( loadCodeTab ) ;
250+ const PullRequestCodeTab = memo ( lazy ( loadCodeTab ) ) ;
251+ const RetainedSummaryTab = memo ( PullRequestSummaryTab ) ;
252+ const RetainedTimelineTab = memo ( PullRequestTimelineTab ) ;
249253
250254/**
251255 * What the last hand-off wrote into each draft, kept outside React because the panel that wrote it
@@ -657,13 +661,13 @@ export function PullRequestDetailPanel({
657661 } > ( ( ) => ( { pullRequestKey, oid : null } ) ) ;
658662 const selectedCodeCommitOid =
659663 codeCommitScope . pullRequestKey === pullRequestKey ? codeCommitScope . oid : null ;
660- const selectCodeCommit = ( oid : string | null ) => {
664+ const selectCodeCommit = useStableCallback ( ( oid : string | null ) => {
661665 setCodeCommitScope ( { pullRequestKey, oid } ) ;
662- } ;
663- const openCommit = ( oid : string ) => {
666+ } ) ;
667+ const openCommit = useStableCallback ( ( oid : string ) => {
664668 selectCodeCommit ( oid ) ;
665669 selectTab ( "code" ) ;
666- } ;
670+ } ) ;
667671 const [ codeRevealRequest , setCodeRevealRequest ] = useState < {
668672 readonly path : string ;
669673 readonly nonce : number ;
@@ -843,11 +847,11 @@ export function PullRequestDetailPanel({
843847 } ) ;
844848 const activityPending = activityQuery . isPending && activity === null ;
845849 const activityError = activity === null ? activityQuery . error : null ;
846- const refreshDetail = ( ) => {
850+ const refreshDetail = useStableCallback ( ( ) => {
847851 detailQuery . refresh ( ) ;
848852 activityQuery . refresh ( ) ;
849853 nativeStackQuery . refresh ( ) ;
850- } ;
854+ } ) ;
851855 const [ refreshToken , setRefreshToken ] = useState ( 0 ) ;
852856 const [ activityRevision , setActivityRevision ] = useState < {
853857 readonly key : string ;
@@ -883,14 +887,14 @@ export function PullRequestDetailPanel({
883887 const invalidate = useAtomCommand ( pullRequestEnvironment . invalidate , { reportFailure : false } ) ;
884888 const [ isInvalidating , setIsInvalidating ] = useState ( false ) ;
885889 const refreshing = isInvalidating || detailQuery . isPending ;
886- const refreshFromHost = async ( ) => {
890+ const refreshFromHost = useStableCallback ( async ( ) => {
887891 setIsInvalidating ( true ) ;
888892 // Atom commands settle instead of throwing, so the reset below always runs.
889893 await invalidate ( { environmentId, input : { reference } } ) ;
890894 refreshDetail ( ) ;
891895 setRefreshToken ( ( token ) => token + 1 ) ;
892896 setIsInvalidating ( false ) ;
893- } ;
897+ } ) ;
894898 const refreshFromHostOnRequest = useEffectEvent ( ( ) => void refreshFromHost ( ) ) ;
895899 const appliedForcedToken = useRef ( forcedRefreshToken ) ;
896900 useEffect ( ( ) => {
@@ -1349,34 +1353,33 @@ export function PullRequestDetailPanel({
13491353 ) ;
13501354 } ;
13511355
1352- const addSelectionToAgent = (
1353- selection : PullRequestAgentSelectionInput ,
1354- options ?: { readonly keepGuide ?: boolean } ,
1355- ) => {
1356- if ( ! detail ) return ;
1357- void startAsk (
1358- `selection:${ selection . comment . id } ` ,
1359- buildAddSelectionToAgentHandoff ( {
1360- number : detail . number ,
1361- title : detail . title ,
1362- url : detail . url ,
1363- headBranch : detail . headBranch ,
1364- baseBranch : detail . baseBranch ,
1365- state : detail . state ,
1366- isDraft : detail . isDraft ,
1367- comment : selection . comment ,
1368- request : selection . request ,
1369- } ) ,
1370- options ,
1371- ) ;
1372- } ;
1356+ const addSelectionToAgent = useStableCallback (
1357+ ( selection : PullRequestAgentSelectionInput , options ?: { readonly keepGuide ?: boolean } ) => {
1358+ if ( ! detail ) return ;
1359+ void startAsk (
1360+ `selection:${ selection . comment . id } ` ,
1361+ buildAddSelectionToAgentHandoff ( {
1362+ number : detail . number ,
1363+ title : detail . title ,
1364+ url : detail . url ,
1365+ headBranch : detail . headBranch ,
1366+ baseBranch : detail . baseBranch ,
1367+ state : detail . state ,
1368+ isDraft : detail . isDraft ,
1369+ comment : selection . comment ,
1370+ request : selection . request ,
1371+ } ) ,
1372+ options ,
1373+ ) ;
1374+ } ,
1375+ ) ;
13731376
13741377 const startCheckout = ( mode : "worktree" | "local" ) => {
13751378 if ( ! handoffSummary ) return ;
13761379 void startHandoff ( `checkout:${ mode } ` , null , mode ) ;
13771380 } ;
13781381
1379- const startFixFinding = ( finding : PullRequestFinding ) => {
1382+ const startFixFinding = useStableCallback ( ( finding : PullRequestFinding ) => {
13801383 if ( ! detail ) return ;
13811384 void startHandoff (
13821385 pullRequestFindingKey ( finding ) ,
@@ -1389,7 +1392,7 @@ export function PullRequestDetailPanel({
13891392 finding,
13901393 } ) ,
13911394 ) ;
1392- } ;
1395+ } ) ;
13931396
13941397 const startFixFindings = ( ) => {
13951398 if ( ! detail ) return ;
@@ -2814,7 +2817,7 @@ export function PullRequestDetailPanel({
28142817 < PullRequestMarkdownContext value = { markdownContext } >
28152818 { mountedTabs . has ( "summary" ) ? (
28162819 < div className = { cn ( "absolute inset-0" , tab !== "summary" && "invisible" ) } >
2817- < PullRequestSummaryTab
2820+ < RetainedSummaryTab
28182821 scrollerRef = { scrollerRefs . summary }
28192822 environmentId = { environmentId }
28202823 threadRef = { threadRef }
@@ -2869,7 +2872,7 @@ export function PullRequestDetailPanel({
28692872 onRetry = { activityQuery . refresh }
28702873 />
28712874 ) : (
2872- < PullRequestTimelineTab
2875+ < RetainedTimelineTab
28732876 scrollerRef = { scrollerRefs . timeline }
28742877 detail = { detail }
28752878 environmentId = { environmentId }
0 commit comments