GeezerVison is showing github.com — perf(mobile): thread switches commit less and show their rows sooner … · patroza/t3code@2ae7315
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/browser/ThreadBrowserFloat.tsx +10-7Lines changed: 10 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,7 @@ import { useAppForeground } from "../../lib/appState"; | 12 | 12 | import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider"; | 13 | 13 | import { browserTabTitle } from "./browserTabs"; | 14 | 14 | import { PreviewStreamWebView } from "./PreviewStreamWebView"; | | 15 | +import { useThreadServerBrowserTabs } from "../../state/preview"; | 15 | 16 | import { usePreparedConnection } from "../../state/session"; | 16 | 17 |
| 17 | 18 | const PLAYER_LONG_SIDE = 184; | @@ -21,28 +22,30 @@ const PLAYER_EXITING = FadeOut.duration(120).reduceMotion(ReduceMotion.System); | 21 | 22 | export function ThreadBrowserFloat(props: { | 22 | 23 | readonly environmentId: EnvironmentId; | 23 | 24 | readonly threadId: ThreadId; | 24 | | - readonly tabs: ReadonlyArray<PreviewSessionSnapshot>; | 25 | | - readonly loaded: boolean; | | 25 | + /** Whether the environment serves browser tabs. */ | | 26 | + readonly enabled: boolean; | 26 | 27 | readonly top: number; | 27 | 28 | readonly onOpen: (tabId: string) => void; | 28 | 29 | }) { | | 30 | + // Read here rather than by the thread screen, so a list read re-renders only the float. | | 31 | + const { tabs, loaded } = useThreadServerBrowserTabs(props); | 29 | 32 | const [tabId, setTabId] = useState<string | null>(null); | 30 | 33 | // The reveal requests already seen, so only a tab revealed after the first | 31 | 34 | // list pops the player. | 32 | 35 | const [seen, setSeen] = useState<{ | 33 | 36 | readonly tabs: ReadonlyArray<PreviewSessionSnapshot>; | 34 | 37 | readonly reveals: ReadonlyMap<string, string | undefined>; | 35 | 38 | } | null>(null); | 36 | | - if (props.loaded && seen?.tabs !== props.tabs) { | | 39 | + if (loaded && seen?.tabs !== tabs) { | 37 | 40 | setSeen({ | 38 | | - tabs: props.tabs, | 39 | | - reveals: new Map(props.tabs.map((tab) => [tab.tabId, tab.revealRequest?.id])), | | 41 | + tabs, | | 42 | + reveals: new Map(tabs.map((tab) => [tab.tabId, tab.revealRequest?.id])), | 40 | 43 | }); | 41 | 44 | const previous = seen?.reveals; | 42 | 45 | const opened = | 43 | 46 | previous === undefined | 44 | 47 | ? undefined | 45 | | - : props.tabs.findLast( | | 48 | + : tabs.findLast( | 46 | 49 | (tab) => | 47 | 50 | tab.reveal === true && | 48 | 51 | (tab.revealRequest | @@ -53,7 +56,7 @@ export function ThreadBrowserFloat(props: { | 53 | 56 | } | 54 | 57 | const focused = useIsFocused(); | 55 | 58 | const foreground = useAppForeground(); | 56 | | - const tab = props.tabs.find((entry) => entry.tabId === tabId) ?? null; | | 59 | + const tab = tabs.find((entry) => entry.tabId === tabId) ?? null; | 57 | 60 | const onOpen = props.onOpen; | 58 | 61 | const open = () => { | 59 | 62 | if (tabId === null) return; | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/home/useThreadListActions.test.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -42,6 +42,9 @@ vi.mock("react", () => ({ | 42 | 42 | useCallback: (callback: unknown) => callback, | 43 | 43 | useRef: (current: unknown) => ({ current }), | 44 | 44 | })); | | 45 | +vi.mock("../../lib/useStableCallback", () => ({ | | 46 | + useStableCallback: (callback: unknown) => callback, | | 47 | +})); | 45 | 48 | vi.mock("react-native", () => ({ | 46 | 49 | Alert: { | 47 | 50 | alert: (title: string, _message: string, buttons?: { text: string; onPress?: () => void }[]) => | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/home/useThreadListActions.ts +34-12Lines changed: 34 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -42,6 +42,7 @@ import { | 42 | 42 | import { getThreadListV2OrderedSection } from "../threads/threadListV2"; | 43 | 43 | import { threadCanArchive } from "./threadArchive"; | 44 | 44 | import { resolveThreadTitleRename } from "../threads/thread-title-rename"; | | 45 | +import { useStableCallback } from "../../lib/useStableCallback"; | 45 | 46 |
| 46 | 47 | function environmentConfigLoaded(environmentId: EnvironmentThreadShell["environmentId"]) { | 47 | 48 | return appAtomRegistry.get(environmentServerConfigsAtom).has(environmentId); | @@ -833,20 +834,41 @@ export function useThreadListActions(): { | 833 | 834 | const confirmDeleteThread = (thread: EnvironmentThreadShell) => | 834 | 835 | confirmThreadDeletion(executeAction, thread); | 835 | 836 |
| | 837 | + // Stable, so a list that re-renders does not re-render every row these reach. | 836 | 838 | // `moveThread` looks up its own row, and refuses while a list holds older rows. | 837 | 839 | return { | 838 | | - archiveThread: (thread) => archiveThread(liveThread(thread)), | 839 | | - confirmDeleteThread: (thread) => confirmDeleteThread(liveThread(thread)), | 840 | | - settleThread: (thread) => settleThread(liveThread(thread)), | 841 | | - snoozeThread: (thread, snoozedUntil) => snoozeThread(liveThread(thread), snoozedUntil), | 842 | | - unsnoozeThread: (thread) => unsnoozeThread(liveThread(thread)), | 843 | | - unsettleThread: (thread) => unsettleThread(liveThread(thread)), | 844 | | - pinThread: (thread) => pinThread(liveThread(thread)), | 845 | | - unpinThread: (thread) => unpinThread(liveThread(thread)), | 846 | | - setThreadAutoSettle: (thread, enabled) => setThreadAutoSettle(liveThread(thread), enabled), | 847 | | - moveThread, | 848 | | - renameThread: (thread) => renameThread(liveThread(thread)), | 849 | | - regenerateThreadTitle: (thread) => regenerateThreadTitle(liveThread(thread)), | | 840 | + archiveThread: useStableCallback((thread: EnvironmentThreadShell) => | | 841 | + archiveThread(liveThread(thread)), | | 842 | + ), | | 843 | + confirmDeleteThread: useStableCallback((thread: EnvironmentThreadShell) => | | 844 | + confirmDeleteThread(liveThread(thread)), | | 845 | + ), | | 846 | + settleThread: useStableCallback((thread: EnvironmentThreadShell) => | | 847 | + settleThread(liveThread(thread)), | | 848 | + ), | | 849 | + snoozeThread: useStableCallback((thread: EnvironmentThreadShell, snoozedUntil: string) => | | 850 | + snoozeThread(liveThread(thread), snoozedUntil), | | 851 | + ), | | 852 | + unsnoozeThread: useStableCallback((thread: EnvironmentThreadShell) => | | 853 | + unsnoozeThread(liveThread(thread)), | | 854 | + ), | | 855 | + unsettleThread: useStableCallback((thread: EnvironmentThreadShell) => | | 856 | + unsettleThread(liveThread(thread)), | | 857 | + ), | | 858 | + pinThread: useStableCallback((thread: EnvironmentThreadShell) => pinThread(liveThread(thread))), | | 859 | + unpinThread: useStableCallback((thread: EnvironmentThreadShell) => | | 860 | + unpinThread(liveThread(thread)), | | 861 | + ), | | 862 | + setThreadAutoSettle: useStableCallback((thread: EnvironmentThreadShell, enabled: boolean) => | | 863 | + setThreadAutoSettle(liveThread(thread), enabled), | | 864 | + ), | | 865 | + moveThread: useStableCallback(moveThread), | | 866 | + renameThread: useStableCallback((thread: EnvironmentThreadShell) => | | 867 | + renameThread(liveThread(thread)), | | 868 | + ), | | 869 | + regenerateThreadTitle: useStableCallback((thread: EnvironmentThreadShell) => | | 870 | + regenerateThreadTitle(liveThread(thread)), | | 871 | + ), | 850 | 872 | }; | 851 | 873 | } | 852 | 874 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/layout/workspace/WorkspaceNativeTabs.ios.tsx +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -123,12 +123,12 @@ function RetainedWorkspaceTab(props: { | 123 | 123 | ); | 124 | 124 | return () => cancelAnimationFrame(frame); | 125 | 125 | }, [headerOnly, optionsByRoute, slot, setPrewarmRequests]); | | 126 | + // Built apart from the providers: a header option write re-renders their readers, not the tab. | | 127 | + const body = content ? content.children(content.workspace, content.headerOnly) : null; | 126 | 128 | return content ? ( | 127 | 129 | <NativeWorkspaceTabActivityContext value={activity}> | 128 | 130 | <WorkspaceSlotOptionsContext value={slotOptions}> | 129 | | - <WorkspaceTabsContext value={content.workspace}> | 130 | | - {content.children(content.workspace, content.headerOnly)} | 131 | | - </WorkspaceTabsContext> | | 131 | + <WorkspaceTabsContext value={content.workspace}>{body}</WorkspaceTabsContext> | 132 | 132 | </WorkspaceSlotOptionsContext> | 133 | 133 | </NativeWorkspaceTabActivityContext> | 134 | 134 | ) : null; | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/pull-requests/PullRequestFiles.tsx +11-13Lines changed: 11 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,7 @@ import { AnimatedLegendList } from "@legendapp/list/reanimated"; | 4 | 4 | import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native"; | 5 | 5 | import type { PullRequestChangeBreakdown } from "@t3tools/contracts"; | 6 | 6 | import { msg, T, useGT, useMessages, Var } from "gt-react-native"; | 7 | | -import { useState } from "react"; | | 7 | +import { memo, useState } from "react"; | 8 | 8 | import { View } from "react-native"; | 9 | 9 | import Animated from "react-native-reanimated"; | 10 | 10 | import { PierreEntryIcon } from "../../components/PierreEntryIcon"; | @@ -108,12 +108,13 @@ function describeFiles( | 108 | 108 | .join(" · "); | 109 | 109 | } | 110 | 110 |
| 111 | | -function FileRow(props: { | | 111 | +// Memoized: a pull request's rows rebuild as its detail, diff and viewed reads land. | | 112 | +const FileRow = memo(function FileRow(props: { | 112 | 113 | readonly file: ReviewRenderableFile; | 113 | 114 | readonly viewed: boolean; | 114 | 115 | /** Shown under the file name where files aren't grouped by directory. */ | 115 | 116 | readonly directory?: string; | 116 | | - readonly onPress: () => void; | | 117 | + readonly onPress: (path: string) => void; | 117 | 118 | }) { | 118 | 119 | const { file } = props; | 119 | 120 | const gt = useGT(); | @@ -126,7 +127,7 @@ function FileRow(props: { | 126 | 127 | ? gt("View diff for {path}, {additions} additions, {deletions} deletions, viewed", values) | 127 | 128 | : gt("View diff for {path}, {additions} additions, {deletions} deletions", values) | 128 | 129 | } | 129 | | - onPress={props.onPress} | | 130 | + onPress={() => props.onPress(file.path)} | 130 | 131 | className="min-h-14 flex-row items-center gap-3 border-b border-border-subtle py-3 active:opacity-70" | 131 | 132 | > | 132 | 133 | <PierreEntryIcon kind="file" path={file.path} size={20} /> | @@ -158,7 +159,7 @@ function FileRow(props: { | 158 | 159 | <SymbolView name="chevron.right" size={12} tintColorClassName="accent-icon-muted" /> | 159 | 160 | </RowPressable> | 160 | 161 | ); | 161 | | -} | | 162 | +}); | 162 | 163 |
| 163 | 164 | function FileRowSkeleton(props: { readonly index: number }) { | 164 | 165 | return ( | @@ -289,6 +290,7 @@ export function usePullRequestFilesSection(params: PullRequestParams) { | 289 | 290 | composerPullRequests.changeBreakdown(pullRequestTarget(params)), | 290 | 291 | ).data; | 291 | 292 | const expected = pr ?? params.initialSummary; | | 293 | + const openFile = (path: string) => navigation.navigate("PullRequestFile", { ...params, path }); | 292 | 294 | return { | 293 | 295 | refresh: diff.refresh, | 294 | 296 | header: ( | @@ -363,7 +365,7 @@ export function usePullRequestFilesSection(params: PullRequestParams) { | 363 | 365 | file={file} | 364 | 366 | directory={fileDirectory(file.path)} | 365 | 367 | viewed={viewed.isViewed(file.path)} | 366 | | - onPress={() => navigation.navigate("PullRequestFile", { ...params, path: file.path })} | | 368 | + onPress={openFile} | 367 | 369 | /> | 368 | 370 | ), | 369 | 371 | })), | @@ -461,14 +463,10 @@ export function PullRequestFilesSheet({ route }: StaticScreenProps<PullRequestDi | 461 | 463 | <FileRow | 462 | 464 | file={item.file} | 463 | 465 | viewed={viewed.isViewed(item.file.path)} | 464 | | - onPress={() => { | 465 | | - requestPullRequestFileJump(navigation.getState()?.routes ?? [], item.file.path); | | 466 | + onPress={(path) => { | | 467 | + requestPullRequestFileJump(navigation.getState()?.routes ?? [], path); | 466 | 468 | navigation.dispatch( | 467 | | - StackActions.popTo("PullRequestFile", { | 468 | | - ...params, | 469 | | - path: item.file.path, | 470 | | - focus: undefined, | 471 | | - }), | | 469 | + StackActions.popTo("PullRequestFile", { ...params, path, focus: undefined }), | 472 | 470 | ); | 473 | 471 | }} | 474 | 472 | /> | |
|