Skip to content

Commit c18aa12

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-11929
2 parents a568caa + 0232932 commit c18aa12

50 files changed

Lines changed: 1682 additions & 1678 deletions

Some content is hidden

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

‎.github/workflows/deploy-relay.yml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ on:
55
branches:
66
- main
77
# Redeploys main after a variable or secret change. Alchemy redeploys the
8-
# Worker when a value it reads changes, so force is rarely needed, and it
9-
# replaces the Postgres runtime role (alchemy-run/alchemy#1832).
8+
# Worker when a value it reads changes, so force is rarely needed.
109
workflow_dispatch:
1110
inputs:
1211
force:
13-
description: Redeploy every resource, including ones with no detected changes. Replaces the Postgres runtime role.
12+
description: Redeploy every resource, including ones with no detected changes.
1413
type: boolean
1514
default: false
1615

‎apps/mobile/src/App.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import { OverlayPortalHost } from "./components/ui/OverlayPortal";
5252
import { shouldHandleAppLink, restoreDraftLinkState } from "./lib/appLinking";
5353
import { hasCloudPublicConfig } from "./features/cloud/publicConfig";
5454
import { takeScheduledTaskNewLink } from "./features/settings/scheduled-task-editor-state";
55-
import { startDevAutoConnect } from "./features/connection/devAutoConnect";
55+
import { pairingFormLinkAction, startDevAutoConnect } from "./features/connection/devAutoConnect";
5656
import {
5757
resolvePendingNewTaskPromptLink,
5858
takeNewTaskPromptLink,
@@ -129,6 +129,10 @@ const appLinking = {
129129
): ReturnType<typeof getActionFromState> =>
130130
// Our router handles the selection; React Navigation's type only lists its own actions.
131131
(workspaceDetailLinkAction(state) as ReturnType<typeof getActionFromState>) ??
132+
pairingFormLinkAction(
133+
state,
134+
rootNavigationRef.isReady() ? rootNavigationRef.getRootState() : undefined,
135+
) ??
132136
getActionFromState(state, options),
133137
getStateFromPath: getAppStateFromPath,
134138
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import type { ReactNode } from "react";
2+
import { act, Profiler } from "react";
3+
import { createRoot } from "react-dom/client";
4+
import { expect, it, vi } from "vite-plus/test";
5+
6+
const harness = vi.hoisted(() => ({
7+
Passthrough: ({ children }: { children?: unknown }) => children,
8+
}));
9+
10+
vi.mock("react-native", () => ({ View: harness.Passthrough }));
11+
vi.mock("expo-image", () => ({ Image: () => <img alt="" /> }));
12+
vi.mock("./ui/AppSymbol", () => ({ SymbolView: () => null }));
13+
vi.mock("./ui/AppText", () => ({
14+
AppText: ({ children }: { children?: ReactNode }) => <span>{children}</span>,
15+
}));
16+
vi.mock("../state/assets", async () => {
17+
const { Atom } = await import("effect/reactivity");
18+
const url = Atom.make<string | null>("https://example.test/favicon.png");
19+
return { projectFaviconUrlAtom: () => url };
20+
});
21+
22+
import { EnvironmentId } from "@t3tools/contracts";
23+
24+
import { ProjectFavicon } from "./ProjectFavicon";
25+
26+
it("mounts the favicon image in the first commit", async () => {
27+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
28+
const container = document.createElement("div");
29+
const root = createRoot(container);
30+
const commits: string[] = [];
31+
try {
32+
await act(async () =>
33+
root.render(
34+
<Profiler id="favicon" onRender={(_id, phase) => commits.push(phase)}>
35+
<ProjectFavicon
36+
environmentId={EnvironmentId.make("env-1")}
37+
projectTitle="Project"
38+
workspaceRoot="/repo"
39+
/>
40+
</Profiler>,
41+
),
42+
);
43+
expect(container.querySelector("img")).not.toBeNull();
44+
expect(commits).toEqual(["mount"]);
45+
} finally {
46+
await act(async () => root.unmount());
47+
}
48+
});

‎apps/mobile/src/components/ProjectFavicon.tsx‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,11 @@ function ProjectFaviconImage(props: {
163163
() => createProjectFaviconRequest(props.cacheKey, props.faviconUrl),
164164
[props.cacheKey, props.faviconUrl],
165165
);
166-
const [activeFaviconRequest, setActiveFaviconRequest] = useState<typeof faviconRequest>(null);
166+
// Registers with the module-level loader before the Image's native onLoad/onError can fire,
167+
// so stale loads for a superseded URL under the same cacheKey are ignored.
167168
useLayoutEffect(() => {
168169
if (faviconRequest === null) return;
169-
170-
const endRequest = beginProjectFaviconRequest(faviconRequest);
171-
// oxlint-disable-next-line react/set-state-in-effect -- Publishes the favicon request registered with the external loader until its cleanup runs.
172-
setActiveFaviconRequest(faviconRequest);
173-
return endRequest;
170+
return beginProjectFaviconRequest(faviconRequest);
174171
}, [faviconRequest]);
175172

176173
const [status, setStatus] = useState<"loading" | "loaded" | "error">(() =>
@@ -179,8 +176,7 @@ function ProjectFaviconImage(props: {
179176
: "loading",
180177
);
181178

182-
const requestIsActive = faviconRequest !== null && activeFaviconRequest === faviconRequest;
183-
const showImage = requestIsActive && status === "loaded";
179+
const showImage = faviconRequest !== null && status === "loaded";
184180
const fallbackGlyph = showImage ? null : projectAutoMonogram(props.projectTitle);
185181

186182
return (
@@ -203,7 +199,7 @@ function ProjectFaviconImage(props: {
203199
/>
204200
)}
205201

206-
{requestIsActive ? (
202+
{faviconRequest !== null ? (
207203
<Image
208204
key={faviconRequest.faviconUrl}
209205
source={

‎apps/mobile/src/features/connection/devAutoConnect.test.ts‎

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
import * as NodeModule from "node:module";
12
import type { NavigationState, PartialState } from "@react-navigation/native";
23
import { expect, it, vi } from "vite-plus/test";
34

5+
const requireFromNative = NodeModule.createRequire(
6+
NodeModule.createRequire(import.meta.url).resolve("@react-navigation/native/package.json"),
7+
);
8+
const requireFromCore = NodeModule.createRequire(
9+
requireFromNative.resolve("@react-navigation/core/package.json"),
10+
);
11+
const { getActionFromState, getStateFromPath } = requireFromNative("@react-navigation/core") as {
12+
readonly getActionFromState: typeof import("@react-navigation/native").getActionFromState;
13+
readonly getStateFromPath: typeof import("@react-navigation/native").getStateFromPath;
14+
};
15+
const { StackRouter } = requireFromCore("@react-navigation/routers") as {
16+
readonly StackRouter: typeof import("@react-navigation/native").StackRouter;
17+
};
18+
419
const harness = vi.hoisted(() => ({
520
pair: vi.fn(),
621
goBack: vi.fn(),
@@ -20,7 +35,12 @@ const harness = vi.hoisted(() => ({
2035
deferred: null as Array<() => void> | null,
2136
}));
2237

23-
vi.mock("@react-navigation/native", () => ({ StackActions: { replace: vi.fn() } }));
38+
vi.mock("@react-navigation/native", () => ({
39+
StackActions: { replace: vi.fn() },
40+
CommonActions: {
41+
replaceParams: (params: object) => ({ type: "REPLACE_PARAMS", payload: { params } }),
42+
},
43+
}));
2444
vi.mock("../../state/use-remote-environment-registry", () => ({
2545
pairEnvironment: harness.pair,
2646
}));
@@ -47,6 +67,7 @@ import { appAtomRegistry } from "../../state/atom-registry";
4767
import {
4868
autoConnectReport,
4969
devAutoConnectAttemptAtom,
70+
pairingFormLinkAction,
5071
startDevAutoConnect,
5172
} from "./devAutoConnect";
5273

@@ -191,3 +212,45 @@ it("a success that waited for navigation leaves a newer link's form open", async
191212
expect(harness.goBack).not.toHaveBeenCalled();
192213
expect(harness.dispatch).not.toHaveBeenCalled();
193214
});
215+
216+
it("a pairing link fills the pairing form already on screen instead of stacking a second one", () => {
217+
const linking = {
218+
initialRouteName: "Home",
219+
screens: {
220+
Home: "",
221+
Settings: "settings",
222+
SettingsEnvironmentNew: "settings/environment-new",
223+
ConnectionsNew: "connections/new",
224+
},
225+
};
226+
const router = StackRouter({});
227+
const options = {
228+
routeNames: Object.keys(linking.screens),
229+
routeParamList: {},
230+
routeGetIdList: {},
231+
};
232+
// Settings > Environments > Add environment, as the user opened it.
233+
const open = router.getRehydratedState(
234+
{
235+
index: 2,
236+
routes: [{ name: "Home" }, { name: "Settings" }, { name: "SettingsEnvironmentNew" }],
237+
},
238+
options,
239+
);
240+
const link = getStateFromPath(
241+
`connections/new?pairingUrl=${encodeURIComponent(PAIRING_URL)}`,
242+
linking,
243+
)!;
244+
const action = pairingFormLinkAction(link, open) ?? getActionFromState(link, linking)!;
245+
const next = router.getStateForAction(open, { target: open.key, ...action }, options);
246+
247+
expect(next?.routes.map((route) => route.name)).toEqual([
248+
"Home",
249+
"Settings",
250+
"SettingsEnvironmentNew",
251+
]);
252+
expect(next?.routes.at(-1)).toMatchObject({
253+
key: open.routes[2]!.key,
254+
params: { pairingUrl: PAIRING_URL },
255+
});
256+
});

‎apps/mobile/src/features/connection/devAutoConnect.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NavigationState, PartialState } from "@react-navigation/native";
2-
import { StackActions } from "@react-navigation/native";
2+
import { CommonActions, StackActions } from "@react-navigation/native";
33
import type { EnvironmentId } from "@t3tools/contracts";
44
import { Atom } from "effect/reactivity";
55

@@ -97,3 +97,22 @@ export function startDevAutoConnect(
9797
}
9898
return state;
9999
}
100+
101+
/**
102+
* A pairing link that lands on an open pairing form fills that form. React Navigation would push
103+
* `ConnectionsNew` over the Settings page's `SettingsEnvironmentNew`, stacking two copies of the
104+
* same form. The form keys on the link's pairing URL, so new params remount it with the prefill.
105+
*/
106+
export function pairingFormLinkAction(
107+
link: PartialState<NavigationState>,
108+
current: NavigationState | undefined,
109+
) {
110+
const linked = findLinkedRoute(link, PAIRING_FORM_ROUTES);
111+
const open = current?.routes[current.index];
112+
if (!linked || !current || !open || !PAIRING_FORM_ROUTES.includes(open.name)) return undefined;
113+
return {
114+
...CommonActions.replaceParams(linked.params ?? {}),
115+
source: open.key,
116+
target: current.key,
117+
};
118+
}

‎apps/mobile/src/features/home/HomeRouteScreen.tsx‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { NativePrimaryColumnContext } from "../../native/v5-workspace-context";
66
import * as Arr from "effect/Array";
77
import * as Order from "effect/Order";
88
import { useNavigation } from "@react-navigation/native";
9-
import { useCallback, useEffect, useMemo, useState } from "react";
9+
import { useCallback, useMemo, useState } from "react";
1010
import { Platform, useWindowDimensions } from "react-native";
1111

1212
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
@@ -137,16 +137,16 @@ export function HomeRouteScreen() {
137137
setSelectedProjectKey,
138138
} = useHomeListOptions(availableEnvironmentIds);
139139
const selectedEnvironmentId = listOptions.selectedEnvironmentId;
140-
const projectScopeKey = listOptions.selectedProjectKey;
141-
const resolvedProjectKey = resolveScratchProjectScopeKey(projectScopeKey, projects, {
142-
sidebarProjectGroupingMode: listOptions.projectGroupingMode,
143-
sidebarProjectGroupingOverrides: {},
144-
});
145-
useEffect(() => {
146-
if (resolvedProjectKey !== projectScopeKey) {
147-
setSelectedProjectKey(resolvedProjectKey);
148-
}
149-
}, [projectScopeKey, resolvedProjectKey, setSelectedProjectKey]);
140+
// A legacy per-environment scratch key resolves here on every render; the stored
141+
// value is only rewritten when the user picks a filter.
142+
const resolvedProjectKey = resolveScratchProjectScopeKey(
143+
listOptions.selectedProjectKey,
144+
projects,
145+
{
146+
sidebarProjectGroupingMode: listOptions.projectGroupingMode,
147+
sidebarProjectGroupingOverrides: {},
148+
},
149+
);
150150
const projectFilterOptions = useMemo(
151151
() =>
152152
buildHomeProjectScopes({

‎apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { AnimatedLegendList } from "@legendapp/list/reanimated";
1515
import { THREAD_SIDEBAR_ROW_LAYOUT } from "./threadListAnimations";
1616
import type { MenuAction } from "@react-native-menu/menu";
1717
import { useAtomValue } from "@effect/atom-react";
18-
import { useEffect, useMemo, useRef, useState } from "react";
18+
import { useMemo, useRef, useState } from "react";
1919
import type { LayoutChangeEvent, TextInputInstance } from "react-native";
2020
import { Platform, StyleSheet, TextInput, View } from "react-native";
2121
import { GestureDetector, useNativeGesture } from "react-native-gesture-handler";
@@ -198,16 +198,12 @@ function ThreadNavigationSidebarPane(
198198
)
199199
? [options.selectedEnvironmentId]
200200
: [];
201-
const projectScopeKey = options.selectedProjectKey;
202-
const resolvedProjectKey = resolveScratchProjectScopeKey(projectScopeKey, projects, {
201+
// A legacy per-environment scratch key resolves here on every render; the stored
202+
// value is only rewritten when the user picks a filter.
203+
const resolvedProjectKey = resolveScratchProjectScopeKey(options.selectedProjectKey, projects, {
203204
sidebarProjectGroupingMode: options.projectGroupingMode,
204205
sidebarProjectGroupingOverrides: {},
205206
});
206-
useEffect(() => {
207-
if (resolvedProjectKey !== projectScopeKey) {
208-
setSelectedProjectKey(resolvedProjectKey);
209-
}
210-
}, [projectScopeKey, resolvedProjectKey, setSelectedProjectKey]);
211207
const projectScopes = useMemo(
212208
() =>
213209
buildHomeProjectScopes({

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
resolveThreadWorkingStartedAt,
2727
} from "@t3tools/client-runtime/state/models";
2828
import { AuthOrchestrationOperateScope, type EnvironmentMachineKind } from "@t3tools/contracts";
29-
import { canSnooze, resolveSnoozePresets } from "@t3tools/client-runtime/state/thread-settled";
29+
import { canSnooze } from "@t3tools/client-runtime/state/thread-settled";
3030
import type { MenuAction } from "@react-native-menu/menu";
3131
import { memo, useCallback, useMemo, useState, type ComponentProps } from "react";
3232
import { Pressable, useWindowDimensions, View } from "react-native";
@@ -63,6 +63,7 @@ import {
6363
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
6464
resolveThreadListV2SnoozeGateExpiryMs,
6565
resolveThreadListV2SnoozeMenuSelection,
66+
resolveThreadListV2SnoozePresets,
6667
threadHasUnseenCompletion,
6768
resolveThreadListV2Status,
6869
resolveThreadListV2ProviderDrivers,
@@ -756,12 +757,10 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
756757
snoozable: canSnooze(thread, { now: snoozeGateNow }),
757758
snoozed: snoozedRow,
758759
});
759-
const snoozePresets = useMemo(
760-
// oxlint-disable-next-line react/purity -- The memo recomputes on the snoozePresetMinute tick, so preset times refresh every minute.
761-
() => (swipeActions.secondary === "snooze" ? resolveSnoozePresets(new Date()) : ([] as const)),
762-
// oxlint-disable-next-line react/memo-dependencies -- The minute tick refreshes relative snooze times while the row remains mounted.
763-
[props.snoozePresetMinute, swipeActions.secondary],
764-
);
760+
const snoozePresets = resolveThreadListV2SnoozePresets({
761+
secondary: swipeActions.secondary,
762+
now: props.snoozePresetMinute || snoozeGateNow,
763+
});
765764
const snoozePresetActions = useMemo<MenuAction[]>(
766765
() => [
767766
...snoozePresets.map((preset) => ({

‎apps/mobile/src/features/threads/threadListV2.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
buildThreadListV2ListItems,
3636
getThreadListV2OrderedSection,
3737
resolveThreadListV2SnoozeMenuSelection,
38+
resolveThreadListV2SnoozePresets,
3839
resolveThreadListV2Status,
3940
resolveThreadListV2WokeAt,
4041
sortThreadsForListV2,
@@ -76,6 +77,22 @@ describe("resolveThreadListV2SnoozeMenuSelection", () => {
7677
});
7778
});
7879

80+
describe("resolveThreadListV2SnoozePresets", () => {
81+
it("reads preset times from the list minute, not the clock at first render", () => {
82+
using _timers = { [Symbol.dispose]: () => vi.useRealTimers() };
83+
vi.useFakeTimers({ now: new Date(2026, 4, 8, 10) });
84+
const laterMinute = new Date(2026, 4, 8, 19, 15).toISOString();
85+
86+
const presets = resolveThreadListV2SnoozePresets({ secondary: "snooze", now: laterMinute });
87+
88+
expect(presets.find((preset) => preset.id === "hour")?.snoozedUntil).toBe(
89+
new Date(2026, 4, 8, 20, 15).toISOString(),
90+
);
91+
// The evening preset is gone by 19:15; a reading from 10:00 would still offer it.
92+
expect(presets.map((preset) => preset.id)).not.toContain("evening");
93+
});
94+
});
95+
7996
describe("resolveThreadListV2Status", () => {
8097
it("presents decoded thread waits as Waiting while preserving requests and older servers", () => {
8198
const raw = makeRawThreadShell({

0 commit comments

Comments
 (0)