@devries-cameron20 / t3code-1 / commits / fecd7138e9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): long threads no longer jump to the bottom after they appear (#37559)

Julius Marminge committed Nov 16, 2026 at 08:40 UTC fecd7138e97d6b77265f5d73ec8ed62261b8632c
1 file changed +29 -8
apps/mobile/src/features/threads/ThreadFeed.tsx
+29 -8
@@ -3476,14 +3476,26 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
3476 };
3477 const feedThreadKey = scopedThreadKey(props.environmentId, props.threadId);
3478 const [loadedListKey, setLoadedListKey] = useState<string | null>(null);
3479 - // LegendList hides rows until it has scrolled to the end, but not its header.
3480 - const settling = props.feed.length > 0 && loadedListKey !== feedThreadKey;
3481 - const handleMetricsChange = () => {
3479 + const [landedListKey, setLandedListKey] = useState<string | null>(null);
3480 + // LegendList reports ready, and shows its rows, while rows measured during its initial scroll can
3481 + // still leave it hundreds of points short of the end; isAtEnd stays true through that.
3482 + const settling = props.feed.length > 0 && landedListKey !== feedThreadKey;
3483 + const landingFallback = useRef<ReturnType<typeof setTimeout> | null>(null);
3484 + const reportMetrics = (ready: boolean) => {
3485 const state = listRef.current?.getState();
3486 + if (!state) return;
3487 + if (
3488 + settling &&
3489 + ready &&
3490 + (state.distanceFromEnd <= 2 || !state.isFollowingEnd || props.jumpToMessageId)
3491 + ) {
3492 + setLandedListKey(feedThreadKey);
3493 + }
3494 // Offset 0 before the first positioning, and the gaps while rows measure in, are not the
3495 // user leaving the end; only a scroll away stops end following.
3485 - if (state) onIsAtEndChange?.(settling || state.isAtEnd || state.isFollowingEnd);
3496 + onIsAtEndChange?.(settling || state.isAtEnd || state.isFollowingEnd);
3497 };
3498 + const handleMetricsChange = () => reportMetrics(loadedListKey === feedThreadKey);
3499 const handleScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
3500 reportHeaderMaterialVisibility(
3501 event.nativeEvent.contentOffset.y + (usesNativeAutomaticInsets ? barInset : 0) > 6,
@@ -3506,6 +3518,13 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
3518 for (const stop of stops) stop();
3519 };
3520 }, [listRef, handleMetricsChange]);
3521 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- clears the landing fallback timer when the feed unmounts
3522 + useEffect(
3523 + () => () => {
3524 + if (landingFallback.current !== null) clearTimeout(landingFallback.current);
3525 + },
3526 + [],
3527 + );
3528 const [workGroupScrollPositions] = useState(
3529 () => new Map<string, ThreadWorkGroupScrollPosition>(),
3530 );
@@ -3949,7 +3968,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
3968 <KeyboardAwareLegendList
3969 ref={attachList}
3970 dataKey={feedThreadKey}
3952 - style={{ flex: 1 }}
3971 + style={settling ? { flex: 1, opacity: 0 } : { flex: 1 }}
3972 // RN 0.81+ drops inset-area touches (facebook/react-native#54123), making blank post-send space unscrollable.
3973 applyWorkaroundForContentInsetHitTestBug
3974 {...(Platform.OS === "ios" ? { ScrollViewComponent: ThreadFeedScrollView } : {})}
@@ -4001,14 +4020,16 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
4020 initialScrollAtEnd
4021 onReady={() => {
4022 setLoadedListKey(feedThreadKey);
4004 - handleMetricsChange();
4023 + reportMetrics(true);
4024 + // Never leave the feed hidden if end following stalls short of the end.
4025 + landingFallback.current = setTimeout(() => setLandedListKey(feedThreadKey), 1000);
4026 }}
4027 onLayout={handleMetricsChange}
4028 onItemSizeChanged={handleItemSizeChanged}
4029 onScroll={handleScroll}
4030 scrollEventThrottle={16}
4031 ListHeaderComponent={
4011 - <View style={settling ? { opacity: 0 } : undefined}>
4032 + <>
4033 {usesNativeAutomaticInsets ? null : <View style={{ height: topContentInset }} />}
4034 {setupAnchorIndex < 0 && props.worktreeSetup ? (
4035 <WorktreeSetupCard key={props.threadId} {...props.worktreeSetup} />
@@ -4018,7 +4039,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
4039 {props.historyControls ? (
4040 <ThreadFeedLoadEarlierControl {...props.historyControls} />
4041 ) : null}
4021 - </View>
4042 + </>
4043 }
4044 ListFooterComponent={
4045 props.pendingHandoff ? (