Skip to content

Commit 791dc0c

Browse files
authored
Merge branch 'main' into t3android/issue-21148
2 parents 358554f + 695f5c9 commit 791dc0c

342 files changed

Lines changed: 8218 additions & 5513 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/desktop/src/app/DesktopCliCommand.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,15 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
100100
const command = yield* commandIn({ home });
101101
const link = path.join(home, ".local", "bin", "t3");
102102

103-
expect(yield* command.state).toEqual({ supported: true, installedPath: null, onPath: false });
103+
expect(yield* command.state).toEqual({
104+
supported: true,
105+
installedPath: null,
106+
onPath: false,
107+
launcherPath: null,
108+
});
104109
const installed = yield* command.install;
105110
expect(installed.installedPath).toBe(link);
111+
expect(installed.launcherPath).toBe(path.join(home, ".t3", "bin", "t3"));
106112
expect(yield* fs.readLink(link)).toBe(path.join(home, ".t3", "bin", "t3"));
107113
expect((yield* command.install).installedPath).toBe(link);
108114

‎apps/desktop/src/app/DesktopCliCommand.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,26 @@ export const make = Effect.gen(function* () {
150150

151151
const state: DesktopCliCommand["Service"]["state"] = Effect.gen(function* () {
152152
if (!environment.isPackaged) {
153-
return { supported: false, installedPath: null, onPath: false } as const;
153+
return { supported: false, installedPath: null, onPath: false, launcherPath: null } as const;
154154
}
155+
const launcherPath = (yield* exists(launcher)) ? launcher : null;
155156
const installed = yield* installedAt;
156157
const shadowedBy = yield* foreignFirstOnPath;
157158
const shadow = Option.isSome(shadowedBy) ? { shadowedBy: shadowedBy.value } : {};
158159
if (Option.isNone(installed)) {
159-
return { supported: true, installedPath: null, onPath: false, ...shadow };
160+
return { supported: true, installedPath: null, onPath: false, launcherPath, ...shadow };
160161
}
161162
const first = yield* firstOnPath;
162163
const onPath = windows || (Option.isSome(first) && (yield* isOurLink(first.value)));
163-
return { supported: true, installedPath: installed.value, onPath, ...shadow };
164-
}).pipe(Effect.orElseSucceed(() => ({ supported: false, installedPath: null, onPath: false })));
164+
return { supported: true, installedPath: installed.value, onPath, launcherPath, ...shadow };
165+
}).pipe(
166+
Effect.orElseSucceed(() => ({
167+
supported: false,
168+
installedPath: null,
169+
onPath: false,
170+
launcherPath: null,
171+
})),
172+
);
165173

166174
const ensureLauncher = DesktopCliShim.install.pipe(
167175
Effect.provideService(DesktopEnvironment.DesktopEnvironment, environment),

‎apps/mobile/src/App.tsx‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PermissionUpdateNotice } from "./features/connection/PermissionUpdateNotice";
1+
import { installPermissionUpdateNotice } from "./features/connection/permissionUpdateNotice";
22
import * as Linking from "expo-linking";
33
import * as SplashScreen from "expo-splash-screen";
44
import { useEffect } from "react";
@@ -31,6 +31,12 @@ import { environmentThreadShells } from "./state/threads";
3131
import { environmentShell } from "./state/shell";
3232
import { OverlayPortalHost } from "./components/ui/OverlayPortal";
3333
import { shouldHandleAppLink, restoreDraftLinkState } from "./lib/appLinking";
34+
import { hasCloudPublicConfig } from "./features/cloud/publicConfig";
35+
import { takeScheduledTaskNewLink } from "./features/settings/scheduled-task-editor-state";
36+
import {
37+
disposeOnFoundationReplace,
38+
type FoundationHotModule,
39+
} from "./lib/foundation-fast-refresh";
3440
import { useMobileNavigationTheme } from "./lib/useMobileNavigationTheme";
3541
import { useUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarningGc";
3642
import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator";
@@ -58,7 +64,7 @@ void hydrateWorkspaceSelections();
5864
const appLinking = {
5965
prefixes: [Linking.createURL("/"), "t3code://", "t3code-dev://", "t3code-preview://"],
6066
config: { initialRouteName: "Home" },
61-
filter: shouldHandleAppLink,
67+
filter: (url: string) => shouldHandleAppLink(url, hasCloudPublicConfig()),
6268
getInitialURL: async () => (await Linking.getInitialURL()) ?? (await launchWorkspaceURL()),
6369
getActionFromState: (
6470
state: Parameters<typeof getActionFromState>[0],
@@ -68,15 +74,25 @@ const appLinking = {
6874
(workspaceDetailLinkAction(state) as ReturnType<typeof getActionFromState>) ??
6975
getActionFromState(state, options),
7076
getStateFromPath: (path: string, options: Parameters<typeof getStateFromPath>[1]) =>
71-
restoreSettingsLinkState(
72-
restoreDraftLinkState(getStateFromPath(path, options), path),
73-
settingsLinkPage(),
77+
takeScheduledTaskNewLink(
78+
restoreSettingsLinkState(
79+
restoreDraftLinkState(getStateFromPath(path, options), path),
80+
settingsLinkPage(),
81+
),
7482
),
7583
};
7684

7785
const Navigation = createStaticNavigation(RootStack);
7886
const navigationRef = createNavigationContainerRef();
7987

88+
declare const module: { readonly hot?: FoundationHotModule } | undefined;
89+
90+
const disposePermissionUpdateNotice = installPermissionUpdateNotice();
91+
disposeOnFoundationReplace(
92+
typeof module === "undefined" ? undefined : module.hot,
93+
disposePermissionUpdateNotice,
94+
);
95+
8096
function SplashScreenCoordinator() {
8197
const { isReady } = useAppearancePreferences();
8298

@@ -119,7 +135,6 @@ function AppContent() {
119135
<>
120136
<SplashScreenCoordinator />
121137
<SubscriptionUsageCoordinator />
122-
<PermissionUpdateNotice />
123138
<GestureHandlerRootView className="flex-1">
124139
<KeyboardProvider statusBarTranslucent>
125140
<SafeAreaProvider>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export function ComposerEditor({
7979
() => () => {
8080
importRef.current?.abort();
8181
},
82+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Switching drafts aborts an import owned by the previous draft.
8283
[draftKey],
8384
);
8485
const pasteContext = async (

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ function LoadedMediaVideo(props: {
9191

9292
useEffect(() => {
9393
const controller = new AbortController();
94+
// oxlint-disable-next-line react/set-state-in-effect -- Starting a native media load publishes pending before its async result.
9495
setLoadState("pending");
9596
// A renewed signature is used on Retry, not as a reason to reset the native player.
9697
void loadSource(controller.signal).then(
@@ -102,6 +103,7 @@ function LoadedMediaVideo(props: {
102103
},
103104
);
104105
return () => controller.abort();
106+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- A play request or Retry (attempt) reloads the source into the same player.
105107
}, [player, props.playRequested, attempt]);
106108

107109
return (

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ function ProjectFaviconImage(props: {
168168
if (faviconRequest === null) return;
169169

170170
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.
171172
setActiveFaviconRequest(faviconRequest);
172173
return endRequest;
173174
}, [faviconRequest]);

‎apps/mobile/src/components/VideoPreviewModal.ios.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function NativeVideoPreview(props: {
7070
return () => fullscreenVideoClosed();
7171
}, []);
7272
useEffect(() => {
73+
// oxlint-disable-next-line react/set-state-in-effect -- The native player latches the first resolved URL to keep its playback session.
7374
if (playbackUrl === null && resolvedUrl !== null) setPlaybackUrl(resolvedUrl);
7475
}, [playbackUrl, resolvedUrl]);
7576
useEffect(() => {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function useLocalPlayback(source: LocalVideoPreviewSource): PlaybackState {
6464
);
6565
const { id: attachmentId, fileUri } = attachment;
6666
useEffect(() => {
67+
// oxlint-disable-next-line react/set-state-in-effect -- A new attachment clears the previous attachment's result before loading.
6768
setUri(null);
6869
setError(null);
6970
const controller = new AbortController();
@@ -87,6 +88,7 @@ function useLocalPlayback(source: LocalVideoPreviewSource): PlaybackState {
8788
() => undefined,
8889
);
8990
};
91+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- A different attachment restarts the load even when it resolves to the same cached file URI.
9092
}, [attachmentId, fileUri]);
9193
const mimeType = videoMimeType(attachment) ?? attachment.mimeType;
9294
return {
@@ -208,9 +210,10 @@ export function VideoPreviewModal(props: {
208210
}) {
209211
const isFocused = useIsFocused();
210212
const hasSource = props.source !== null;
213+
const { onRequestClose } = props;
211214
useEffect(() => {
212-
if (!isFocused && hasSource) props.onRequestClose();
213-
}, [isFocused, hasSource, props.onRequestClose]);
215+
if (!isFocused && hasSource) onRequestClose();
216+
}, [isFocused, hasSource, onRequestClose]);
214217
const { source } = props;
215218
if (source === null || !isFocused) return null;
216219
return source.type === "local" ? (

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

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { MenuAction, MenuComponentProps } from "@react-native-menu/menu";
22
import type { ReactNode } from "react";
3-
import { use, useCallback, useEffect, useRef, useState } from "react";
3+
import { use, useRef, useState } from "react";
44
import type { StyleProp, ViewInstance, ViewStyle } from "react-native";
5-
import { BackHandler, Pressable, ScrollView, View } from "react-native";
5+
import { Pressable, ScrollView, View } from "react-native";
66
import { useKeyboardState } from "react-native-keyboard-controller";
77
import Animated, { FadeIn } from "react-native-reanimated";
88

9+
import { useHardwareBack } from "../../lib/backHandler";
910
import { deriveMenuHorizontalPlacement } from "../../lib/menu-placement";
1011
import { WindowHingeContext } from "../../native/window-hinge-context";
1112
import { OverlayPortal } from "./OverlayPortal";
@@ -47,46 +48,43 @@ export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
4748
const [rootHeight, setRootHeight] = useState<number | null>(null);
4849
const [overlay, setOverlay] = useState<OverlayFrame | null>(null);
4950
const windowHinge = use(WindowHingeContext);
50-
const anchorRef = useRef<ViewInstance>(null);
51+
// State, not a ref: `open` reaches render-prop children, and the compiler
52+
// bails out of the whole component when a ref might be read during render.
53+
const [anchorNode, setAnchorNode] = useState<ViewInstance | null>(null);
5154
const overlayRef = useRef<ViewInstance>(null);
5255

5356
const keyboardVisible = useKeyboardState((state) => state.isVisible);
5457
const keyboardHeight = useKeyboardState((state) => state.height);
55-
const close = useCallback(() => {
58+
const close = () => {
5659
setAnchor(null);
5760
setPath([]);
5861
setOverlay(null);
5962
setRootHeight(null);
60-
}, []);
63+
};
6164

62-
const open = useCallback(() => {
63-
anchorRef.current?.measureInWindow((x, y, width, height) => {
65+
const open = () => {
66+
anchorNode?.measureInWindow((x, y, width, height) => {
6467
setAnchor({ x, y, width, height, keyboardWasVisible: keyboardVisible });
6568
});
66-
}, [keyboardVisible]);
69+
};
6770

68-
const measureOverlay = useCallback(() => {
71+
const measureOverlay = () => {
6972
overlayRef.current?.measureInWindow((x, y, width, height) => {
7073
setOverlay({ x, y, width, height });
7174
setRootHeight(height);
7275
});
73-
}, []);
76+
};
7477

75-
const submenuDepth = path.length;
76-
useEffect(() => {
77-
if (anchor === null || !anchor.keyboardWasVisible) {
78-
return;
78+
// Only the in-window (keyboard) presentation needs this; the native popup
79+
// handles back itself.
80+
useHardwareBack(anchor?.keyboardWasVisible === true, () => {
81+
if (path.length > 0) {
82+
setPath((current) => current.slice(0, -1));
83+
} else {
84+
close();
7985
}
80-
const subscription = BackHandler.addEventListener("hardwareBackPress", () => {
81-
if (submenuDepth > 0) {
82-
setPath((current) => current.slice(0, -1));
83-
} else {
84-
close();
85-
}
86-
return true;
87-
});
88-
return () => subscription.remove();
89-
}, [anchor, close, submenuDepth]);
86+
return true;
87+
});
9088

9189
const parent = path[path.length - 1] ?? null;
9290
const levelActions = (parent?.subactions ?? props.actions).filter(
@@ -125,31 +123,33 @@ export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
125123
const maxHeight = Math.min(opensDown ? spaceBelow : spaceAbove, 480);
126124
const placeable = local !== null && rootHeight !== null;
127125

128-
const onPressItem = useCallback(
129-
(action: MenuAction) => {
130-
if ((action.subactions?.length ?? 0) > 0) {
131-
setPath((current) => [...current, action]);
132-
return;
133-
}
134-
close();
135-
if (action.id !== undefined) {
136-
props.onPressAction?.({
137-
nativeEvent: { event: action.id },
138-
} as Parameters<NonNullable<MenuComponentProps["onPressAction"]>>[0]);
139-
}
140-
},
141-
[close, props.onPressAction],
142-
);
126+
const onPressItem = (action: MenuAction) => {
127+
if ((action.subactions?.length ?? 0) > 0) {
128+
setPath((current) => [...current, action]);
129+
return;
130+
}
131+
close();
132+
if (action.id !== undefined) {
133+
props.onPressAction?.({
134+
nativeEvent: { event: action.id },
135+
} as Parameters<NonNullable<MenuComponentProps["onPressAction"]>>[0]);
136+
}
137+
};
143138

144139
return (
145140
<>
146141
{typeof props.children === "function" ? (
147-
<View ref={anchorRef} collapsable={false} className={props.className} style={props.style}>
142+
<View
143+
ref={setAnchorNode}
144+
collapsable={false}
145+
className={props.className}
146+
style={props.style}
147+
>
148148
{props.children(open)}
149149
</View>
150150
) : (
151151
<Pressable
152-
ref={anchorRef}
152+
ref={setAnchorNode}
153153
accessibilityRole="button"
154154
className={props.className}
155155
collapsable={false}

‎apps/mobile/src/components/ui/Dialog.android.test.tsx‎

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import { act, type ReactNode } from "react";
22
import { createRoot, type Root } from "react-dom/client";
33
import { afterEach, expect, it, vi } from "vite-plus/test";
44

5+
// Every click handler a button was rendered with, so a test can deliver a
6+
// native event that was dispatched against an older render.
7+
const renderedClicks = vi.hoisted(() => [] as Array<() => void>);
8+
59
vi.mock("@expo/ui/jetpack-compose", () => {
610
const Slot = (props: { readonly children?: ReactNode }) => <div>{props.children}</div>;
7-
const Button = (props: { readonly children?: ReactNode; readonly onClick?: () => void }) => (
8-
<button onClick={props.onClick}>{props.children}</button>
9-
);
11+
const Button = (props: { readonly children?: ReactNode; readonly onClick?: () => void }) => {
12+
if (props.onClick) renderedClicks.push(props.onClick);
13+
return <button onClick={props.onClick}>{props.children}</button>;
14+
};
1015
return {
1116
AlertDialog: Object.assign(Slot, {
1217
Title: Slot,
@@ -51,6 +56,7 @@ function mountHost() {
5156

5257
afterEach(() => {
5358
for (const root of roots.splice(0)) act(() => root.unmount());
59+
renderedClicks.length = 0;
5460
document.body.innerHTML = "";
5561
});
5662

@@ -65,3 +71,34 @@ it("keeps presenting dialogs after an older root's Host unmounts", () => {
6571

6672
expect(current.container.textContent).toContain("Saved");
6773
});
74+
75+
it("presents a dialog requested before any Host mounted", () => {
76+
Dialog.alert("Could not import shared content", undefined, [{ text: "Dismiss" }]);
77+
78+
const { container } = mountHost();
79+
80+
expect(container.textContent).toContain("Could not import shared content");
81+
});
82+
83+
it("keeps a dialog raised while the activity is replaced", () => {
84+
const previous = mountHost();
85+
act(() => Dialog.alert("Shared content imported", undefined, [{ text: "OK" }]));
86+
const current = mountHost();
87+
roots.splice(roots.indexOf(previous.root), 1);
88+
act(() => previous.root.unmount());
89+
90+
expect(current.container.textContent).toContain("Shared content imported");
91+
});
92+
93+
it("ignores a late action from a dialog that a newer one replaced", () => {
94+
const { container } = mountHost();
95+
const olderAction = vi.fn();
96+
act(() => Dialog.alert("Older", undefined, [{ text: "OK", onPress: olderAction }]));
97+
const olderClick = renderedClicks.at(-1)!;
98+
act(() => Dialog.alert("Newer", undefined, [{ text: "OK" }]));
99+
100+
act(() => olderClick());
101+
102+
expect(olderAction).toHaveBeenCalledOnce();
103+
expect(container.textContent).toContain("Newer");
104+
});

0 commit comments

Comments
 (0)