Skip to content
TypeScript

perf(mobile): stop menu fault logging and whole-list re-renders on Home (#24646)

Julius Marminge62eb35b163d6
diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsx
index f20a8fee636..6e83e124de4 100644
--- a/apps/mobile/src/features/home/HomeScreen.tsx
+++ b/apps/mobile/src/features/home/HomeScreen.tsx
@@ -2,7 +2,6 @@ import { useActiveNewTask } from "../../state/active-new-task";
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
import type { ThreadMoveDestination } from "../threads/threadOrder";
-import { computeThreadMoveAvailability } from "../threads/threadOrder";
import type { LegendListRef } from "@legendapp/list/react-native";
import { AnimatedLegendList } from "@legendapp/list/reanimated";
import { THREAD_SIDEBAR_ROW_LAYOUT } from "../threads/threadListAnimations";
@@ -54,6 +53,7 @@ import { useNativeWorkspaceColumnsSupported } from "../../native/NativeWorkspace
import { useThreadSearch } from "../../state/queries";
import { requestThreadMessageJump } from "../threads/threadMessageJump";
import { useThreadListSearchMatches } from "../threads/useThreadListSearchMatches";
+import { useThreadListV2 } from "../threads/useThreadListV2";
import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
import { usePendingThreadOrder } from "../../state/thread-order";
import { threadListEnvironmentsAtom } from "../../state/server";
@@ -71,11 +71,7 @@ import { useThreadRowProviderInstanceResolver } from "../threads/thread-provider
import { useOpenThreadPullRequests } from "../threads/use-open-thread-pull-requests";
import type { ThreadPrPresentation } from "../../state/thread-pr-presentation";
import {
- buildThreadListV2Items,
- getThreadListV2OrderedSection,
- buildThreadListV2ListItems,
threadListV2ListItemsAreEqual,
- threadListInboxReturns,
THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
type ThreadListV2ListItem,
@@ -300,7 +296,6 @@ export function HomeScreen(props: HomeScreenProps) {
: [];
const threadSearch = useThreadSearch(searchEnvironmentIds, props.searchQuery);
const threadSearchMatchByKey = useThreadListSearchMatches(props.threads, threadSearch);
- const matchedThreadKeys = new Set(threadSearchMatchByKey.keys());
const handleSwipeableWillOpen = (methods: SwipeableMethods) => {
if (openSwipeableRef.current !== methods) {
openSwipeableRef.current?.close();
@@ -397,14 +392,6 @@ export function HomeScreen(props: HomeScreenProps) {
),
),
);
- const v2ScopedProjectKeys =
- v2ScopedProjectGroup === null
- ? null
- : new Set(
- v2ScopedProjectGroup.projectRefs.map((projectRef) =>
- scopedProjectKey(projectRef.environmentId, projectRef.projectId),
- ),
- );
const handleSettleThread = props.onSettleThread;
const handleSnoozeThread = props.onSnoozeThread;
const handleUnsnoozeThread = props.onUnsnoozeThread;
@@ -462,54 +449,32 @@ export function HomeScreen(props: HomeScreenProps) {
} = listEnvironments;
const resolveProviderInstance = useThreadRowProviderInstanceResolver(providersByEnvironmentId);
const pendingOrder = usePendingThreadOrder(nowMinute, snoozeWakeTick);
- // Up/down menu availability for every card, computed once per section per
- // rebuild (see computeThreadMoveAvailability): per-thread planner calls made
- // list construction quadratic, and this list rebuilds on every minute tick.
- const threadMoveAvailability = (() => {
- const sectionAvailability = (section: "pinned" | "active") =>
- computeThreadMoveAvailability({
- allThreads: props.threads,
- section,
- pendingOrder,
- reorderableEnvironmentIds:
- section === "pinned" ? pinReorderEnvironmentIds : activeReorderEnvironmentIds,
- ordered: getThreadListV2OrderedSection({
- threads: props.threads,
- section,
- pendingOrder,
- now,
- settlementEnvironmentIds,
- snoozeEnvironmentIds,
- queuedThreadKeys,
- }),
- });
- return new Map([
- ...sectionAvailability("pinned"),
- ...(workingShelfEnabled ? [] : sectionAvailability("active")),
- ]);
- })();
- const threadListV2Layout = (() => {
- threadListInboxReturns.observe(workingShelfEnabled ? props.threads : null);
- return buildThreadListV2Items({
- pendingOrder,
- threads: props.threads.filter((thread) => thread.archivedAt === null),
- environmentId: props.selectedEnvironmentId,
- projectRefs: v2ScopedProjectGroup === null ? null : v2ScopedProjectGroup.projectRefs,
- searchQuery: props.searchQuery,
- matchedThreadKeys,
- settlementEnvironmentIds,
- snoozeEnvironmentIds,
- queuedThreadKeys,
- settledLimit: settledVisibleCount,
- now,
- workingShelfEnabled,
- workingShelfExpanded,
- inboxReturnAt: threadListInboxReturns.returnedAt,
- snoozedShelfExpanded,
- settledShelfExpanded,
- selectedThreadKey,
- });
- })();
+ const {
+ layout: threadListV2Layout,
+ items: threadListV2Items,
+ contentOnlyThreadKeys,
+ } = useThreadListV2({
+ threads: props.threads,
+ pendingTasks: props.pendingTasks,
+ environmentId: props.selectedEnvironmentId,
+ projectRefs: v2ScopedProjectGroup === null ? null : v2ScopedProjectGroup.projectRefs,
+ searchQuery: props.searchQuery,
+ searchMatches: threadSearchMatchByKey,
+ settlementEnvironmentIds,
+ snoozeEnvironmentIds,
+ pinReorderEnvironmentIds,
+ activeReorderEnvironmentIds,
+ queuedThreadKeys,
+ settledLimit: settledVisibleCount,
+ now,
+ pendingOrder,
+ shelfPreferencesLoaded,
+ workingShelfEnabled,
+ workingShelfExpanded,
+ snoozedShelfExpanded,
+ settledShelfExpanded,
+ selectedThreadKey,
+ });
const nextSnoozeWakeAt = threadListV2Layout.nextSnoozeWakeAt;
useEffect(() => {
if (nextSnoozeWakeAt === null) return;
@@ -525,47 +490,20 @@ export function HomeScreen(props: HomeScreenProps) {
// unchanged: after a clamped fire (wake beyond the 32-bit setTimeout
// range) the boundary string is identical and the chain would die.
}, [nextSnoozeWakeAt, snoozeWakeTick]);
- const v2SearchQuery = props.searchQuery.trim().toLocaleLowerCase();
- const v2PendingTasks = props.pendingTasks.filter(
- (pendingTask) =>
- (props.selectedEnvironmentId === null ||
- pendingTask.environmentId === props.selectedEnvironmentId) &&
- (v2ScopedProjectKeys === null ||
- v2ScopedProjectKeys.has(
- scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
- )) &&
- (v2SearchQuery.length === 0 || pendingTask.title.toLocaleLowerCase().includes(v2SearchQuery)),
- );
- const threadListV2Items = buildThreadListV2ListItems({
- items: threadListV2Layout.items,
- pendingTasks: v2PendingTasks,
- workingCount: threadListV2Layout.workingCount,
- workingShelfExpanded,
- workingShelfHeaderIndex: threadListV2Layout.workingShelfHeaderIndex,
- snoozedCount: threadListV2Layout.snoozedCount,
- snoozedShelfExpanded,
- snoozedShelfHeaderIndex: threadListV2Layout.snoozedShelfHeaderIndex,
- settledCount: threadListV2Layout.settledCount,
- settledShelfExpanded,
- settledShelfHeaderIndex: threadListV2Layout.settledShelfHeaderIndex,
- snoozeLabelNow: `${nowMinute}:00.000Z`,
- snoozeEnvironmentIds,
- queuedThreadKeys,
- moveAvailability: threadMoveAvailability,
- shelfPreferencesLoading: !shelfPreferencesLoaded,
- });
-
+ // Called as `props.onSelectThread(...)`, the compiler would cache this handler on the whole
+ // props object, which is new on every render of Home's parent.
+ const { onSelectThread } = props;
// A row listed for a message match opens the thread at that message, by
// tap or by shortcut.
const selectThread = (thread: EnvironmentThreadShell) => {
const key = threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id });
- const messageId = threadListV2Layout.contentOnlyThreadKeys.has(key)
+ const messageId = contentOnlyThreadKeys.has(key)
? threadSearchMatchByKey.get(key)?.messageId
: undefined;
if (messageId) {
requestThreadMessageJump(scopedThreadKey(thread.environmentId, thread.id), messageId);
}
- props.onSelectThread(thread);
+ onSelectThread(thread);
};
useThreadJumpShortcuts(threadListV2Items, selectThread);
useEffect(() => {
@@ -670,7 +608,7 @@ export function HomeScreen(props: HomeScreenProps) {
environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
searchMatch={
// Only rows listed for their messages show one and open at it.
- threadListV2Layout.contentOnlyThreadKeys.has(
+ contentOnlyThreadKeys.has(
threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id }),
)
? threadSearchMatchByKey.get(
diff --git a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
index 13ce478929d..3462c8ae885 100644
--- a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
+++ b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx
@@ -3,7 +3,6 @@ import { ThreadUndoNotice } from "../home/ThreadUndoNotice";
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
import { resolveScratchProjectScopeKey } from "@t3tools/client-runtime/state/project-grouping";
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
-import { computeThreadMoveAvailability } from "./threadOrder";
import type {
EnvironmentProject,
EnvironmentThreadShell,
@@ -41,6 +40,7 @@ import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
import { useWorkspaceState } from "../../state/workspace";
import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";
+import { useThreadListV2 } from "./useThreadListV2";
import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
import { requestThreadMessageJump } from "./threadMessageJump";
import { useThreadListSearchMatches } from "./useThreadListSearchMatches";
@@ -72,12 +72,8 @@ import {
import { useThreadRowProviderInstanceResolver } from "./thread-provider-instance";
import type { ThreadPrPresentation } from "../../state/thread-pr-presentation";
import {
- buildThreadListV2Items,
- getThreadListV2OrderedSection,
- buildThreadListV2ListItems,
isThreadListV2ListItem,
threadListV2ListItemsAreEqual,
- threadListInboxReturns,
THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
type ThreadListV2ListItem,
@@ -190,7 +186,6 @@ function ThreadNavigationSidebarPane(
// This map reaches LegendList's extraData, which re-renders every row whenever it changes
// identity; the hook keeps it stable.
const threadSearchMatchByKey = useThreadListSearchMatches(threads, threadSearch);
- const matchedThreadKeys = new Set(threadSearchMatchByKey.keys());
const projectScopeKey = options.selectedProjectKey;
const resolvedProjectKey = resolveScratchProjectScopeKey(projectScopeKey, projects, {
sidebarProjectGroupingMode: options.projectGroupingMode,
@@ -232,14 +227,6 @@ function ThreadNavigationSidebarPane(
const selectedProjectScope =
projectScopes.find((scope) => scope.key === resolvedProjectKey) ?? null;
const selectedProjectKey = selectedProjectScope?.key ?? null;
- const selectedProjectRefs =
- selectedProjectScope === null
- ? null
- : new Set(
- selectedProjectScope.projectRefs.map((projectRef) =>
- scopedProjectKey(projectRef.environmentId, projectRef.projectId),
- ),
- );
const projectByKey = useMemo(() => {
const map = new Map<string, EnvironmentProject>();
for (const project of projects) {
@@ -294,54 +281,32 @@ function ThreadNavigationSidebarPane(
} = listEnvironments;
const resolveProviderInstance = useThreadRowProviderInstanceResolver(providersByEnvironmentId);
const pendingOrder = usePendingThreadOrder(nowMinute, snoozeWakeTick);
- // Up/down menu availability for every card, computed once per section per
- // rebuild (see computeThreadMoveAvailability): per-thread planner calls made
- // list construction quadratic, and this list rebuilds on every minute tick.
- const threadMoveAvailability = (() => {
- const sectionAvailability = (section: "pinned" | "active") =>
- computeThreadMoveAvailability({
- allThreads: threads,
- section,
- pendingOrder,
- reorderableEnvironmentIds:
- section === "pinned" ? pinReorderEnvironmentIds : activeReorderEnvironmentIds,
- ordered: getThreadListV2OrderedSection({
- threads,
- section,
- pendingOrder,
- now,
- settlementEnvironmentIds,
- snoozeEnvironmentIds,
- queuedThreadKeys,
- }),
- });
- return new Map([
- ...sectionAvailability("pinned"),
- ...(workingShelfEnabled ? [] : sectionAvailability("active")),
- ]);
- })();
- const threadListV2Layout = (() => {
- threadListInboxReturns.observe(workingShelfEnabled ? threads : null);
- return buildThreadListV2Items({
- pendingOrder,
- threads: threads.filter((thread) => thread.archivedAt === null),
- environmentId: options.selectedEnvironmentId,
- projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs,
- searchQuery: props.searchQuery,
- matchedThreadKeys,
- settlementEnvironmentIds,
- snoozeEnvironmentIds,
- queuedThreadKeys,
- settledLimit: settledVisibleCount,
- now,
- workingShelfEnabled,
- workingShelfExpanded,
- inboxReturnAt: threadListInboxReturns.returnedAt,
- snoozedShelfExpanded,
- settledShelfExpanded,
- selectedThreadKey: props.selectedThreadKey ?? null,
- });
- })();
+ const {
+ layout: threadListV2Layout,
+ items: threadListV2Items,
+ contentOnlyThreadKeys,
+ } = useThreadListV2({
+ threads,
+ pendingTasks,
+ environmentId: options.selectedEnvironmentId,
+ projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs,
+ searchQuery: props.searchQuery,
+ searchMatches: threadSearchMatchByKey,
+ settlementEnvironmentIds,
+ snoozeEnvironmentIds,
+ pinReorderEnvironmentIds,
+ activeReorderEnvironmentIds,
+ queuedThreadKeys,
+ settledLimit: settledVisibleCount,
+ now,
+ pendingOrder,
+ shelfPreferencesLoaded,
+ workingShelfEnabled,
+ workingShelfExpanded,
+ snoozedShelfExpanded,
+ settledShelfExpanded,
+ selectedThreadKey: props.selectedThreadKey ?? null,
+ });
const nextSnoozeWakeAt = threadListV2Layout.nextSnoozeWakeAt;
useEffect(() => {
if (nextSnoozeWakeAt === null) return;
@@ -357,46 +322,17 @@ function ThreadNavigationSidebarPane(
// unchanged: after a clamped fire (wake beyond the 32-bit setTimeout
// range) the boundary string is identical and the chain would die.
}, [nextSnoozeWakeAt, snoozeWakeTick]);
- const listItems = ((): readonly SidebarListItem[] => {
- const v2SearchQuery = props.searchQuery.trim().toLocaleLowerCase();
- const v2PendingTasks = pendingTasks.filter(
- (pendingTask) =>
- (options.selectedEnvironmentId === null ||
- pendingTask.environmentId === options.selectedEnvironmentId) &&
- (selectedProjectRefs === null ||
- selectedProjectRefs.has(
- scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
- )) &&
- (v2SearchQuery.length === 0 ||
- pendingTask.title.toLocaleLowerCase().includes(v2SearchQuery)),
- );
- const items: SidebarListItem[] = buildThreadListV2ListItems({
- items: threadListV2Layout.items,
- pendingTasks: v2PendingTasks,
- workingCount: threadListV2Layout.workingCount,
- workingShelfExpanded,
- workingShelfHeaderIndex: threadListV2Layout.workingShelfHeaderIndex,
- snoozedCount: threadListV2Layout.snoozedCount,
- snoozedShelfExpanded,
- snoozedShelfHeaderIndex: threadListV2Layout.snoozedShelfHeaderIndex,
- settledCount: threadListV2Layout.settledCount,
- settledShelfExpanded,
- settledShelfHeaderIndex: threadListV2Layout.settledShelfHeaderIndex,
- snoozeLabelNow: `${nowMinute}:00.000Z`,
- snoozeEnvironmentIds,
- queuedThreadKeys,
- moveAvailability: threadMoveAvailability,
- shelfPreferencesLoading: !shelfPreferencesLoaded,
- });
- if (settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0) {
- items.push({
- type: "v2-show-more",
- key: "v2-show-more",
- hiddenCount: threadListV2Layout.hiddenSettledCount,
- });
- }
- return items;
- })();
+ const listItems: readonly SidebarListItem[] =
+ settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0
+ ? [
+ ...threadListV2Items,
+ {
+ type: "v2-show-more",
+ key: "v2-show-more",
+ hiddenCount: threadListV2Layout.hiddenSettledCount,
+ },
+ ]
+ : threadListV2Items;
const listMenuActions = [
{
id: "environment",
@@ -503,7 +439,7 @@ function ThreadNavigationSidebarPane(
// tap or by shortcut.
const handleSelectThread = (thread: EnvironmentThreadShell) => {
const key = threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id });
- const messageId = threadListV2Layout.contentOnlyThreadKeys.has(key)
+ const messageId = contentOnlyThreadKeys.has(key)
? threadSearchMatchByKey.get(key)?.messageId
: undefined;
if (messageId) {
@@ -634,7 +570,7 @@ function ThreadNavigationSidebarPane(
environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
searchMatch={
// Only rows listed for their messages show one and open at it.
- threadListV2Layout.contentOnlyThreadKeys.has(
+ contentOnlyThreadKeys.has(
threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id }),
)
? threadSearchMatchByKey.get(
diff --git a/apps/mobile/src/features/threads/useThreadListV2.ts b/apps/mobile/src/features/threads/useThreadListV2.ts
new file mode 100644
index 00000000000..12d861d193a
--- /dev/null
+++ b/apps/mobile/src/features/threads/useThreadListV2.ts
@@ -0,0 +1,139 @@
+import type { EnvironmentId } from "@t3tools/contracts";
+import { useMemo } from "react";
+
+import { scopedProjectKey } from "../../lib/scopedEntities";
+import type { PendingNewTask } from "../../state/use-pending-new-tasks";
+import {
+ buildThreadListV2Items,
+ buildThreadListV2ListItems,
+ getThreadListV2OrderedSection,
+ threadListInboxReturns,
+} from "./threadListV2";
+import { computeThreadMoveAvailability } from "./threadOrder";
+
+/**
+ * Screens' select handlers read the content-only key set; a fresh one per list rebuild gave
+ * every row a new handler whenever any thread shell changed. Keyed by a string, the set keeps
+ * its identity until its keys change.
+ */
+function useKeySet(newlineSeparatedKeys: string): ReadonlySet<string> {
+ return useMemo(
+ () => new Set(newlineSeparatedKeys.length === 0 ? [] : newlineSeparatedKeys.split("\n")),
+ [newlineSeparatedKeys],
+ );
+}
+
+type LayoutInput = Parameters<typeof buildThreadListV2Items>[0];
+
+/**
+ * Home's and the thread sidebar's thread list. Its result is one value a screen only reads:
+ * built inline, the list's inputs stayed open to mutation across the screen's other hooks, so
+ * the React Compiler cached none of it and every render of the screen re-rendered every row.
+ */
+export function useThreadListV2(input: {
+ readonly threads: LayoutInput["threads"];
+ readonly pendingTasks: ReadonlyArray<PendingNewTask>;
+ readonly environmentId: EnvironmentId | null;
+ readonly projectRefs: LayoutInput["projectRefs"];
+ readonly searchQuery: string;
+ /** Threads that match the search by content, keyed like `threadSearchMatchKey`. */
+ readonly searchMatches: ReadonlyMap<string, unknown>;
+ readonly settlementEnvironmentIds: ReadonlySet<EnvironmentId>;
+ readonly snoozeEnvironmentIds: ReadonlySet<EnvironmentId>;
+ readonly pinReorderEnvironmentIds: ReadonlySet<EnvironmentId>;
+ readonly activeReorderEnvironmentIds: ReadonlySet<EnvironmentId>;
+ readonly queuedThreadKeys: ReadonlySet<string>;
+ readonly settledLimit: number;
+ readonly now: string;
+ readonly pendingOrder: LayoutInput["pendingOrder"];
+ readonly shelfPreferencesLoaded: boolean;
+ readonly workingShelfEnabled: boolean;
+ readonly workingShelfExpanded: boolean;
+ readonly snoozedShelfExpanded: boolean;
+ readonly settledShelfExpanded: boolean;
+ readonly selectedThreadKey: string | null;
+}) {
+ const { threads, workingShelfEnabled } = input;
+ // Observed once per change to the threads: that is when a thread can stop working.
+ const inboxReturnAt = useMemo(
+ () => threadListInboxReturns.observe(workingShelfEnabled ? threads : null),
+ [threads, workingShelfEnabled],
+ );
+ // Up/down menu availability for every card, computed once per section per
+ // rebuild (see computeThreadMoveAvailability): per-thread planner calls made
+ // list construction quadratic, and this list rebuilds on every minute tick.
+ const sectionAvailability = (section: "pinned" | "active") =>
+ computeThreadMoveAvailability({
+ allThreads: threads,
+ section,
+ pendingOrder: input.pendingOrder,
+ reorderableEnvironmentIds:
+ section === "pinned" ? input.pinReorderEnvironmentIds : input.activeReorderEnvironmentIds,
+ ordered: getThreadListV2OrderedSection({
+ threads,
+ section,
+ pendingOrder: input.pendingOrder,
+ now: input.now,
+ settlementEnvironmentIds: input.settlementEnvironmentIds,
+ snoozeEnvironmentIds: input.snoozeEnvironmentIds,
+ queuedThreadKeys: input.queuedThreadKeys,
+ }),
+ });
+ const moveAvailability = new Map([
+ ...sectionAvailability("pinned"),
+ ...(workingShelfEnabled ? [] : sectionAvailability("active")),
+ ]);
+ const layout = buildThreadListV2Items({
+ pendingOrder: input.pendingOrder,
+ threads: threads.filter((thread) => thread.archivedAt === null),
+ environmentId: input.environmentId,
+ projectRefs: input.projectRefs,
+ searchQuery: input.searchQuery,
+ matchedThreadKeys: new Set(input.searchMatches.keys()),
+ settlementEnvironmentIds: input.settlementEnvironmentIds,
+ snoozeEnvironmentIds: input.snoozeEnvironmentIds,
+ queuedThreadKeys: input.queuedThreadKeys,
+ settledLimit: input.settledLimit,
+ now: input.now,
+ workingShelfEnabled,
+ workingShelfExpanded: input.workingShelfExpanded,
+ inboxReturnAt,
+ snoozedShelfExpanded: input.snoozedShelfExpanded,
+ settledShelfExpanded: input.settledShelfExpanded,
+ selectedThreadKey: input.selectedThreadKey,
+ });
+ const contentOnlyThreadKeys = useKeySet([...layout.contentOnlyThreadKeys].sort().join("\n"));
+ const scopedProjectKeys =
+ input.projectRefs == null
+ ? null
+ : new Set(input.projectRefs.map((ref) => scopedProjectKey(ref.environmentId, ref.projectId)));
+ const searchQuery = input.searchQuery.trim().toLocaleLowerCase();
+ const pendingTasks = input.pendingTasks.filter(
+ (pendingTask) =>
+ (input.environmentId === null || pendingTask.environmentId === input.environmentId) &&
+ (scopedProjectKeys === null ||
+ scopedProjectKeys.has(
+ scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
+ )) &&
+ (searchQuery.length === 0 || pendingTask.title.toLocaleLowerCase().includes(searchQuery)),
+ );
+ const items = buildThreadListV2ListItems({
+ items: layout.items,
+ pendingTasks,
+ workingCount: layout.workingCount,
+ workingShelfExpanded: input.workingShelfExpanded,
+ workingShelfHeaderIndex: layout.workingShelfHeaderIndex,
+ snoozedCount: layout.snoozedCount,
+ snoozedShelfExpanded: input.snoozedShelfExpanded,
+ snoozedShelfHeaderIndex: layout.snoozedShelfHeaderIndex,
+ settledCount: layout.settledCount,
+ settledShelfExpanded: input.settledShelfExpanded,
+ settledShelfHeaderIndex: layout.settledShelfHeaderIndex,
+ snoozeLabelNow: `${input.now.slice(0, 16)}:00.000Z`,
+ snoozeEnvironmentIds: input.snoozeEnvironmentIds,
+ queuedThreadKeys: input.queuedThreadKeys,
+ moveAvailability,
+ shelfPreferencesLoading: !input.shelfPreferencesLoaded,
+ });
+ return { layout, items, contentOnlyThreadKeys };
+}
diff --git a/packages/client-runtime/src/state/threadInbox.test.ts b/packages/client-runtime/src/state/threadInbox.test.ts
index 86516983a2f..f5675d3a72e 100644
--- a/packages/client-runtime/src/state/threadInbox.test.ts
+++ b/packages/client-runtime/src/state/threadInbox.test.ts
@@ -32,13 +32,16 @@ function thread(id: string, working: boolean) {
describe("createInboxReturnTracker", () => {
it("stamps a thread when it stops working, but never on the first observation", () => {
const tracker = createInboxReturnTracker();
- tracker.observe([thread("a", true), thread("b", false)]);
- expect(tracker.returnedAt(thread("a", true))).toBeUndefined();
- expect(tracker.returnedAt(thread("b", false))).toBeUndefined();
+ const first = tracker.observe([thread("a", true), thread("b", false)]);
+ expect(first(thread("a", true))).toBeUndefined();
+ expect(first(thread("b", false))).toBeUndefined();
- tracker.observe([thread("a", false), thread("b", false)]);
- expect(tracker.returnedAt(thread("a", false))).toBeDefined();
- expect(tracker.returnedAt(thread("b", false))).toBeUndefined();
+ const second = tracker.observe([thread("a", false), thread("b", false)]);
+ expect(second(thread("a", false))).toBeDefined();
+ expect(second(thread("b", false))).toBeUndefined();
+ expect(tracker.returnedAt(thread("a", false))).toBe(second(thread("a", false)));
+ // An earlier observation keeps its answer, so lists built from it stay valid.
+ expect(first(thread("a", false))).toBeUndefined();
});
});
diff --git a/packages/client-runtime/src/state/threadInbox.ts b/packages/client-runtime/src/state/threadInbox.ts
index 880e6ebf31a..8083dd04538 100644
--- a/packages/client-runtime/src/state/threadInbox.ts
+++ b/packages/client-runtime/src/state/threadInbox.ts
@@ -88,8 +88,9 @@ function sortNewestFirst<T extends Pick<EnvironmentThreadShell, "id" | "environm
/**
* Keep one at module scope so the inbox order survives routes that unmount the
- * list. Call `observe` with every thread shell on each list rebuild, or with
- * null to reset while the beta is off.
+ * list. Call `observe` with every thread shell whenever the shells change, or
+ * with null to reset while the beta is off. It returns the return times as of
+ * that observation, which stay fixed so a list built from them can be cached.
*/
export function createInboxReturnTracker() {
const keyOf = (thread: Pick<EnvironmentThreadShell, "environmentId" | "id">) =>
@@ -97,11 +98,13 @@ export function createInboxReturnTracker() {
let lastWorkingKeys: ReadonlySet<string> | null = null;
const returns = new Map<string, number>();
return {
- observe(threads: ReadonlyArray<WorkingThreadInput & InboxThreadInput> | null): void {
+ observe(
+ threads: ReadonlyArray<WorkingThreadInput & InboxThreadInput> | null,
+ ): (thread: Pick<EnvironmentThreadShell, "environmentId" | "id">) => number | undefined {
if (threads === null) {
lastWorkingKeys = null;
returns.clear();
- return;
+ return () => undefined;
}
const working = new Set<string>();
const present = new Set<string>();
@@ -119,6 +122,8 @@ export function createInboxReturnTracker() {
if (present.has(key) && !working.has(key)) returns.set(key, at);
}
lastWorkingKeys = working;
+ const observed = new Map(returns);
+ return (thread) => observed.get(keyOf(thread));
},
returnedAt: (thread: Pick<EnvironmentThreadShell, "environmentId" | "id">) =>
returns.get(keyOf(thread)),
diff --git a/patches/@[email protected] b/patches/@[email protected]
index 5e2071dca0b..a96e172c098 100644
--- a/patches/@[email protected]
+++ b/patches/@[email protected]
@@ -343,10 +343,21 @@ index 5c4e0da4292b15d3a27b5ea1555f11452a470815..475a99b2a3b1800c9d3e3e5f77a64f55
+ }
}
diff --git a/ios/Shared/RCTMenuItem.swift b/ios/Shared/RCTMenuItem.swift
-index bb6bb2b7ad56135089f267587c974b166760539d..949b3f7ec49af7ba26d966a8923a51f619443d5a 100644
+index bb6bb2b7ad56135089f267587c974b166760539d..5675067ecb2db0239b74c66ff2e095471a721699 100644
--- a/ios/Shared/RCTMenuItem.swift
+++ b/ios/Shared/RCTMenuItem.swift
-@@ -103,10 +103,18 @@ class RCTMenuAction {
+@@ -27,7 +27,9 @@ class RCTMenuAction {
+ self.identifier = UIAction.Identifier(rawValue: identifier as String);
+ }
+
+- if let image = details["image"] as? NSString {
++ // Fabric sends an absent image as "", and every asset lookup for "" logs a
++ // CoreUI fault with a backtrace.
++ if let image = details["image"] as? NSString, image.length > 0 {
+ self.image = UIImage(systemName: image as String);
+ if self.image === nil {
+ self.image = UIImage(named: image as String)
+@@ -103,10 +105,18 @@ class RCTMenuAction {
subMenuActions.append(subaction.createUIMenuElement(handler))
}
var menu: UIMenu;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 10d7746c90e..75a04ae377e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -356,7 +356,7 @@ patchedDependencies:
'@muse-code/[email protected]': 7b495b607fc5d76b444c7c4d58821e839726a30e6f3c53564f0d59f2d5b42101
'@pierre/[email protected]': 2ec81ba1e8ce4681095a3473c2bf78e630417740c622720ef624febb467c25fc
'@react-native-ai/[email protected]': 2d09870c2848d185cb05b53ed823a46e12dba519324d8dd8e584e28731990f9d
- '@react-native-menu/[email protected]': a4866ecfcd44f318043de839d20110c17e14909004900f002ffe12050376f2ba
+ '@react-native-menu/[email protected]': 910ec1bf22aa85a96fcf12299cd823bc30f702dd9b2d77b564d10b9ed709f7f6
'@react-navigation/[email protected]': 990d575444c4af2ce8218b3b7a8280fe244c03abbdb32b822a2e862f791dbf42
[email protected]: bea1b6c0c0b23157fd5f439a1d7feff430f28ac1621ba135d8a13eeec60ccacd
[email protected]: a28c2dfcfc2b90d6c6247e199e6537391db9ecd941854c650910d607442512d3
@@ -550,7 +550,7 @@ importers:
'@react-native-menu/menu':
specifier: 2.0.0
'@react-navigation/elements':
specifier: 2.9.45
version: 2.9.45(d8845bac868f4d8a58c8a8f12ad0d4a5)
@@ -15465,7 +15465,7 @@ snapshots:
optional: true
dependencies:
react: 19.3.0