GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(mobile): thread switches commit less and show their rows sooner … · patroza/t3code@2ae7315

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/mobile
    • src
      • features
        • browser
          • ThreadBrowserFloat.tsx
        • home
          • useThreadListActions.test.ts
          • useThreadListActions.ts
        • layout/workspace
          • WorkspaceNativeTabs.ios.tsx
        • pull-requests
          • PullRequestFiles.tsx
          • PullRequestRouteScreen.tsx
        • threads
          • ThreadDetailScreen.tsx
          • ThreadRouteScreen.tsx
          • ThreadScreenHost.test.tsx
          • ThreadScreenHost.tsx
          • threadContentPresentation.ts
      • lib
        • threadActivity.test.ts
        • threadActivity.ts
        • useStableCallback.ts
      • state
        • device.ts
        • preview.ts
    • vite.config.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/mobile/src/features/browser/ThreadBrowserFloat.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/browser/ThreadBrowserFloat.tsx
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useAppForeground } from "../../lib/appState";
1212
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
1313
import { browserTabTitle } from "./browserTabs";
1414
import { PreviewStreamWebView } from "./PreviewStreamWebView";
15+
import { useThreadServerBrowserTabs } from "../../state/preview";
1516
import { usePreparedConnection } from "../../state/session";
1617

1718
const PLAYER_LONG_SIDE = 184;
@@ -21,28 +22,30 @@ const PLAYER_EXITING = FadeOut.duration(120).reduceMotion(ReduceMotion.System);
2122
export function ThreadBrowserFloat(props: {
2223
readonly environmentId: EnvironmentId;
2324
readonly threadId: ThreadId;
24-
readonly tabs: ReadonlyArray<PreviewSessionSnapshot>;
25-
readonly loaded: boolean;
25+
/** Whether the environment serves browser tabs. */
26+
readonly enabled: boolean;
2627
readonly top: number;
2728
readonly onOpen: (tabId: string) => void;
2829
}) {
30+
// Read here rather than by the thread screen, so a list read re-renders only the float.
31+
const { tabs, loaded } = useThreadServerBrowserTabs(props);
2932
const [tabId, setTabId] = useState<string | null>(null);
3033
// The reveal requests already seen, so only a tab revealed after the first
3134
// list pops the player.
3235
const [seen, setSeen] = useState<{
3336
readonly tabs: ReadonlyArray<PreviewSessionSnapshot>;
3437
readonly reveals: ReadonlyMap<string, string | undefined>;
3538
} | null>(null);
36-
if (props.loaded && seen?.tabs !== props.tabs) {
39+
if (loaded && seen?.tabs !== tabs) {
3740
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])),
4043
});
4144
const previous = seen?.reveals;
4245
const opened =
4346
previous === undefined
4447
? undefined
45-
: props.tabs.findLast(
48+
: tabs.findLast(
4649
(tab) =>
4750
tab.reveal === true &&
4851
(tab.revealRequest
@@ -53,7 +56,7 @@ export function ThreadBrowserFloat(props: {
5356
}
5457
const focused = useIsFocused();
5558
const foreground = useAppForeground();
56-
const tab = props.tabs.find((entry) => entry.tabId === tabId) ?? null;
59+
const tab = tabs.find((entry) => entry.tabId === tabId) ?? null;
5760
const onOpen = props.onOpen;
5861
const open = () => {
5962
if (tabId === null) return;
Collapse file

‎apps/mobile/src/features/home/useThreadListActions.test.ts‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/home/useThreadListActions.test.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ vi.mock("react", () => ({
4242
useCallback: (callback: unknown) => callback,
4343
useRef: (current: unknown) => ({ current }),
4444
}));
45+
vi.mock("../../lib/useStableCallback", () => ({
46+
useStableCallback: (callback: unknown) => callback,
47+
}));
4548
vi.mock("react-native", () => ({
4649
Alert: {
4750
alert: (title: string, _message: string, buttons?: { text: string; onPress?: () => void }[]) =>
Collapse file

‎apps/mobile/src/features/home/useThreadListActions.ts‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/home/useThreadListActions.ts
+34-12Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
import { getThreadListV2OrderedSection } from "../threads/threadListV2";
4343
import { threadCanArchive } from "./threadArchive";
4444
import { resolveThreadTitleRename } from "../threads/thread-title-rename";
45+
import { useStableCallback } from "../../lib/useStableCallback";
4546

4647
function environmentConfigLoaded(environmentId: EnvironmentThreadShell["environmentId"]) {
4748
return appAtomRegistry.get(environmentServerConfigsAtom).has(environmentId);
@@ -833,20 +834,41 @@ export function useThreadListActions(): {
833834
const confirmDeleteThread = (thread: EnvironmentThreadShell) =>
834835
confirmThreadDeletion(executeAction, thread);
835836

837+
// Stable, so a list that re-renders does not re-render every row these reach.
836838
// `moveThread` looks up its own row, and refuses while a list holds older rows.
837839
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+
),
850872
};
851873
}
852874

Collapse file

‎apps/mobile/src/features/layout/workspace/WorkspaceNativeTabs.ios.tsx‎

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 numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ function RetainedWorkspaceTab(props: {
123123
);
124124
return () => cancelAnimationFrame(frame);
125125
}, [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;
126128
return content ? (
127129
<NativeWorkspaceTabActivityContext value={activity}>
128130
<WorkspaceSlotOptionsContext value={slotOptions}>
129-
<WorkspaceTabsContext value={content.workspace}>
130-
{content.children(content.workspace, content.headerOnly)}
131-
</WorkspaceTabsContext>
131+
<WorkspaceTabsContext value={content.workspace}>{body}</WorkspaceTabsContext>
132132
</WorkspaceSlotOptionsContext>
133133
</NativeWorkspaceTabActivityContext>
134134
) : null;
Collapse file

‎apps/mobile/src/features/pull-requests/PullRequestFiles.tsx‎

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 numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AnimatedLegendList } from "@legendapp/list/reanimated";
44
import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
55
import type { PullRequestChangeBreakdown } from "@t3tools/contracts";
66
import { msg, T, useGT, useMessages, Var } from "gt-react-native";
7-
import { useState } from "react";
7+
import { memo, useState } from "react";
88
import { View } from "react-native";
99
import Animated from "react-native-reanimated";
1010
import { PierreEntryIcon } from "../../components/PierreEntryIcon";
@@ -108,12 +108,13 @@ function describeFiles(
108108
.join(" · ");
109109
}
110110

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: {
112113
readonly file: ReviewRenderableFile;
113114
readonly viewed: boolean;
114115
/** Shown under the file name where files aren't grouped by directory. */
115116
readonly directory?: string;
116-
readonly onPress: () => void;
117+
readonly onPress: (path: string) => void;
117118
}) {
118119
const { file } = props;
119120
const gt = useGT();
@@ -126,7 +127,7 @@ function FileRow(props: {
126127
? gt("View diff for {path}, {additions} additions, {deletions} deletions, viewed", values)
127128
: gt("View diff for {path}, {additions} additions, {deletions} deletions", values)
128129
}
129-
onPress={props.onPress}
130+
onPress={() => props.onPress(file.path)}
130131
className="min-h-14 flex-row items-center gap-3 border-b border-border-subtle py-3 active:opacity-70"
131132
>
132133
<PierreEntryIcon kind="file" path={file.path} size={20} />
@@ -158,7 +159,7 @@ function FileRow(props: {
158159
<SymbolView name="chevron.right" size={12} tintColorClassName="accent-icon-muted" />
159160
</RowPressable>
160161
);
161-
}
162+
});
162163

163164
function FileRowSkeleton(props: { readonly index: number }) {
164165
return (
@@ -289,6 +290,7 @@ export function usePullRequestFilesSection(params: PullRequestParams) {
289290
composerPullRequests.changeBreakdown(pullRequestTarget(params)),
290291
).data;
291292
const expected = pr ?? params.initialSummary;
293+
const openFile = (path: string) => navigation.navigate("PullRequestFile", { ...params, path });
292294
return {
293295
refresh: diff.refresh,
294296
header: (
@@ -363,7 +365,7 @@ export function usePullRequestFilesSection(params: PullRequestParams) {
363365
file={file}
364366
directory={fileDirectory(file.path)}
365367
viewed={viewed.isViewed(file.path)}
366-
onPress={() => navigation.navigate("PullRequestFile", { ...params, path: file.path })}
368+
onPress={openFile}
367369
/>
368370
),
369371
})),
@@ -461,14 +463,10 @@ export function PullRequestFilesSheet({ route }: StaticScreenProps<PullRequestDi
461463
<FileRow
462464
file={item.file}
463465
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);
466468
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 }),
472470
);
473471
}}
474472
/>

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.