Skip to content

fix(core): add vite server fallback for embedded connections - #494

Merged
antfu merged 1 commit into
mainfrom
fix/embedded-client-base-url
Jul 29, 2026
Merged

fix(core): add vite server fallback for embedded connections#494
antfu merged 1 commit into
mainfrom
fix/embedded-client-base-url

Conversation

@webfansplz

Copy link
Copy Markdown
Member

The embedded client currently loads connection metadata from the page origin. When the page is served by a separate backend, this can point to the wrong server.

This PR:

keeps the existing /__devtools/ base as the first candidate

falls back to the vite server URL inferred from import.meta.url

preserves existing same-origin and proxied setups

adds unit tests for both candidate URLs and their priority

Related devframe change

This relies on devframes/devframe#146.

fetch() resolves normally for HTTP errors such as 404. If the response body is valid JSON, the previous implementation could treat it as connection metadata and never try the fallback URL.

devframes/devframe#146 checks response.ok before parsing the response, allowing connection discovery to continue with the next candidate after an HTTP error.

Fixes #489.

@pkg-pr-new

pkg-pr-new Bot commented Jul 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@494

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@494

@vitejs/devtools-oxc

npm i https://pkg.pr.new/@vitejs/devtools-oxc@494

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@494

@vitejs/devtools-vite

npm i https://pkg.pr.new/@vitejs/devtools-vite@494

@vitejs/devtools-vitest

npm i https://pkg.pr.new/@vitejs/devtools-vitest@494

commit: 20215b7

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes embedded-client connection discovery when the host page is served from a different origin than the Vite dev server by adding a fallback base URL derived from import.meta.url, while keeping the existing /__devtools/ lookup as the first (backwards-compatible) candidate.

Changes:

  • Update the injected runtime to try connection metadata from /__devtools/ first, then fall back to the Vite-origin URL inferred from import.meta.url.
  • Add unit tests asserting the two candidate base URLs and their priority order.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/core/src/client/inject/runtime.ts Adds baseURL fallback logic for RPC client connection discovery in embedded mode.
packages/core/src/client/inject/runtime.test.ts Introduces tests covering the baseURL candidate list and its ordering.
Comments suppressed due to low confidence (2)

packages/core/src/client/inject/runtime.test.ts:44

  • This assertion hardcodes '/__devtools/'. Prefer asserting against DEVTOOLS_MOUNT_PATH so the test stays consistent with the runtime constant.
    expect(options.baseURL).toHaveLength(2)
    expect(options.baseURL[0]).toBe('/__devtools/')
  })

packages/core/src/client/inject/runtime.test.ts:51

  • This assertion also hardcodes the mount path. Using DEVTOOLS_MOUNT_PATH here avoids duplicated literals and keeps the fallback URL test aligned with the runtime constant.
    expect(options.baseURL[1]).toBe(
      new URL('/__devtools/', import.meta.url).href,
    )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/client/inject/runtime.test.ts
@webfansplz
webfansplz force-pushed the fix/embedded-client-base-url branch from 50c2fef to 20215b7 Compare July 28, 2026 16:51
@antfu
antfu merged commit 969d4ca into main Jul 29, 2026
10 checks passed
@antfu
antfu deleted the fix/embedded-client-base-url branch July 29, 2026 06:54
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.

Embedded client can't connect when the page is served from a different origin

3 participants