@@ -1671,6 +1671,33 @@ function ThreadFeedPlaceholder(props: {
16711671 ) ;
16721672}
16731673
1674+ // A hook's return value is frozen to the compiler, so ThreadFeed's later
1675+ // hooks can't drag this derivation into an uncached scope.
1676+ function useThreadFeedPresentation (
1677+ props : ThreadFeedProps ,
1678+ expandedTurnIds : ReadonlySet < RunId > ,
1679+ expandedWorkGroups : Record < string , boolean > ,
1680+ ) {
1681+ const [ feedCache ] = useState ( createThreadFeedCache ) ;
1682+ return appendPendingThreadMessages (
1683+ deriveThreadFeedPresentation (
1684+ props . feed ,
1685+ props . latestRun ,
1686+ expandedTurnIds ,
1687+ new Set (
1688+ Object . entries ( expandedWorkGroups )
1689+ . filter ( ( [ , expanded ] ) => expanded )
1690+ . map ( ( [ groupId ] ) => groupId ) ,
1691+ ) ,
1692+ props . activeWorkStartedAt ,
1693+ props . runlessWorkActive ?? false ,
1694+ feedCache ,
1695+ ) ,
1696+ props . feed ,
1697+ props . queuedMessages ,
1698+ ) ;
1699+ }
1700+
16741701export const ThreadFeed = memo ( function ThreadFeed ( props : ThreadFeedProps ) {
16751702 const { listRef, onEndFollowEnabledChange, onHeaderMaterialVisibilityChange } = props ;
16761703 const workflowOpening = useWorkflowOpening ( props . environmentId , props . threadId ) ;
@@ -1683,7 +1710,6 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
16831710 const disclosureSettleFrameRef = useRef < number | null > ( null ) ;
16841711 const disclosureSettleSecondFrameRef = useRef < number | null > ( null ) ;
16851712 const disclosureAnchorKeyRef = useRef < string | null > ( null ) ;
1686- const [ feedCache ] = useState ( createThreadFeedCache ) ;
16871713 const previousLatestTurnRef = useRef ( props . latestRun ) ;
16881714 const userScrollSettleTimerRef = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
16891715 const headerMaterialVisibleRef = useRef ( false ) ;
@@ -2094,23 +2120,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
20942120 reportHeaderMaterialVisibility ( false ) ;
20952121 } , [ feedThreadKey , reportHeaderMaterialVisibility ] ) ;
20962122
2097- const presentedFeed = appendPendingThreadMessages (
2098- deriveThreadFeedPresentation (
2099- props . feed ,
2100- props . latestRun ,
2101- expandedTurnIds ,
2102- new Set (
2103- Object . entries ( expandedWorkGroups )
2104- . filter ( ( [ , expanded ] ) => expanded )
2105- . map ( ( [ groupId ] ) => groupId ) ,
2106- ) ,
2107- props . activeWorkStartedAt ,
2108- props . runlessWorkActive ?? false ,
2109- feedCache ,
2110- ) ,
2111- props . feed ,
2112- props . queuedMessages ,
2113- ) ;
2123+ const presentedFeed = useThreadFeedPresentation ( props , expandedTurnIds , expandedWorkGroups ) ;
21142124 const setupAnchorIndex = presentedFeed . findIndex (
21152125 ( entry ) => entry . type === "message" && entry . message . role === "user" ,
21162126 ) ;
0 commit comments