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 — fix(web): keep repository lookup dismissed after going back (#43427) · pingdotgg/t3code@1099705

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps
    • mobile/src/features/projects
      • AddProjectScreen.test.ts
      • AddProjectScreen.tsx
    • web/src/components
      • CommandPalette.composition.browser.test.tsx
      • CommandPalette.tsx
  • scripts/scenarios
    • back-keeps-repository-lookup-dismissed.e2e.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/mobile/src/features/projects/AddProjectScreen.test.ts‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/projects/AddProjectScreen.test.ts
+106-5Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from "@t3tools/contracts";
1414
import * as Cause from "effect/Cause";
1515
import { AsyncResult } from "effect/reactivity";
16-
import { act, createElement, isValidElement, type ReactNode } from "react";
16+
import { act, Children, createElement, isValidElement, type ReactNode } from "react";
1717
import { createRoot } from "react-dom/client";
1818
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
1919

@@ -32,6 +32,7 @@ const state = vi.hoisted(() => ({
3232
createResult: null as Promise<unknown> | null,
3333
createNewResult: null as Promise<unknown> | null,
3434
startCloneResult: null as Promise<unknown> | null,
35+
lookupRepository: vi.fn(),
3536
connectionStates: {} as Record<string, EnvironmentConnectionPhase>,
3637
newProjectsRoot: null as string | null,
3738
waitForProject: vi.fn(),
@@ -76,6 +77,7 @@ vi.mock("react-native", () => ({
7677
View: "View",
7778
}));
7879
vi.mock("@react-navigation/native", () => ({
80+
useRoute: () => state.navigationState?.routes[state.navigationState.index],
7981
useNavigation: () => ({
8082
dispatch: state.dispatch,
8183
getState: () =>
@@ -144,10 +146,14 @@ vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: (command: unkno
144146
vi.mock("../../state/use-atom-query-runner", () => ({
145147
useAtomQueryRunner:
146148
() =>
147-
async ({ input }: { input?: { partialPath?: string } }) =>
148-
input?.partialPath === "~"
149-
? AsyncResult.success({ parentPath: "/home/tester", entries: [] })
150-
: undefined,
149+
({ input }: { input?: { partialPath?: string; repository?: string } }) =>
150+
input?.repository
151+
? state.lookupRepository(input.repository)
152+
: Promise.resolve(
153+
input?.partialPath === "~"
154+
? AsyncResult.success({ parentPath: "/home/tester", entries: [] })
155+
: undefined,
156+
),
151157
}));
152158
vi.mock("../../state/query", () => ({ useEnvironmentQuery: () => ({ data: null }) }));
153159
vi.mock("../../state/presentation", () => ({
@@ -190,6 +196,7 @@ import {
190196
AddProjectNewScreen,
191197
AddProjectDestinationScreen,
192198
AddProjectLocalFolderScreen,
199+
AddProjectRepositoryScreen,
193200
AddProjectSourceScreen,
194201
} from "./AddProjectScreen";
195202
import { AddProjectSourceRoute } from "./AddProjectSourceRoute";
@@ -240,6 +247,99 @@ function renderScreen(render: () => ReactNode) {
240247
return screen;
241248
}
242249

250+
it.each([
251+
{ name: "Back after two submissions in one render", repeatSubmit: true, unmount: true },
252+
{ name: "Back before the screen unmounts" },
253+
{ name: "a change to the repository route parameters", changeParams: true },
254+
{ name: "submitting from a render with stale route parameters", replaceBeforeSubmit: true },
255+
])(
256+
"ignores a pending repository reply after $name",
257+
async ({ repeatSubmit, unmount, changeParams, replaceBeforeSubmit }) => {
258+
const repository = AsyncResult.success({
259+
provider: "github",
260+
nameWithOwner: "example/slow",
261+
url: "https://github.com/example/slow",
262+
sshUrl: "[email protected]:example/slow.git",
263+
});
264+
const lookup = Promise.withResolvers<typeof repository>();
265+
const duplicateLookup = Promise.withResolvers<typeof repository>();
266+
state.lookupRepository
267+
.mockReset()
268+
.mockReturnValueOnce(lookup.promise)
269+
.mockReturnValue(duplicateLookup.promise);
270+
state.dispatch.mockReset();
271+
state.environments = [{ environmentId: "environment", environmentLabel: "Environment" }];
272+
state.connectionStates = {};
273+
const flow = mountProjectFlow(false, false, false, "AddProjectRepository");
274+
flow.setParams({ environmentId: "environment", source: "github" });
275+
let screen: ReactNode;
276+
function RepositoryScreen() {
277+
screen = AddProjectRepositoryScreen({ environmentId: "environment", source: "github" });
278+
return null;
279+
}
280+
function withRepositoryInput(
281+
node: ReactNode,
282+
action: (input: {
283+
onChangeText: (value: string) => void;
284+
onSubmitEditing: () => void;
285+
}) => void,
286+
): void {
287+
Children.forEach(node, (child) => {
288+
if (
289+
!isValidElement<{
290+
children?: ReactNode;
291+
onChangeText?: (value: string) => void;
292+
onSubmitEditing?: () => void;
293+
}>(child)
294+
) {
295+
return;
296+
}
297+
const { onChangeText, onSubmitEditing } = child.props;
298+
if (onChangeText && onSubmitEditing) {
299+
action({ onChangeText, onSubmitEditing });
300+
} else {
301+
withRepositoryInput(child.props.children, action);
302+
}
303+
});
304+
}
305+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
306+
const root = createRoot(document.createElement("div"));
307+
mountedRoots.push(root);
308+
await act(() => root.render(createElement(RepositoryScreen)));
309+
await act(() => withRepositoryInput(screen, (input) => input.onChangeText("example/slow")));
310+
const submit = findAction(screen, "Lookup repository");
311+
if (!submit) throw new Error("Repository lookup action missing");
312+
try {
313+
if (replaceBeforeSubmit) flow.setParams({ source: "gitlab" });
314+
await act(() => {
315+
if (repeatSubmit) {
316+
withRepositoryInput(screen, (input) => input.onSubmitEditing());
317+
}
318+
void submit();
319+
});
320+
if (!replaceBeforeSubmit) {
321+
expect(state.lookupRepository).toHaveBeenCalledWith("example/slow");
322+
if (changeParams) {
323+
flow.setParams({ source: "gitlab" });
324+
} else {
325+
flow.back();
326+
}
327+
}
328+
if (unmount) await act(() => root.render(null));
329+
await act(async () => {
330+
lookup.resolve(repository);
331+
duplicateLookup.resolve(repository);
332+
await lookup.promise;
333+
});
334+
expect(state.dispatch).not.toHaveBeenCalled();
335+
expect(state.lookupRepository).toHaveBeenCalledTimes(replaceBeforeSubmit ? 0 : 1);
336+
} finally {
337+
state.navigationState = undefined;
338+
state.dispatch.mockReset();
339+
}
340+
},
341+
);
342+
243343
function cloneAction() {
244344
const action = findAction(
245345
renderScreen(() =>
@@ -340,6 +440,7 @@ function mountProjectFlow(
340440
"PullRequestFile",
341441
"NewTaskProject",
342442
"AddProject",
443+
"AddProjectRepository",
343444
"AddProjectLocal",
344445
"AddProjectNew",
345446
"AddProjectDestination",
Collapse file

‎apps/mobile/src/features/projects/AddProjectScreen.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/projects/AddProjectScreen.tsx
+39-20Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {
6565
import {
6666
StackActions,
6767
useNavigation,
68+
useRoute,
6869
type NavigationState,
6970
type ParamListBase,
7071
} from "@react-navigation/native";
@@ -755,6 +756,20 @@ function getActiveRoute(navigation: {
755756
return state?.routes[state.index];
756757
}
757758

759+
function isActiveRoute(
760+
navigation: Parameters<typeof getActiveRoute>[0],
761+
originRoute: ReturnType<typeof getActiveRoute>,
762+
): boolean {
763+
const activeRoute = getActiveRoute(navigation);
764+
// A warm link can change the task without replacing its native route key.
765+
return (
766+
originRoute !== undefined &&
767+
activeRoute?.key === originRoute.key &&
768+
activeRoute.name === originRoute.name &&
769+
activeRoute.params === originRoute.params
770+
);
771+
}
772+
758773
function useOpenNewTaskDraft() {
759774
const navigation = useNavigation<NativeStackNavigationProp<ReactNavigation.RootParamList>>();
760775
const selectDetail = useSelectWorkspaceDetail();
@@ -768,17 +783,7 @@ function useOpenNewTaskDraft() {
768783
},
769784
originRoute: NavigationState<ParamListBase>["routes"][number] | undefined,
770785
) => {
771-
const isStillOnOrigin = () => {
772-
const activeRoute = getActiveRoute(navigation);
773-
// A warm link can change the task without replacing its native route key.
774-
return (
775-
originRoute !== undefined &&
776-
activeRoute?.key === originRoute.key &&
777-
activeRoute.name === originRoute.name &&
778-
activeRoute.params === originRoute.params
779-
);
780-
};
781-
if (!isStillOnOrigin()) return;
786+
if (!isActiveRoute(navigation, originRoute)) return;
782787
const chooserDraft =
783788
params.draftId === undefined
784789
? chooserDraftKey(
@@ -792,7 +797,7 @@ function useOpenNewTaskDraft() {
792797
environmentId: params.environmentId,
793798
projectId: params.projectId,
794799
}).catch(() => false));
795-
if (!isStillOnOrigin()) return;
800+
if (!isActiveRoute(navigation, originRoute)) return;
796801
selectDetail({
797802
name: "Thread",
798803
params: { draft: carried ? { ...params, draftId: chooserDraft } : params },
@@ -962,16 +967,22 @@ export function AddProjectRepositoryScreen(props: {
962967
reportFailure: false,
963968
});
964969
const navigation = useNavigation();
970+
const originRoute = useRoute();
965971
const environment = useEnvironmentFromParam(props.environmentId);
966972
const source = sourceFromParam(props.source);
967973
const [repositoryInput, setRepositoryInput] = useState("");
968974
const [isSubmitting, setIsSubmitting] = useState(false);
969975
const [error, setError] = useState<string | null>(null);
976+
const pendingLookup = useRef<AbortController | null>(null);
970977
const gt = useGT();
971978
const messages = useMessages();
972979

980+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- cancels the repository lookup when its screen unmounts
981+
useEffect(() => () => pendingLookup.current?.abort(), []);
982+
973983
const lookupRepository = async () => {
974-
if (!environment || repositoryInput.trim().length === 0 || isSubmitting) return;
984+
if (!environment || repositoryInput.trim().length === 0 || pendingLookup.current) return;
985+
if (!isActiveRoute(navigation, originRoute)) return;
975986
const incompleteOwnerMessage = githubIncompleteOwnerRepositoryMessage(
976987
source,
977988
repositoryInput,
@@ -999,13 +1010,22 @@ export function AddProjectRepositoryScreen(props: {
9991010
return;
10001011
}
10011012

1002-
const result = await lookupRepositoryQuery({
1003-
environmentId: environment.environmentId,
1004-
input: {
1005-
provider,
1006-
repository: repositoryInput.trim(),
1013+
const lookup = new AbortController();
1014+
pendingLookup.current = lookup;
1015+
const result = await lookupRepositoryQuery(
1016+
{
1017+
environmentId: environment.environmentId,
1018+
input: {
1019+
provider,
1020+
repository: repositoryInput.trim(),
1021+
},
10071022
},
1008-
});
1023+
{ signal: lookup.signal },
1024+
);
1025+
if (lookup.signal.aborted) return;
1026+
pendingLookup.current = null;
1027+
setIsSubmitting(false);
1028+
if (!isActiveRoute(navigation, originRoute)) return;
10091029
if (AsyncResult.isFailure(result)) {
10101030
setError(errorMessage(Cause.squash(result.cause)));
10111031
} else {
@@ -1020,7 +1040,6 @@ export function AddProjectRepositoryScreen(props: {
10201040
}),
10211041
);
10221042
}
1023-
setIsSubmitting(false);
10241043
};
10251044

10261045
return (
Collapse file

‎apps/web/src/components/CommandPalette.composition.browser.test.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/CommandPalette.composition.browser.test.tsx
+35-1Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import { act, render } from "../../test/render";
77
import { CommandPalette } from "./CommandPalette";
88
import { openCommandPalette } from "../commandPaletteBus";
99
import { primaryServerKeybindingsAtom } from "../state/server";
10+
import { sourceControlEnvironment } from "../state/sourceControl";
11+
import { AsyncResult } from "effect/reactivity";
1012

1113
const scopes = vi.hoisted(() => ({
1214
denied: undefined as string | undefined,
1315
sourceControl: undefined as unknown,
16+
lookupRepository: vi.fn(),
1417
}));
1518
const setup = (deniedScope?: string, sourceControl?: unknown) => {
1619
scopes.denied = deniedScope;
@@ -73,7 +76,10 @@ vi.mock("../state/use-atom-command", () => ({
7376
}));
7477
vi.mock("../state/use-atom-query-runner", () => ({
7578
// Doubles as the add-project folder scan, which finds nothing to track.
76-
useAtomQueryRunner: () => async () => ({ _tag: "Success", value: { folders: [] } }),
79+
useAtomQueryRunner: (family: unknown) =>
80+
family === sourceControlEnvironment.repository
81+
? scopes.lookupRepository
82+
: async () => ({ _tag: "Success", value: { folders: [] } }),
7783
}));
7884
vi.mock("../state/environments", async (original) => ({
7985
...(await original<typeof import("../state/environments")>()),
@@ -244,3 +250,31 @@ it("tells screen readers whether a new project will be published", async () => {
244250
await option.click();
245251
await expect.element(option).toHaveAttribute("aria-checked", "true");
246252
});
253+
254+
it("keeps the source list visible after a dismissed repository lookup succeeds", async () => {
255+
setup(undefined, githubAvailable);
256+
const repository = AsyncResult.success({
257+
provider: "github",
258+
nameWithOwner: "example/slow",
259+
url: "https://github.com/example/slow",
260+
sshUrl: "[email protected]:example/slow.git",
261+
});
262+
const lookup = Promise.withResolvers<typeof repository>();
263+
scopes.lookupRepository.mockReset().mockReturnValue(lookup.promise);
264+
await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
265+
await act(() => openCommandPalette({ open: "add-project" }));
266+
await page.getByRole("option", { name: /^GitHub repository/ }).click();
267+
await page.getByRole("combobox").fill("example/slow");
268+
await userEvent.keyboard("{Enter}");
269+
expect(scopes.lookupRepository).toHaveBeenCalledOnce();
270+
await page.getByRole("combobox").fill("");
271+
await userEvent.keyboard("{Backspace}");
272+
const sources = page.getByText("Git URL", { exact: true });
273+
await expect.element(sources).toBeVisible();
274+
275+
await act(async () => {
276+
lookup.resolve(repository);
277+
await lookup.promise;
278+
});
279+
expect(sources.element()).toBeVisible();
280+
});
Collapse file

‎apps/web/src/components/CommandPalette.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/CommandPalette.tsx
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,10 @@ function OpenCommandPaletteDialog(props: {
10211021
setHighlightedItemValue(null);
10221022
});
10231023

1024-
function popView(): void {
1024+
const popView = useStableCallback((): void => {
10251025
browseNavigation.invalidate();
1026+
cloneLookupGeneration.current += 1;
1027+
setIsRemoteProjectLookingUp(false);
10261028
setAddProjectCloneFlow(null);
10271029
setNewProjectFlow(null);
10281030
if (viewStack.length <= 1) {
@@ -1032,7 +1034,7 @@ function OpenCommandPaletteDialog(props: {
10321034
}
10331035
dispatchSearch({ type: "back" });
10341036
setHighlightedItemValue(null);
1035-
}
1037+
});
10361038

10371039
function handleQueryChange(nextQuery: string, source: EventTarget | null): void {
10381040
browseNavigation.invalidate();

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.