Skip to content

Commit 437abce

Browse files
committed
fix(webview): distinguish HMR probe timeouts from unavailable dev server
1 parent dea0067 commit 437abce

20 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎src/core/webview/ClineProvider.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,8 +1639,11 @@ export class ClineProvider
16391639
// Check if local dev server is running.
16401640
try {
16411641
await axios.get(`http://${localServerUrl}`, { timeout: 5_000 })
1642-
} catch {
1643-
vscode.window.showErrorMessage(t("common:errors.hmr_not_running"))
1642+
} catch (error) {
1643+
const timedOut = axios.isAxiosError(error) && (error.code === "ECONNABORTED" || error.code === "ETIMEDOUT")
1644+
void vscode.window.showErrorMessage(
1645+
t(timedOut ? "common:errors.hmr_probe_timeout" : "common:errors.hmr_not_running"),
1646+
)
16441647
return this.getHtmlContent(webview)
16451648
}
16461649

‎src/core/webview/__tests__/ClineProvider.spec.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ vi.mock("fs/promises", async (importOriginal) => {
6969
}
7070
})
7171

72-
vi.mock("axios", () => ({
72+
vi.mock("axios", async (importOriginal) => ({
7373
default: {
74+
isAxiosError: (await importOriginal<typeof import("axios")>()).default.isAxiosError,
7475
get: vi.fn().mockResolvedValue({ data: { data: [] } }),
7576
post: vi.fn(),
7677
},
@@ -2300,6 +2301,21 @@ describe("ClineProvider", () => {
23002301
expect(scriptSrcMatch![0]).toContain("'wasm-unsafe-eval'")
23012302
})
23022303

2304+
test.each([
2305+
["ECONNABORTED", "errors.hmr_probe_timeout"],
2306+
["ETIMEDOUT", "errors.hmr_probe_timeout"],
2307+
["ECONNREFUSED", "errors.hmr_not_running"],
2308+
])("reports dev-server probe failure %s accurately and falls back to built HTML", async (code, message) => {
2309+
const { AxiosError } = await vi.importActual<typeof import("axios")>("axios")
2310+
vi.mocked(axios.get).mockRejectedValueOnce(new AxiosError("probe failed", code))
2311+
2312+
const html = await provider["getHMRHtmlContent"](mockWebviewView.webview)
2313+
2314+
expect(vscode.window.showErrorMessage).toHaveBeenCalledWith(message)
2315+
expect(html).toContain("<!DOCTYPE html>")
2316+
expect(html).not.toContain("/@react-refresh")
2317+
})
2318+
23032319
test("resolveWebviewView builds HMR content against the local dev server when it is reachable", async () => {
23042320
const originalThemeFixtureProbe = process.env.ROO_CODE_THEME_FIXTURE_PROBE
23052321
delete process.env.ROO_CODE_THEME_FIXTURE_PROBE

‎src/i18n/locales/ca/common.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/de/common.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/en/common.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"list_api_config": "Failed to get list api configuration",
5252
"update_server_timeout": "Failed to update server timeout",
5353
"hmr_not_running": "Local development server is not running, HMR will not work. Please run 'npm run dev' before launching the extension to enable HMR.",
54+
"hmr_probe_timeout": "The local development server did not respond within 5 seconds. Using the built extension UI without HMR.",
5455
"retrieve_current_mode": "Error: failed to retrieve current mode from state.",
5556
"failed_delete_repo": "Failed to delete associated shadow repository or branch: {{error}}",
5657
"failed_remove_directory": "Failed to remove task directory: {{error}}",

‎src/i18n/locales/es/common.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/fr/common.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/hi/common.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/id/common.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/i18n/locales/it/common.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)