Skip to content

Commit b60fe8b

Browse files
committed
Merge remote-tracking branch 'origin/main' into t3/move-undo-toast-top
# Conflicts: # apps/web/src/components/LegacySidebar.tsx # apps/web/src/components/sidebar/SidebarThreadUndoNotice.tsx
2 parents 5c36b3e + f40c7c6 commit b60fe8b

272 files changed

Lines changed: 6949 additions & 4792 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/mobile/modules/t3-source-text/src/SourceText.tsx‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,23 @@ export function SourceText({ style, children, nativeTextRef, ...props }: SourceT
2828
</Text>
2929
);
3030
}
31-
const runs = React.Children.toArray(children).map((child, index) => {
32-
if (React.isValidElement(child)) return child;
33-
if (typeof child !== "string" && typeof child !== "number") return null;
34-
return (
35-
<T3SourceTextRunNativeComponent
36-
key={index}
37-
style={flattenedStyle}
38-
{...flattenedStyle}
39-
text={String(child)}
40-
/>
41-
);
42-
});
31+
const runs = React.Children.toArray(children).map(
32+
(
33+
child,
34+
index,
35+
) => /* oxlint-disable react/no-array-index-key -- Native text runs are stateless positions within the supplied text. */ {
36+
if (React.isValidElement(child)) return child;
37+
if (typeof child !== "string" && typeof child !== "number") return null;
38+
return (
39+
<T3SourceTextRunNativeComponent
40+
key={index}
41+
style={flattenedStyle}
42+
{...flattenedStyle}
43+
text={String(child)}
44+
/>
45+
);
46+
} /* oxlint-enable react/no-array-index-key */,
47+
);
4348
if (isAncestor) {
4449
return <TextAncestorContext.Provider value={contextValue}>{runs}</TextAncestorContext.Provider>;
4550
}

‎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/Stack.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ export const RootStack = RootStackConfig.with(function AdaptiveRootStack({ Navig
10771077
const nativeMetrics = useNativeLayoutMetrics();
10781078
const usesSplitView = deriveLayout({ width, height, nativeMetrics }).usesSplitView;
10791079

1080+
/* oxlint-disable react/no-unstable-nested-components -- React Navigation invokes screenLayout as a render callback. */
10801081
return (
10811082
<Navigator
10821083
screenLayout={(props) => <GuardedScreenLayout {...props} />}
@@ -1087,6 +1088,8 @@ export const RootStack = RootStackConfig.with(function AdaptiveRootStack({ Navig
10871088
}
10881089
/>
10891090
);
1091+
1092+
/* oxlint-enable react/no-unstable-nested-components */
10901093
});
10911094

10921095
type RootStackType = typeof RootStack;

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,18 +268,23 @@ export function ComposerContextSheet(props: {
268268
<ContextField label="Comment" value={record.comment} />
269269
<ContextField label="Selection" value={record.targetSummary} />
270270
<ContextField label="Requested changes" value={record.styleChanges.join("\n")} />
271-
{record.elements?.map((element, index) => (
272-
<View key={`${element.selector ?? element.tagName}:${index}`} className="gap-3">
273-
<ContextField
274-
label="Element"
275-
value={element.componentName ?? element.tagName}
276-
/>
277-
<ContextField label="Selector" value={element.selector} code />
278-
<ContextSource source={element.source} />
279-
<ContextField label="HTML" value={element.htmlPreview} code />
280-
<ContextField label="Styles" value={element.styles} code />
281-
</View>
282-
))}
271+
{record.elements?.map(
272+
(element, index) => (
273+
/* oxlint-disable react/no-array-index-key -- Captured DOM elements are a fixed snapshot without persistent element IDs. */ <View
274+
key={`${element.selector ?? element.tagName}:${index}`}
275+
className="gap-3"
276+
>
277+
<ContextField
278+
label="Element"
279+
value={element.componentName ?? element.tagName}
280+
/>
281+
<ContextField label="Selector" value={element.selector} code />
282+
<ContextSource source={element.source} />
283+
<ContextField label="HTML" value={element.htmlPreview} code />
284+
<ContextField label="Styles" value={element.styles} code />
285+
</View>
286+
) /* oxlint-enable react/no-array-index-key */,
287+
)}
283288
</>
284289
) : null}
285290
{record.kind === "element" ? (

‎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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ function LoadedMediaVideo(props: {
102102
},
103103
);
104104
return () => controller.abort();
105+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- A play request or Retry (attempt) reloads the source into the same player.
105106
}, [player, props.playRequested, attempt]);
106107

107108
return (

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ function useLocalPlayback(source: LocalVideoPreviewSource): PlaybackState {
8787
() => undefined,
8888
);
8989
};
90+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- A different attachment restarts the load even when it resolves to the same cached file URI.
9091
}, [attachmentId, fileUri]);
9192
const mimeType = videoMimeType(attachment) ?? attachment.mimeType;
9293
return {
@@ -208,9 +209,10 @@ export function VideoPreviewModal(props: {
208209
}) {
209210
const isFocused = useIsFocused();
210211
const hasSource = props.source !== null;
212+
const { onRequestClose } = props;
211213
useEffect(() => {
212-
if (!isFocused && hasSource) props.onRequestClose();
213-
}, [isFocused, hasSource, props.onRequestClose]);
214+
if (!isFocused && hasSource) onRequestClose();
215+
}, [isFocused, hasSource, onRequestClose]);
214216
const { source } = props;
215217
if (source === null || !isFocused) return null;
216218
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)