fix(core): add vite server fallback for embedded connections - #494
Merged
Conversation
@vitejs/devtools
@vitejs/devtools-kit
@vitejs/devtools-oxc
@vitejs/devtools-rolldown
@vitejs/devtools-vite
@vitejs/devtools-vitest
commit: |
Contributor
There was a problem hiding this comment.
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 fromimport.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 againstDEVTOOLS_MOUNT_PATHso 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_PATHhere 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.
webfansplz
force-pushed
the
fix/embedded-client-base-url
branch
from
July 28, 2026 16:51
50c2fef to
20215b7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 candidatefalls 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.