Skip to content

Commit 3066c86

Browse files
committed
fix(web): refresh saved icons after a partial group failure
1 parent 49d73c4 commit 3066c86

2 files changed

Lines changed: 45 additions & 12 deletions

File tree

‎apps/web/src/components/settings/ProjectSettingsPanel.browser.test.tsx‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const state = vi.hoisted(() => ({
3939
(request: {
4040
environmentId: EnvironmentId;
4141
input: UpdateProjectInput;
42-
}) => Promise<AsyncResult.Success<void>>
42+
}) => Promise<AsyncResult.Success<void> | AsyncResult.Failure<void, Error>>
4343
>(),
4444
delete:
4545
vi.fn<
@@ -134,6 +134,7 @@ vi.mock(import("../files/projectFilesQueryState"), async (original) => ({
134134

135135
import { useComposerDraftStore } from "../../composerDraftStore";
136136
import { appAtomRegistry } from "../../rpc/atomRegistry";
137+
import { assetEnvironment } from "../../state/assets";
137138
import { buildSidebarProjectSnapshots } from "../../sidebarProjectGrouping";
138139
import { ProjectSettingsPanel } from "./ProjectSettingsPanel";
139140
import { ProjectsSettings } from "./ProjectsSettings";
@@ -532,6 +533,40 @@ describe("project identity reset", () => {
532533
},
533534
]);
534535
});
536+
537+
it("refreshes a saved checkout's icon when a later checkout update fails", async () => {
538+
setup();
539+
state.projects = state.projects.map((project) => ({ ...project, faviconPath: "logo.png" }));
540+
let iconExists = false;
541+
const iconUrl = Atom.make(() =>
542+
AsyncResult.success({
543+
expiresAt: 4_000_000_000_000,
544+
relativeUrl: iconExists ? "/restored-icon.svg" : "/project-favicon-missing",
545+
}),
546+
);
547+
using _mount = { [Symbol.dispose]: appAtomRegistry.mount(iconUrl) };
548+
const createUrl = assetEnvironment.createUrl;
549+
using _createUrl = vi
550+
.spyOn(assetEnvironment, "createUrl")
551+
.mockImplementation((target) =>
552+
target.environmentId === primaryId ? iconUrl : createUrl(target),
553+
);
554+
state.update
555+
.mockResolvedValueOnce(AsyncResult.success(undefined))
556+
.mockResolvedValueOnce(AsyncResult.failure(Cause.fail(new Error("Save failed"))));
557+
await using screen = await mountPanel();
558+
expect(appAtomRegistry.get(iconUrl).value.relativeUrl).toBe("/project-favicon-missing");
559+
560+
iconExists = true;
561+
await userEvent.click(resetButton(screen, "project icon")!);
562+
563+
await vi.waitFor(() =>
564+
expect(appAtomRegistry.get(iconUrl).value.relativeUrl).toBe("/restored-icon.svg"),
565+
);
566+
expect(state.toast).toHaveBeenCalledWith(
567+
expect.objectContaining({ title: "Failed to update project icon on remote" }),
568+
);
569+
});
535570
});
536571

537572
it("opens the fallback search target across all environments from a checkout", async () => {

‎apps/web/src/components/settings/ProjectSettingsPanel.tsx‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,15 @@ function ProjectDetail({
258258
if (savingFaviconRef.current) return;
259259
savingFaviconRef.current = true;
260260
setIsSavingFavicon(true);
261-
const result = await updateAllMembers(input, "Failed to update project icon");
262-
if (result._tag === "Success") {
263-
for (const member of group.memberProjects) {
264-
const update = typeof input === "function" ? input(member) : input;
265-
if (update.faviconPath === undefined || update.projectIcon) continue;
266-
refreshProjectFaviconUrl({
267-
environmentId: member.environmentId,
268-
cwd: member.workspaceRoot,
269-
faviconPath: update.faviconPath,
270-
});
271-
}
261+
await updateAllMembers(input, "Failed to update project icon");
262+
for (const member of group.memberProjects) {
263+
const update = typeof input === "function" ? input(member) : input;
264+
if (update.faviconPath === undefined || update.projectIcon) continue;
265+
refreshProjectFaviconUrl({
266+
environmentId: member.environmentId,
267+
cwd: member.workspaceRoot,
268+
faviconPath: update.faviconPath,
269+
});
272270
}
273271
savingFaviconRef.current = false;
274272
setIsSavingFavicon(false);

0 commit comments

Comments
 (0)