Skip to content

Commit 029eaaa

Browse files
perf(mobile): shell-first opens and quieter lists for feel-faster paths
Defer heavy chrome until after the push frame (settings, thread sheet, environment pickers), keep filter/shelf updates off the press path, and split streaming markdown so settled blocks stay cheap while reconnecting. Co-authored-by: Cursor <[email protected]>
1 parent 257e407 commit 029eaaa

75 files changed

Lines changed: 3688 additions & 1361 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/components/ui/AppBar.tsx‎

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Toolbar } from "./Toolbar";
22
import { AppActivityIndicator } from "./AppActivityIndicator";
33
import type { HeaderBarButtonMailSearchToolbarItem } from "react-native-screens";
44
import { NavigationContext } from "@react-navigation/native";
5-
import { use, useId, useLayoutEffect } from "react";
5+
import { use, useEffect, useId, useLayoutEffect, useState } from "react";
66
import { View } from "react-native";
77
import { createNativeHeaderMenu } from "./nativeHeaderMenu.ios";
88
import { ScreenHeaderButton } from "./ScreenHeaderButton";
@@ -82,23 +82,71 @@ export function AppBar(props: AppBarProps) {
8282
const usesNativeMailSearchToolbar = useNativeMailSearchToolbar();
8383
const { search, menus } = props;
8484
const menu = menus?.[0];
85-
const compactSearch =
85+
// Reserve mail-toolbar chrome from the first frame even before search attaches, so menus[0]
86+
// never flashes as a trailing bar button during the push.
87+
const wantsCompactSearch =
8688
search !== undefined &&
8789
(search.compactToolbar ?? !layout.usesSplitView) &&
8890
usesNativeMailSearchToolbar;
89-
const visibleMenus = compactSearch ? (menus?.slice(1) ?? []) : (menus ?? []);
91+
// Token identity: search stays detached until transitionEnd marks this key ready.
92+
const searchAttachKey = wantsCompactSearch ? `${headerId}:compact` : null;
93+
const [attachedSearchKey, setAttachedSearchKey] = useState<string | null>(null);
94+
const searchAttached = searchAttachKey === null || attachedSearchKey === searchAttachKey;
95+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- attaches native search after the push so UIKit does not flash its trailing bar-button form
96+
useEffect(() => {
97+
if (searchAttachKey === null) return;
98+
let done = false;
99+
let opening = false;
100+
const finish = () => {
101+
if (done) return;
102+
done = true;
103+
setAttachedSearchKey(searchAttachKey);
104+
};
105+
const stackNavigation = navigation as unknown as {
106+
readonly addListener: (
107+
type: "transitionStart" | "transitionEnd",
108+
listener: (event: { readonly data: { readonly closing: boolean } }) => void,
109+
) => () => void;
110+
} | null;
111+
const removeStart = stackNavigation?.addListener("transitionStart", ({ data }) => {
112+
if (!data.closing) opening = true;
113+
});
114+
const removeEnd = stackNavigation?.addListener("transitionEnd", ({ data }) => {
115+
if (!data.closing) finish();
116+
});
117+
let frame = requestAnimationFrame(() => {
118+
frame = requestAnimationFrame(() => {
119+
if (!opening) finish();
120+
});
121+
});
122+
const fallback = setTimeout(finish, 1_000);
123+
return () => {
124+
done = true;
125+
removeStart?.();
126+
removeEnd?.();
127+
cancelAnimationFrame(frame);
128+
clearTimeout(fallback);
129+
};
130+
}, [navigation, searchAttachKey]);
131+
const compactSearch = wantsCompactSearch && searchAttached;
132+
const activeSearch = wantsCompactSearch && !searchAttached ? undefined : search;
133+
const visibleMenus = wantsCompactSearch ? (menus?.slice(1) ?? []) : (menus ?? []);
90134
// Where the mail toolbar isn't used, the Duo keeps search at the bottom of the pane like its
91135
// workspace lists; elsewhere inline search is a button in the bar.
92136
const duoBottomSearch =
93-
search !== undefined &&
137+
activeSearch !== undefined &&
94138
!compactSearch &&
95139
NATIVE_MAIL_SEARCH_TOOLBAR_SUPPORTED &&
96140
isDuoDevice(deviceType);
97141
if (props.embedded || props.sheet) return null;
98142
return (
99143
<>
100144
<NativeStackScreenOptions
101-
optionsVersion={[props.optionsVersion, compactSearch ? menu : undefined]}
145+
optionsVersion={[
146+
props.optionsVersion,
147+
wantsCompactSearch ? menu : undefined,
148+
searchAttached,
149+
]}
102150
options={{
103151
headerShown: true,
104152
headerBackVisible:
@@ -112,14 +160,14 @@ export function AppBar(props: AppBarProps) {
112160
...(props.matchSearchSurface
113161
? { contentStyle: { backgroundColor: themeVariables["--color-sheet-solid"] } }
114162
: undefined),
115-
...(search
163+
...(activeSearch
116164
? {
117165
unstable_headerToolbarItems: compactSearch
118166
? () => [
119167
createNativeMailSearchToolbarItem({
120168
showsSearchDismissButton: true,
121-
placeholder: search.compactPlaceholder ?? search.placeholder,
122-
onSearchTextChange: search.onChangeText,
169+
placeholder: activeSearch.compactPlaceholder ?? activeSearch.placeholder,
170+
onSearchTextChange: activeSearch.onChangeText,
123171
searchTextChangeId: `${headerId}-search-text`,
124172
...(menu
125173
? {
@@ -137,20 +185,25 @@ export function AppBar(props: AppBarProps) {
137185
allowToolbarIntegration: true,
138186
...(duoBottomSearch
139187
? { placement: "integrated" as const }
140-
: NATIVE_MAIL_SEARCH_TOOLBAR_SUPPORTED && search.mode === "inline"
188+
: NATIVE_MAIL_SEARCH_TOOLBAR_SUPPORTED && activeSearch.mode === "inline"
141189
? { placement: "integratedButton" as const }
142190
: undefined),
143191
autoCapitalize: "none",
144192
hideNavigationBar: false,
145-
...(search.mode === "inline" || duoBottomSearch
193+
...(activeSearch.mode === "inline" || duoBottomSearch
146194
? { obscureBackground: false }
147195
: undefined),
148-
placeholder: search.placeholder,
149-
onChangeText: (event) => search.onChangeText(event.nativeEvent.text),
150-
onCancelButtonPress: () => search.onChangeText(""),
196+
placeholder: activeSearch.placeholder,
197+
onChangeText: (event) => activeSearch.onChangeText(event.nativeEvent.text),
198+
onCancelButtonPress: () => activeSearch.onChangeText(""),
151199
},
152200
}
153-
: undefined),
201+
: wantsCompactSearch
202+
? {
203+
// Keep the mail-toolbar filter slot reserved before search attaches.
204+
unstable_headerToolbarItems: () => [],
205+
}
206+
: undefined),
154207
}}
155208
/>
156209
{props.onClose ? (

‎apps/mobile/src/components/ui/RowPressable.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ export function RowPressable({
2020
return (
2121
<GestureDetector gesture={hoverGesture}>
2222
<Pressable {...props} className={cn("relative overflow-hidden", className)}>
23-
{() => (
23+
{({ pressed }) => (
2424
<>
2525
<View
2626
pointerEvents="none"
2727
className={cn("absolute inset-0", interactionClassName)}
28-
style={{ opacity: props.disabled || !hovered ? 0 : interactionOpacity }}
28+
style={{
29+
// Phones have no hover; show the same wash on press so taps feel acknowledged
30+
// before navigation starts.
31+
opacity: props.disabled || !(hovered || pressed) ? 0 : interactionOpacity,
32+
}}
2933
/>
3034
{children}
3135
</>

‎apps/mobile/src/features/archive/ArchivedThreadsScreen.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,10 @@ export function ArchivedThreadsScreen(props: {
423423
}}
424424
contentInsetAdjustmentBehavior="automatic"
425425
data={listItems}
426+
drawDistance={500}
426427
estimatedItemSize={62}
427428
getItemType={(item) => item.kind}
429+
itemsAreEqual={(previous, next) => previous === next}
428430
keyboardDismissMode="on-drag"
429431
keyboardShouldPersistTaps="handled"
430432
keyExtractor={(item) => item.key}
@@ -433,6 +435,7 @@ export function ArchivedThreadsScreen(props: {
433435
props.error ? <ArchiveError message={props.error} onRetry={props.onRefresh} /> : null
434436
}
435437
onScrollBeginDrag={() => openSwipeableRef.current?.close()}
438+
recycleItems
436439
refreshControl={
437440
<RefreshControl
438441
onRefresh={props.onRefresh}

‎apps/mobile/src/features/connection/ConnectionEnvironmentRow.tsx‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ export function ConnectionEnvironmentRow(props: {
9090
);
9191
};
9292

93-
return (
94-
<Animated.View layout={LinearTransition.duration(250)} className="bg-grouped-card">
93+
const body = (
94+
<>
9595
<View className="flex-row items-center gap-3 px-4 py-3.5">
9696
<Pressable
9797
className="min-w-0 flex-1 gap-0.5 active:opacity-70"
@@ -315,6 +315,16 @@ export function ConnectionEnvironmentRow(props: {
315315
)}
316316
</Animated.View>
317317
) : null}
318+
</>
319+
);
320+
321+
// Details push doesn't expand inline — skip layout animation work on that path.
322+
if (props.opensDetails) {
323+
return <View className="bg-grouped-card">{body}</View>;
324+
}
325+
return (
326+
<Animated.View layout={LinearTransition.duration(250)} className="bg-grouped-card">
327+
{body}
318328
</Animated.View>
319329
);
320330
}

‎apps/mobile/src/features/files/FileTreeBrowser.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { LegendList } from "@legendapp/list/react-native";
44
import type { ProjectEntry } from "@t3tools/contracts";
55
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
66
import { SymbolView } from "../../components/ui/AppSymbol";
7-
import { useEffect, useRef, useState } from "react";
7+
import { useEffect, useMemo, useRef, useState } from "react";
88
import { Pressable, RefreshControl, View } from "react-native";
99

1010
import { AppText as Text } from "../../components/ui/AppText";
@@ -208,7 +208,11 @@ export function FileTreeBrowser(props: {
208208
/>
209209
);
210210

211-
const extraData = { expandedPaths, loadingDirectories, selectedPath };
211+
// Keep LegendList from refreshing every visible row on parent ticks that rebuild this object.
212+
const extraData = useMemo(
213+
() => ({ expandedPaths, loadingDirectories, selectedPath }),
214+
[expandedPaths, loadingDirectories, selectedPath],
215+
);
212216

213217
// Keep the list as direct screen content so UIKit can apply header insets.
214218
return (
@@ -224,6 +228,7 @@ export function FileTreeBrowser(props: {
224228
keyboardDismissMode="on-drag"
225229
keyboardShouldPersistTaps="handled"
226230
estimatedItemSize={42}
231+
drawDistance={500}
227232
recycleItems
228233
maintainVisibleContentPosition
229234
extraData={extraData}

‎apps/mobile/src/features/files/SourceFileSurface.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ function JavaScriptSourceFileSurface(props: SourceFileSurfaceProps) {
330330
refreshControl={refreshControl}
331331
data={lines}
332332
keyExtractor={(_line, index) => String(index)}
333-
initialNumToRender={80}
334-
maxToRenderPerBatch={80}
335-
windowSize={12}
333+
initialNumToRender={24}
334+
maxToRenderPerBatch={24}
335+
windowSize={7}
336336
{...(codeWordBreak
337337
? {}
338338
: {

‎apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx‎

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
33
import { resolveFilesystemReadAccess } from "@t3tools/client-runtime/state/filesystem";
44
import { environmentSession } from "../../state/session";
55
import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
6-
import { type ReactNode, useId, useState } from "react";
6+
import { type ReactNode, startTransition, useEffect, useId, useState } from "react";
77
import { Platform, View } from "react-native";
88
import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
99
import { EnvironmentId, type ProjectReadFileResult, ThreadId } from "@t3tools/contracts";
@@ -15,6 +15,7 @@ import {
1515
} from "@t3tools/shared/filePreview";
1616
import { mediaFileReference } from "@t3tools/client-runtime/media-reference";
1717

18+
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
1819
import { ScreenContent } from "../../components/ui/ScreenContent";
1920
import { filePreviewDelimiter, parseDelimitedPreview } from "@t3tools/shared/delimitedPreview";
2021
import { DelimitedFilePreview } from "./DelimitedFilePreview";
@@ -422,6 +423,14 @@ export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
422423
const navigation = useNavigation();
423424
const { fileInspector } = useAdaptiveWorkspaceLayout();
424425
const [searchQuery, setSearchQuery] = useState("");
426+
// Push presents with the Files bar first; LegendList mounts after the open frame.
427+
const [treeReady, setTreeReady] = useState(false);
428+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- defers the file tree until after the Files route open frame
429+
useEffect(() => {
430+
startTransition(() => {
431+
setTreeReady(true);
432+
});
433+
}, []);
425434
const { themeAppearance: highlightTheme } = useAppearancePreferences();
426435
const { cwd, environmentId, projectName, selectedThread, threadId } = useThreadFilesWorkspace(
427436
props.route.params,
@@ -546,28 +555,34 @@ export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
546555
onBack={handleReturnToThread}
547556
/>
548557
<ScreenContent>
549-
<FileTreeBrowser
550-
key={JSON.stringify([environmentId, cwd])}
551-
revealSelection={entriesQuery.revealSelection}
552-
expandedPaths={entriesQuery.expandedPaths}
553-
setExpandedPaths={entriesQuery.setExpandedPaths}
554-
entries={entriesQuery.entries}
555-
loadingDirectories={entriesQuery.loadingDirectories}
556-
onLoadDirectory={entriesQuery.loadDirectory}
557-
error={entriesQuery.error}
558-
isPending={entriesQuery.isPending}
559-
isRefreshing={entriesQuery.isRefreshing}
560-
searchQuery={searchQuery}
561-
searchResultPaths={entriesQuery.searchResultPaths}
562-
searchTruncated={entriesQuery.searchTruncated}
563-
selectedPath={entriesQuery.selectedPath}
564-
onPreviewFile={handlePreviewFile}
565-
onRefresh={entriesQuery.refresh}
566-
onSelectFile={(path) => {
567-
entriesQuery.selectPath(path);
568-
handleSelectFile(path);
569-
}}
570-
/>
558+
{treeReady ? (
559+
<FileTreeBrowser
560+
key={JSON.stringify([environmentId, cwd])}
561+
revealSelection={entriesQuery.revealSelection}
562+
expandedPaths={entriesQuery.expandedPaths}
563+
setExpandedPaths={entriesQuery.setExpandedPaths}
564+
entries={entriesQuery.entries}
565+
loadingDirectories={entriesQuery.loadingDirectories}
566+
onLoadDirectory={entriesQuery.loadDirectory}
567+
error={entriesQuery.error}
568+
isPending={entriesQuery.isPending}
569+
isRefreshing={entriesQuery.isRefreshing}
570+
searchQuery={searchQuery}
571+
searchResultPaths={entriesQuery.searchResultPaths}
572+
searchTruncated={entriesQuery.searchTruncated}
573+
selectedPath={entriesQuery.selectedPath}
574+
onPreviewFile={handlePreviewFile}
575+
onRefresh={entriesQuery.refresh}
576+
onSelectFile={(path) => {
577+
entriesQuery.selectPath(path);
578+
handleSelectFile(path);
579+
}}
580+
/>
581+
) : (
582+
<View className="px-4 py-5">
583+
<AppActivityIndicator size="small" accessibilityLabel="Loading files" />
584+
</View>
585+
)}
571586
<FilesToolbarBottomFade />
572587
</ScreenContent>
573588
</View>

‎apps/mobile/src/features/files/thread-file-navigator-pane.tsx‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { resolveFilesystemReadAccess } from "@t3tools/client-runtime/state/filesystem";
22
import { environmentSession } from "../../state/session";
33
import type { EnvironmentId } from "@t3tools/contracts";
4+
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
45
import { AppBar } from "../../components/ui/AppBar";
56
import { ScreenContent } from "../../components/ui/ScreenContent";
6-
import { useState } from "react";
7+
import { startTransition, useEffect, useState } from "react";
78
import { View } from "react-native";
89

910
import { useEnvironmentQuery } from "../../state/query";
@@ -20,6 +21,14 @@ export function ThreadFileNavigatorPane(props: {
2021
readonly selectedPath: string | null;
2122
readonly onSelectFile: (path: string) => void;
2223
}) {
24+
// Sheet/column present with the Files bar first; LegendList mounts after the open frame.
25+
const [treeReady, setTreeReady] = useState(false);
26+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- defers the file tree until after the inspector open frame
27+
useEffect(() => {
28+
startTransition(() => {
29+
setTreeReady(true);
30+
});
31+
}, []);
2332
const [searchQuery, setSearchQuery] = useState("");
2433
const { themeAppearance: highlightTheme } = useAppearancePreferences();
2534
const fileAccessSession = useEnvironmentQuery(
@@ -46,7 +55,7 @@ export function ThreadFileNavigatorPane(props: {
4655
theme: highlightTheme,
4756
});
4857
};
49-
const fileTree = (
58+
const fileTree = treeReady ? (
5059
<FileTreeBrowser
5160
key={JSON.stringify([props.environmentId, props.cwd])}
5261
revealSelection={entriesQuery.revealSelection}
@@ -75,6 +84,10 @@ export function ThreadFileNavigatorPane(props: {
7584
props.onSelectFile(path);
7685
}}
7786
/>
87+
) : (
88+
<View className="px-4 py-5">
89+
<AppActivityIndicator size="small" accessibilityLabel="Loading files" />
90+
</View>
7891
);
7992

8093
return (

0 commit comments

Comments
 (0)