mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 08:39:02 +03:00
fix(app): suppress missing-file toast on restored and open file tabs (#55022)
This commit is contained in:
committed by
GitHub
Unverified
parent
a3f7f42ac9
commit
2a593c0d1b
@@ -183,7 +183,7 @@ test("open file tab browses, searches, and tracks missing files", async ({ page
|
||||
const missingResponse = page.waitForResponse((response) => response.url().includes("/api/fs/read/README.md"))
|
||||
await workspace.push([filesystemEvent(directory, "README.md", "unlink")])
|
||||
await missingResponse
|
||||
await expect(page.getByText("Failed to load file", { exact: true })).toBeVisible()
|
||||
await expect(page.getByText("Failed to load file", { exact: true })).toHaveCount(0)
|
||||
await expect(tab("File not found: README.md")).toHaveAttribute("aria-selected", "true")
|
||||
await expect(panel.getByText("File not found: README.md", { exact: true })).toBeVisible()
|
||||
|
||||
@@ -495,6 +495,29 @@ test("rereads a file each time an artifact link opens it", async ({ page }) => {
|
||||
await expect(tab).toHaveAttribute("aria-selected", "true")
|
||||
await expect(panel.getByText("second draft", { exact: true })).toBeVisible()
|
||||
await expect(panel.getByText("first draft", { exact: true })).toHaveCount(0)
|
||||
|
||||
// A restored file tab whose file was deleted shows its inline not-found state without a toast; clicking a broken link
|
||||
// when no tab is open for it shows the toast.
|
||||
await page.route("**/api/fs/read/shopping.txt*", (route) =>
|
||||
route.fulfill({
|
||||
status: 404,
|
||||
headers: { "access-control-allow-origin": "*" },
|
||||
// SAFETY: the server's wire body for a missing file, which the client decodes into its own error.
|
||||
// oxlint-disable-next-line anti-slop-effect/no-manual-tagged-construction -- see SAFETY above
|
||||
json: { _tag: "FileNotFoundError", path: "shopping.txt", message: "File not found: shopping.txt" },
|
||||
}),
|
||||
)
|
||||
await page.reload()
|
||||
const missingTab = panel.getByRole("tab", { name: "File not found: shopping.txt", exact: true })
|
||||
await expect(missingTab).toHaveAttribute("aria-selected", "true")
|
||||
await expect(panel.getByText("File not found: shopping.txt", { exact: true })).toBeVisible()
|
||||
await expect(page.getByText("Failed to load file", { exact: true })).toHaveCount(0)
|
||||
|
||||
await missingTab.locator("..").getByRole("button", { name: "Close tab" }).click()
|
||||
await expect(missingTab).toHaveCount(0)
|
||||
await link.click()
|
||||
await expect(page.getByText("Failed to load file", { exact: true })).toBeVisible()
|
||||
await expect(missingTab).toHaveCount(0)
|
||||
})
|
||||
|
||||
/** What the image case's frame probe records on the window. */
|
||||
|
||||
@@ -48,7 +48,7 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
|
||||
const scope = createMemo(() => sdk().directory)
|
||||
const path = createPathHelpers(scope)
|
||||
|
||||
const inflight = new Map<string, Promise<void>>()
|
||||
const inflight = new Map<string, { promise: Promise<void>; silent: boolean }>()
|
||||
|
||||
const [store, setStore] = createStore<{
|
||||
file: Record<string, FileState>
|
||||
@@ -139,7 +139,7 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
|
||||
)
|
||||
}
|
||||
|
||||
const setLoadError = (file: string, message: string, notFound = false) => {
|
||||
const setLoadError = (file: string, message: string, notFound = false, silent = false) => {
|
||||
if (notFound) removeFileContentBytes(file)
|
||||
setStore(
|
||||
"file",
|
||||
@@ -154,6 +154,9 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
|
||||
draft.content = undefined
|
||||
}),
|
||||
)
|
||||
|
||||
if (silent || (notFound && extensions.files.opened().includes(file))) return
|
||||
|
||||
showToast({
|
||||
variant: "error",
|
||||
title: language.t("toast.file.loadFailed.title"),
|
||||
@@ -161,7 +164,7 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
|
||||
})
|
||||
}
|
||||
|
||||
const load = (input: string, options?: { force?: boolean }) => {
|
||||
const load = (input: string, options?: { force?: boolean; silent?: boolean }) => {
|
||||
const file = path.normalize(input)
|
||||
|
||||
if (!file) return Promise.resolve()
|
||||
@@ -174,9 +177,14 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
|
||||
|
||||
if (!options?.force && current?.loaded) return Promise.resolve()
|
||||
|
||||
const silent = Boolean(options?.silent)
|
||||
const pending = inflight.get(key)
|
||||
|
||||
if (pending) return pending
|
||||
if (pending) {
|
||||
if (!silent) pending.silent = false
|
||||
|
||||
return pending.promise
|
||||
}
|
||||
|
||||
setLoading(file)
|
||||
|
||||
@@ -186,7 +194,12 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
|
||||
? { path: getFilename(file), location: { directory: getDirectory(file) } }
|
||||
: { path: file, location: { directory } }
|
||||
|
||||
const promise = serverSDK.api.file
|
||||
const entry = {
|
||||
silent,
|
||||
promise: Promise.resolve(),
|
||||
}
|
||||
|
||||
entry.promise = serverSDK.api.file
|
||||
.read(request)
|
||||
.then((data) => {
|
||||
if (scope() !== directory) return
|
||||
@@ -201,15 +214,16 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({
|
||||
file,
|
||||
formatServerError(e, language.t, language.t("error.chain.unknown")),
|
||||
isFileNotFoundError(e),
|
||||
entry.silent,
|
||||
)
|
||||
})
|
||||
.finally(() => {
|
||||
inflight.delete(key)
|
||||
})
|
||||
|
||||
inflight.set(key, promise)
|
||||
inflight.set(key, entry)
|
||||
|
||||
return promise
|
||||
return entry.promise
|
||||
}
|
||||
|
||||
// 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({
|
||||
hasFile: (file) => Boolean(store.file[file]),
|
||||
isOpen: (file) => extensions.files.opened().includes(file),
|
||||
loadFile: (file) => {
|
||||
void load(file, { force: true })
|
||||
void load(file, { force: true, silent: true })
|
||||
},
|
||||
node: tree.node,
|
||||
isDirLoaded: tree.isLoaded,
|
||||
|
||||
@@ -358,7 +358,7 @@ const setup: Setup<typeof File> = (ctx) => {
|
||||
if (!isFileTab(input.tab.id)) return
|
||||
|
||||
focused.set(input.screen, input.tab.id)
|
||||
void input.screen.file.sync(fileTabPath(input.screen.file, input.tab.id))
|
||||
void input.screen.file.sync(fileTabPath(input.screen.file, input.tab.id), { silent: true })
|
||||
|
||||
// A restored file tab keeps the tree tab the user left, e.g. Changes across a reload.
|
||||
if (!input.restored && tree.value.tab === "changes") shared.tree.setTab("all")
|
||||
@@ -643,7 +643,8 @@ const setup: Setup<typeof File> = (ctx) => {
|
||||
|
||||
const id = focused.get(screen)
|
||||
|
||||
if (id && active(session, id)) void screen.file.sync(fileTabPath(screen.file, id), { force: true })
|
||||
if (id && active(session, id))
|
||||
void screen.file.sync(fileTabPath(screen.file, id), { force: true, silent: true })
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -199,6 +199,8 @@ export interface Files {
|
||||
options?: {
|
||||
/** Reloads even when the content has loaded. Defaults to false. */
|
||||
readonly force?: boolean
|
||||
/** Suppresses the error toast when the load fails. Defaults to false. */
|
||||
readonly silent?: boolean
|
||||
},
|
||||
): Promise<void>
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user