@@ -128,13 +128,6 @@ const processNodeUrl = (
128128) : string => {
129129 // prefix with base (dev only, base is never relative)
130130 const replacer = ( url : string ) => {
131- if ( server ) {
132- const mod = server . environments . client . moduleGraph . urlToModuleMap . get ( url )
133- if ( mod && mod . lastHMRTimestamp > 0 ) {
134- url = injectQuery ( url , `t=${ mod . lastHMRTimestamp } ` )
135- }
136- }
137-
138131 if (
139132 ( url [ 0 ] === '/' && url [ 1 ] !== '/' ) ||
140133 // #3230 if some request url (localhost:3000/a/b) return to fallback html, the relative assets
@@ -153,8 +146,9 @@ const processNodeUrl = (
153146 url = path . posix . join ( config . base , url )
154147 }
155148
156- if ( server && ! isClassicScriptLink && shouldPreTransform ( url , config ) ) {
157- let preTransformUrl : string | undefined
149+ let preTransformUrl : string | undefined
150+
151+ if ( ! isClassicScriptLink && shouldPreTransform ( url , config ) ) {
158152 if ( url [ 0 ] === '/' && url [ 1 ] !== '/' ) {
159153 preTransformUrl = url
160154 } else if ( url [ 0 ] === '.' || isBareRelative ( url ) ) {
@@ -164,16 +158,27 @@ const processNodeUrl = (
164158 url ,
165159 )
166160 }
167- if ( preTransformUrl ) {
168- try {
169- preTransformUrl = decodeURI ( preTransformUrl )
170- } catch {
171- // Malformed uri. Skip pre-transform.
172- return url
173- }
174- preTransformRequest ( server , preTransformUrl , config . decodedBase )
161+ }
162+
163+ if ( server ) {
164+ const mod = server . environments . client . moduleGraph . urlToModuleMap . get (
165+ preTransformUrl || url ,
166+ )
167+ if ( mod && mod . lastHMRTimestamp > 0 ) {
168+ url = injectQuery ( url , `t= ${ mod . lastHMRTimestamp } ` )
175169 }
176170 }
171+
172+ if ( server && preTransformUrl ) {
173+ try {
174+ preTransformUrl = decodeURI ( preTransformUrl )
175+ } catch {
176+ // Malformed uri. Skip pre-transform.
177+ return url
178+ }
179+ preTransformRequest ( server , preTransformUrl , config . decodedBase )
180+ }
181+
177182 return url
178183 }
179184
0 commit comments