Skip to content

Commit 103820f

Browse files
authored
fix: missing warmupRequest in transformIndexHtml (#15303)
1 parent 25d7924 commit 103820f

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

packages/vite/src/node/server/middlewares/indexHtml.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ function shouldPreTransform(url: string, config: ResolvedConfig) {
114114

115115
const wordCharRE = /\w/
116116

117+
function isBareRelative(url: string) {
118+
return wordCharRE.test(url[0]) && !url.includes(':')
119+
}
120+
117121
const isSrcSet = (attr: Token.Attribute) =>
118122
attr.name === 'srcset' && attr.prefix === undefined
119123
const processNodeUrl = (
@@ -143,20 +147,30 @@ const processNodeUrl = (
143147
// rewrite `./index.js` -> `localhost:5173/a/index.js`.
144148
// rewrite `../index.js` -> `localhost:5173/index.js`.
145149
// rewrite `relative/index.js` -> `localhost:5173/a/relative/index.js`.
146-
((url[0] === '.' || (wordCharRE.test(url[0]) && !url.includes(':'))) &&
150+
((url[0] === '.' || isBareRelative(url)) &&
147151
originalUrl &&
148152
originalUrl !== '/' &&
149153
htmlPath === '/index.html')
150154
) {
151-
const devBase = config.base
152-
const fullUrl = path.posix.join(devBase, url)
153-
if (server && shouldPreTransform(url, config)) {
154-
preTransformRequest(server, fullUrl, devBase)
155+
url = path.posix.join(config.base, url)
156+
}
157+
158+
if (server && shouldPreTransform(url, config)) {
159+
let preTransformUrl: string | undefined
160+
if (url[0] === '/') {
161+
preTransformUrl = url
162+
} else if (url[0] === '.' || isBareRelative(url)) {
163+
preTransformUrl = path.posix.join(
164+
config.base,
165+
path.posix.dirname(htmlPath),
166+
url,
167+
)
168+
}
169+
if (preTransformUrl) {
170+
preTransformRequest(server, preTransformUrl, config.base)
155171
}
156-
return fullUrl
157-
} else {
158-
return url
159172
}
173+
return url
160174
}
161175

162176
const processedUrl = useSrcSetReplacer

0 commit comments

Comments
 (0)