Skip to content

Commit 2a593c0

Browse files
authored
fix(app): suppress missing-file toast on restored and open file tabs (#55022)
1 parent a3f7f42 commit 2a593c0

4 files changed

Lines changed: 51 additions & 11 deletions

File tree

‎packages/app/e2e/regression/review.spec.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ test("open file tab browses, searches, and tracks missing files", async ({ page
183183
const missingResponse = page.waitForResponse((response) => response.url().includes("/api/fs/read/README.md"))
184184
await workspace.push([filesystemEvent(directory, "README.md", "unlink")])
185185
await missingResponse
186-
await expect(page.getByText("Failed to load file", { exact: true })).toBeVisible()
186+
await expect(page.getByText("Failed to load file", { exact: true })).toHaveCount(0)
187187
await expect(tab("File not found: README.md")).toHaveAttribute("aria-selected", "true")
188188
await expect(panel.getByText("File not found: README.md", { exact: true })).toBeVisible()
189189

@@ -495,6 +495,29 @@ test("rereads a file each time an artifact link opens it", async ({ page }) => {
495495
await expect(tab).toHaveAttribute("aria-selected", "true")
496496
await expect(panel.getByText("second draft", { exact: true })).toBeVisible()
497497
await expect(panel.getByText("first draft", { exact: true })).toHaveCount(0)
498+
499+
// A restored file tab whose file was deleted shows its inline not-found state without a toast; clicking a broken link
500+
// when no tab is open for it shows the toast.
501+
await page.route("**/api/fs/read/shopping.txt*", (route) =>
502+
route.fulfill({
503+
status: 404,
504+
headers: { "access-control-allow-origin": "*" },
505+
// SAFETY: the server's wire body for a missing file, which the client decodes into its own error.
506+
// oxlint-disable-next-line anti-slop-effect/no-manual-tagged-construction -- see SAFETY above
507+
json: { _tag: "FileNotFoundError", path: "shopping.txt", message: "File not found: shopping.txt" },
508+
}),
509+
)
510+
await page.reload()
511+
const missingTab = panel.getByRole("tab", { name: "File not found: shopping.txt", exact: true })
512+
await expect(missingTab).toHaveAttribute("aria-selected", "true")
513+
await expect(panel.getByText("File not found: shopping.txt", { exact: true })).toBeVisible()
514+
await expect(page.getByText("Failed to load file", { exact: true })).toHaveCount(0)
515+
516+
await missingTab.locator("..").getByRole("button", { name: "Close tab" }).click()
517+
await expect(missingTab).toHaveCount(0)
518+
await link.click()
519+
await expect(page.getByText("Failed to load file", { exact: true })).toBeVisible()
520+
await expect(missingTab).toHaveCount(0)
498521
})
499522

500523
/** What the image case's frame probe records on the window. */

‎packages/app/src/workspaces/files/model.tsx‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
4848
const scope = createMemo(() => sdk().directory)
4949
const path = createPathHelpers(scope)
5050

51-
const inflight = new Map<string, Promise<void>>()
51+
const inflight = new Map<string, { promise: Promise<void>; silent: boolean }>()
5252

5353
const [store, setStore] = createStore<{
5454
file: Record<string, FileState>
@@ -139,7 +139,7 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
139139
)
140140
}
141141

142-
const setLoadError = (file: string, message: string, notFound = false) => {
142+
const setLoadError = (file: string, message: string, notFound = false, silent = false) => {
143143
if (notFound) removeFileContentBytes(file)
144144
setStore(
145145
"file",
@@ -154,14 +154,17 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
154154
draft.content = undefined
155155
}),
156156
)
157+
158+
if (silent || (notFound && extensions.files.opened().includes(file))) return
159+
157160
showToast({
158161
variant: "error",
159162
title: language.t("toast.file.loadFailed.title"),
160163
description: message,
161164
})
162165
}
163166

164-
const load = (input: string, options?: { force?: boolean }) => {
167+
const load = (input: string, options?: { force?: boolean; silent?: boolean }) => {
165168
const file = path.normalize(input)
166169

167170
if (!file) return Promise.resolve()
@@ -174,9 +177,14 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
174177

175178
if (!options?.force && current?.loaded) return Promise.resolve()
176179

180+
const silent = Boolean(options?.silent)
177181
const pending = inflight.get(key)
178182

179-
if (pending) return pending
183+
if (pending) {
184+
if (!silent) pending.silent = false
185+
186+
return pending.promise
187+
}
180188

181189
setLoading(file)
182190

@@ -186,7 +194,12 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
186194
? { path: getFilename(file), location: { directory: getDirectory(file) } }
187195
: { path: file, location: { directory } }
188196

189-
const promise = serverSDK.api.file
197+
const entry = {
198+
silent,
199+
promise: Promise.resolve(),
200+
}
201+
202+
entry.promise = serverSDK.api.file
190203
.read(request)
191204
.then((data) => {
192205
if (scope() !== directory) return
@@ -201,15 +214,16 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
201214
file,
202215
formatServerError(e, language.t, language.t("error.chain.unknown")),
203216
isFileNotFoundError(e),
217+
entry.silent,
204218
)
205219
})
206220
.finally(() => {
207221
inflight.delete(key)
208222
})
209223

210-
inflight.set(key, promise)
224+
inflight.set(key, entry)
211225

212-
return promise
226+
return entry.promise
213227
}
214228

215229
// Lists the parent directory instead of reading the file, so checking a path a message names transfers no content.
@@ -253,7 +267,7 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
253267
hasFile: (file) => Boolean(store.file[file]),
254268
isOpen: (file) => extensions.files.opened().includes(file),
255269
loadFile: (file) => {
256-
void load(file, { force: true })
270+
void load(file, { force: true, silent: true })
257271
},
258272
node: tree.node,
259273
isDirLoaded: tree.isLoaded,

‎packages/gui-extensions/src/file/renderer.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ const setup: Setup<typeof File> = (ctx) => {
358358
if (!isFileTab(input.tab.id)) return
359359

360360
focused.set(input.screen, input.tab.id)
361-
void input.screen.file.sync(fileTabPath(input.screen.file, input.tab.id))
361+
void input.screen.file.sync(fileTabPath(input.screen.file, input.tab.id), { silent: true })
362362

363363
// A restored file tab keeps the tree tab the user left, e.g. Changes across a reload.
364364
if (!input.restored && tree.value.tab === "changes") shared.tree.setTab("all")
@@ -643,7 +643,8 @@ const setup: Setup<typeof File> = (ctx) => {
643643

644644
const id = focused.get(screen)
645645

646-
if (id && active(session, id)) void screen.file.sync(fileTabPath(screen.file, id), { force: true })
646+
if (id && active(session, id))
647+
void screen.file.sync(fileTabPath(screen.file, id), { force: true, silent: true })
647648
})
648649
}
649650

‎packages/gui-extensions/src/sdk/host-apis.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ export interface Files {
199199
options?: {
200200
/** Reloads even when the content has loaded. Defaults to false. */
201201
readonly force?: boolean
202+
/** Suppresses the error toast when the load fails. Defaults to false. */
203+
readonly silent?: boolean
202204
},
203205
): Promise<void>
204206
/**

0 commit comments

Comments
 (0)