Skip to content

fix: fall back to built webview assets when dev server is unreachable - #614

Closed
ONEGAYI wants to merge 1 commit into
cweijan:mainfrom
ONEGAYI:fix/dev-webview-fallback
Closed

ONEGAYI wants to merge 1 commit into
cweijan:mainfrom
ONEGAYI:fix/dev-webview-fallback

Conversation

@ONEGAYI

@ONEGAYI ONEGAYI commented Sep 17, 2026

Copy link
Copy Markdown

Problem

In extension development mode (IS_DEV), the webview HTML is fetched from the vite dev server at 127.0.0.1:5739. When that server is not running — or its port cannot be bound at all (e.g. Windows reserved port ranges covering 5739 yield EACCES on listen) — every office file open fails: resolveCustomEditor rejects with ECONNREFUSED and the editor shows "Unable to open ... Assertion Failed" style errors.

This is easy to hit because the F5 preLaunchTask (npm run dev) starts the esbuild watch and the vite dev server together: the watch succeeds and the task completes, so the Extension Development Host launches even though the dev server is dead.

Fix

  • Extract a small resolveWebviewContent contract (src/common/webviewContent.ts): serve dev content when reachable, otherwise fall back to the last production build in out/webview.
  • Keep the <base> URL consistent with the chosen source via a fromDevServer flag, so fallback pages load assets from the webview CDN instead of the dead dev server.
  • Log the fallback (including the connection error) to the "Office Viewer" output channel, and add a 3s timeout so a hanging dev server falls back quickly instead of stalling the open.

Normal dev workflow (server up) and production mode behavior are unchanged.

Notes

  • The fallback requires out/webview to exist (i.e. npm run build has run at least once). In a fresh clone where only the dev server is expected, a dead server still fails the open — same as before this change.
  • test:unit uses node --test with TypeScript type stripping and needs Node >= 22.6 locally; CI (Node 20) does not run it.

In extension development mode the webview HTML is fetched from the
vite dev server (127.0.0.1:5739). When that server is not running -
or its port cannot be bound (e.g. blocked by OS port exclusions) -
every office file open fails: resolveCustomEditor rejects with
ECONNREFUSED and the editor shows 'Unable to open ... Assertion
Failed' errors.

- Extract a resolveWebviewContent contract: serve dev content when
  reachable, otherwise fall back to the last production build in
  out/webview
- Keep the base URL consistent with the chosen source so fallback
  pages load assets from the webview CDN instead of the dead dev
  server
- Add unit tests covering dev, fallback, and production paths
@ONEGAYI ONEGAYI closed this Sep 17, 2026
@ONEGAYI
ONEGAYI deleted the fix/dev-webview-fallback branch September 17, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant