77 createWebSocketModuleRunnerTransport ,
88 normalizeModuleRunnerTransport ,
99} from '../shared/moduleRunnerTransport'
10- import { wrapId } from '../shared/utils'
10+ import { moduleUrlToBrowserUrl } from '../shared/utils'
1111import type { BundledDevHMRClient } from './bundledDevHmrClient'
1212import { ErrorOverlay , cspNonce , overlayId } from './overlay'
1313// @ts -expect-error internal virtual module
@@ -140,10 +140,6 @@ const debounceReload = (time: number) => {
140140}
141141export const pageReload = debounceReload ( 20 )
142142
143- function wrapIdIfNeeded ( id : string ) : string {
144- return id [ 0 ] === '.' || id [ 0 ] === '/' ? id : wrapId ( id )
145- }
146-
147143const hmrClient = new HMRClient (
148144 {
149145 error : ( err ) => console . error ( '[vite]' , err ) ,
@@ -157,15 +153,11 @@ const hmrClient = new HMRClient(
157153 isWithinCircularImport,
158154 } ) {
159155 const [ acceptedPathWithoutQuery , query ] = acceptedPath . split ( `?` )
160- const browserPath = wrapIdIfNeeded ( acceptedPathWithoutQuery )
161- const importPromise = import (
162- /* @vite -ignore */
163- base +
164- browserPath . slice ( 1 ) +
165- `?${ explicitImportRequired ? 'import&' : '' } t=${ timestamp } ${
166- query ? `&${ query } ` : ''
167- } `
168- )
156+ const moduleUrl = `${ acceptedPathWithoutQuery } ?${ explicitImportRequired ? 'import&' : '' } t=${ timestamp } ${
157+ query ? `&${ query } ` : ''
158+ } `
159+ const browserUrl = moduleUrlToBrowserUrl ( moduleUrl , base )
160+ const importPromise = import ( /* @vite -ignore */ browserUrl )
169161 if ( isWithinCircularImport ) {
170162 importPromise . catch ( ( ) => {
171163 console . info (
@@ -244,9 +236,8 @@ async function handleMessage(payload: HotPayload) {
244236 return
245237 }
246238
247- const newPath = `${ base } ${ searchUrl . slice ( 1 ) } ${
248- searchUrl . includes ( '?' ) ? '&' : '?'
249- } t=${ timestamp } `
239+ const moduleUrl = `${ searchUrl } ${ searchUrl . includes ( '?' ) ? '&' : '?' } t=${ timestamp } `
240+ const browserUrl = moduleUrlToBrowserUrl ( moduleUrl , base )
250241
251242 // rather than swapping the href on the existing tag, we will
252243 // create a new link tag. Once the new stylesheet has loaded we
@@ -255,7 +246,7 @@ async function handleMessage(payload: HotPayload) {
255246 // directly, as the new stylesheet has not yet been loaded.
256247 return new Promise ( ( resolve ) => {
257248 const newLinkTag = el . cloneNode ( ) as HTMLLinkElement
258- newLinkTag . href = new URL ( newPath , el . href ) . href
249+ newLinkTag . href = new URL ( browserUrl , el . href ) . href
259250 const removeOldEl = ( ) => {
260251 el . remove ( )
261252 console . debug ( `[vite] css hot updated: ${ searchUrl } ` )
@@ -605,8 +596,8 @@ export function removeStyle(id: string): void {
605596 }
606597}
607598
608- export function createHotContext ( ownerPath : string ) : ViteHotContext {
609- return new HMRContext ( hmrClient , ownerPath )
599+ export function createHotContext ( moduleUrl : string ) : ViteHotContext {
600+ return new HMRContext ( hmrClient , moduleUrl )
610601}
611602
612603/**
0 commit comments