Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions apps/mobile/src/features/threads/ThreadFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,33 @@ function ThreadFeedPlaceholder(props: {
);
}

// A hook's return value is frozen to the compiler, so ThreadFeed's later
// hooks can't drag this derivation into an uncached scope.
function useThreadFeedPresentation(
props: ThreadFeedProps,
expandedTurnIds: ReadonlySet<RunId>,
expandedWorkGroups: Record<string, boolean>,
) {
const [feedCache] = useState(createThreadFeedCache);
return appendPendingThreadMessages(
deriveThreadFeedPresentation(
props.feed,
props.latestRun,
expandedTurnIds,
new Set(
Object.entries(expandedWorkGroups)
.filter(([, expanded]) => expanded)
.map(([groupId]) => groupId),
),
props.activeWorkStartedAt,
props.runlessWorkActive ?? false,
feedCache,
),
props.feed,
props.queuedMessages,
);
}

export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
const { listRef, onEndFollowEnabledChange, onHeaderMaterialVisibilityChange } = props;
const workflowOpening = useWorkflowOpening(props.environmentId, props.threadId);
Expand All @@ -1759,7 +1786,6 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
const disclosureSettleFrameRef = useRef<number | null>(null);
const disclosureSettleSecondFrameRef = useRef<number | null>(null);
const disclosureAnchorKeyRef = useRef<string | null>(null);
const [feedCache] = useState(createThreadFeedCache);
const previousLatestTurnRef = useRef(props.latestRun);
const userScrollSettleTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const headerMaterialVisibleRef = useRef(false);
Expand Down Expand Up @@ -2315,23 +2341,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
reportHeaderMaterialVisibility(false);
}, [feedThreadKey, reportHeaderMaterialVisibility]);

const presentedFeed = appendPendingThreadMessages(
deriveThreadFeedPresentation(
props.feed,
props.latestRun,
expandedTurnIds,
new Set(
Object.entries(expandedWorkGroups)
.filter(([, expanded]) => expanded)
.map(([groupId]) => groupId),
),
props.activeWorkStartedAt,
props.runlessWorkActive ?? false,
feedCache,
),
props.feed,
props.queuedMessages,
);
const presentedFeed = useThreadFeedPresentation(props, expandedTurnIds, expandedWorkGroups);
const setupAnchorIndex = presentedFeed.findIndex(
(entry) => entry.type === "message" && entry.message.role === "user",
);
Expand Down
Loading