GeezerVison is showing github.com — fix(web): choosing a project icon again re-reads it from disk (#28584) · pingdotgg/t3code@4f555c7
File treeExpand file treeCollapse file tree Open diff view settings packages/client-runtime/src/state
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/project/ProjectService.test.ts +53-1Lines changed: 53 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,7 @@ import { CommandId, type Project, ProjectId, ProviderInstanceId } from "@t3tools | 9 | 9 | import * as Deferred from "effect/Deferred"; | 10 | 10 | import * as Effect from "effect/Effect"; | 11 | 11 | import * as Fiber from "effect/Fiber"; | | 12 | +import * as FileSystem from "effect/FileSystem"; | 12 | 13 | import * as Layer from "effect/Layer"; | 13 | 14 | import * as Metric from "effect/Metric"; | 14 | 15 | import * as Option from "effect/Option"; | @@ -36,6 +37,7 @@ import * as ProjectEnrichmentService from "./ProjectEnrichmentService.ts"; | 36 | 37 | import * as ProjectFaviconResolver from "./ProjectFaviconResolver.ts"; | 37 | 38 | import * as ProjectService from "./ProjectService.ts"; | 38 | 39 | import * as RepositoryIdentityResolver from "./RepositoryIdentityResolver.ts"; | | 40 | +import * as T3ProjectFileLoader from "./T3ProjectFileLoader.ts"; | 39 | 41 |
| 40 | 42 | const layerWorkspacePaths = Layer.succeed(WorkspacePaths.WorkspacePaths, { | 41 | 43 | normalizeWorkspaceRoot: (workspaceRoot) => Effect.succeed(workspaceRoot.replace(/\/$/, "")), | @@ -300,7 +302,14 @@ it.layer(layerTest)("ProjectService", (it) => { | 300 | 302 | }); | 301 | 303 | assert.isFalse(reset.autoPull); | 302 | 304 | assert.isNull(reset.projectIcon); | 303 | | - assert.equal(reset.faviconPath, hydratedCreated.faviconPath); | | 305 | + assert.equal( | | 306 | + (yield* waitForProject( | | 307 | + service, | | 308 | + projectId, | | 309 | + (project) => project.faviconPath === hydratedCreated.faviconPath, | | 310 | + )).faviconPath, | | 311 | + hydratedCreated.faviconPath, | | 312 | + ); | 304 | 313 | assert.isNull(reset.defaultThreadEnvMode); | 305 | 314 | assert.deepEqual( | 306 | 315 | (yield* service.snapshot).projects.map((project) => project.id), | @@ -725,6 +734,49 @@ it.effect("invalidates workspace-derived metadata when a project moves", () => | 725 | 734 | }), | 726 | 735 | ); | 727 | 736 |
| | 737 | +it.effect("resolves a restored icon immediately after reselecting its saved path", () => | | 738 | + Effect.gen(function* () { | | 739 | + const fileSystem = yield* FileSystem.FileSystem; | | 740 | + const cwd = yield* fileSystem.makeTempDirectoryScoped({ prefix: "project-icon-reselect-" }); | | 741 | + const iconPath = `${cwd}/icon.svg`; | | 742 | + const metadata = Layer.merge( | | 743 | + Layer.succeed(RepositoryIdentityResolver.RepositoryIdentityResolver, { | | 744 | + resolve: () => Effect.succeed(null), | | 745 | + }), | | 746 | + ProjectFaviconResolver.layer.pipe( | | 747 | + Layer.provide(layerWorkspacePaths), | | 748 | + Layer.provide(T3ProjectFileLoader.layer), | | 749 | + Layer.provide(NodeServices.layer), | | 750 | + ), | | 751 | + ); | | 752 | + yield* Effect.gen(function* () { | | 753 | + const service = yield* ProjectService.ProjectService; | | 754 | + const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver; | | 755 | + const projectId = ProjectId.make("project:icon-reselect"); | | 756 | + yield* service.create({ | | 757 | + commandId: CommandId.make("command:icon-reselect:create"), | | 758 | + projectId, | | 759 | + title: "Icon reselection", | | 760 | + workspaceRoot: cwd, | | 761 | + }); | | 762 | + yield* service.update({ | | 763 | + commandId: CommandId.make("command:icon-reselect:missing"), | | 764 | + projectId, | | 765 | + faviconPath: "icon.svg", | | 766 | + }); | | 767 | + assert.isNull(yield* resolver.resolvePath(cwd, "icon.svg")); | | 768 | + yield* fileSystem.writeFileString(iconPath, '<svg xmlns="http://www.w3.org/2000/svg"/>'); | | 769 | + assert.isNull(yield* resolver.resolvePath(cwd, "icon.svg")); | | 770 | + yield* service.update({ | | 771 | + commandId: CommandId.make("command:icon-reselect:restored"), | | 772 | + projectId, | | 773 | + faviconPath: "icon.svg", | | 774 | + }); | | 775 | + assert.equal(yield* resolver.resolvePath(cwd, "icon.svg"), iconPath); | | 776 | + }).pipe(Effect.provide(layerTestFor(metadata))); | | 777 | + }).pipe(Effect.provide(NodeServices.layer)), | | 778 | +); | | 779 | + | 728 | 780 | it.effect("serializes two projects claiming the same workspace root", () => | 729 | 781 | Effect.gen(function* () { | 730 | 782 | const eventSink = yield* EventSink.EventSinkV2; | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/project/ProjectService.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -429,7 +429,7 @@ export const make = Effect.gen(function* () { | 429 | 429 | ...(input.pinned === undefined ? {} : { pinned: input.pinned }), | 430 | 430 | ...(input.archived === undefined ? {} : { archived: input.archived }), | 431 | 431 | }); | 432 | | - if (workspaceRoot !== previousRoot) { | | 432 | + if (workspaceRoot !== previousRoot || input.faviconPath !== undefined) { | 433 | 433 | yield* projectEnrichment.invalidate([previousRoot, workspaceRoot]); | 434 | 434 | } | 435 | 435 | return yield* readCommitted(input.projectId); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/settings/ProjectSettingsPanel.browser.test.tsx +36-1Lines changed: 36 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,7 +39,7 @@ const state = vi.hoisted(() => ({ | 39 | 39 | (request: { | 40 | 40 | environmentId: EnvironmentId; | 41 | 41 | input: UpdateProjectInput; | 42 | | - }) => Promise<AsyncResult.Success<void>> | | 42 | + }) => Promise<AsyncResult.Success<void> | AsyncResult.Failure<void, Error>> | 43 | 43 | >(), | 44 | 44 | delete: | 45 | 45 | vi.fn< | @@ -134,6 +134,7 @@ vi.mock(import("../files/projectFilesQueryState"), async (original) => ({ | 134 | 134 |
| 135 | 135 | import { useComposerDraftStore } from "../../composerDraftStore"; | 136 | 136 | import { appAtomRegistry } from "../../rpc/atomRegistry"; | | 137 | +import { assetEnvironment } from "../../state/assets"; | 137 | 138 | import { buildSidebarProjectSnapshots } from "../../sidebarProjectGrouping"; | 138 | 139 | import { ProjectSettingsPanel } from "./ProjectSettingsPanel"; | 139 | 140 | import { ProjectsSettings } from "./ProjectsSettings"; | @@ -532,6 +533,40 @@ describe("project identity reset", () => { | 532 | 533 | }, | 533 | 534 | ]); | 534 | 535 | }); | | 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 | + }); | 535 | 570 | }); | 536 | 571 |
| 537 | 572 | it("opens the fallback search target across all environments from a checkout", async () => { | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/settings/ProjectSettingsPanel.tsx +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,6 +29,7 @@ import { | 29 | 29 | } from "../../sidebarProjectGrouping"; | 30 | 30 | import { useEnvironments, usePrimaryEnvironmentId } from "../../state/environments"; | 31 | 31 | import { useThreadShells, waitForProjectRemoval } from "../../state/entities"; | | 32 | +import { refreshProjectFaviconUrl } from "../../state/assets"; | 32 | 33 | import { projectEnvironment } from "../../state/projects"; | 33 | 34 | import { ProjectFavicon } from "../ProjectFavicon"; | 34 | 35 | import { Alert, AlertDescription } from "../ui/alert"; | @@ -331,6 +332,15 @@ function ProjectDetail({ | 331 | 332 | savingFaviconRef.current = true; | 332 | 333 | setIsSavingFavicon(true); | 333 | 334 | await updateAllMembers(input, "Failed to update project icon"); | | 335 | + for (const member of group.memberProjects) { | | 336 | + const update = typeof input === "function" ? input(member) : input; | | 337 | + if (update.faviconPath === undefined || update.projectIcon) continue; | | 338 | + refreshProjectFaviconUrl({ | | 339 | + environmentId: member.environmentId, | | 340 | + cwd: member.workspaceRoot, | | 341 | + faviconPath: update.faviconPath, | | 342 | + }); | | 343 | + } | 334 | 344 | savingFaviconRef.current = false; | 335 | 345 | setIsSavingFavicon(false); | 336 | 346 | }; | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/state/assets.ts +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import type { ProjectFaviconTarget } from "@t3tools/client-runtime/project-favicon-cache"; | 1 | 2 | import { | 2 | 3 | createAssetEnvironmentAtoms, | 3 | 4 | createProjectFaviconUrlAtomFamily, | | 5 | + projectFaviconResource, | 4 | 6 | } from "@t3tools/client-runtime/state/assets"; | 5 | 7 | import { Atom } from "effect/reactivity"; | 6 | 8 |
| 7 | 9 | import { connectionAtomRuntime } from "../connection/runtime"; | | 10 | +import { appAtomRegistry } from "../rpc/atomRegistry"; | 8 | 11 | import { projectFaviconCache } from "../assets/projectFaviconCache"; | 9 | 12 | import { isElectron } from "../env"; | 10 | 13 | import { primaryEnvironmentIdAtom } from "./primaryEnvironment"; | @@ -33,3 +36,16 @@ export const projectFaviconUrlAtom = createProjectFaviconUrlAtomFamily({ | 33 | 36 | preparedConnection: environmentSession.preparedConnectionValueAtom, | 34 | 37 | projectClones: environmentProjectClonesAtom, | 35 | 38 | }); | | 39 | + | | 40 | +/** | | 41 | + * Asks the server for a project's icon again. Choosing the icon path a project had before would | | 42 | + * otherwise reuse that path's cached URL, which says "missing" if the file did not exist then. | | 43 | + */ | | 44 | +export function refreshProjectFaviconUrl(target: ProjectFaviconTarget) { | | 45 | + appAtomRegistry.refresh( | | 46 | + assetEnvironment.createUrl({ | | 47 | + environmentId: target.environmentId, | | 48 | + input: { resource: projectFaviconResource(target.cwd, target.faviconPath) }, | | 49 | + }), | | 50 | + ); | | 51 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/assets.ts +12-2Lines changed: 12 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -323,6 +323,14 @@ export function createAssetEnvironmentAtoms<R, E>( | 323 | 323 | }; | 324 | 324 | } | 325 | 325 |
| | 326 | +/** | | 327 | + * The resource a project's icon URL is minted for. Refreshing the `createUrl` query for it makes | | 328 | + * the server resolve the icon again instead of serving a cached answer. | | 329 | + */ | | 330 | +export function projectFaviconResource(cwd: string, path: string | null | undefined) { | | 331 | + return { _tag: "project-favicon" as const, cwd, ...(path ? { path } : {}) }; | | 332 | +} | | 333 | + | 326 | 334 | export function createProjectFaviconUrlAtomFamily(input: { | 327 | 335 | readonly imageCache?: ProjectFaviconCache; | 328 | 336 | readonly createUrl: (target: { | @@ -342,8 +350,10 @@ export function createProjectFaviconUrlAtomFamily(input: { | 342 | 350 | const projectClones = input.projectClones; | 343 | 351 | const family = Atom.family((key: string) => { | 344 | 352 | const [environmentId, cwd, path] = decodeKey(JSON.parse(key)); | 345 | | - const resource = { _tag: "project-favicon" as const, cwd, ...(path ? { path } : {}) }; | 346 | | - const query = input.createUrl({ environmentId, input: { resource } }); | | 353 | + const query = input.createUrl({ | | 354 | + environmentId, | | 355 | + input: { resource: projectFaviconResource(cwd, path) }, | | 356 | + }); | 347 | 357 | // A cloned project exists before its files do, and the server reports its | 348 | 358 | // icon missing until the clone lands. Ask again whenever the clone's phase | 349 | 359 | // changes: the first list a client sees may already say done. | |
|