From d4f62e474b6860f0625173ce8ff4501bd3af7ad2 Mon Sep 17 00:00:00 2001 From: patak Date: Tue, 17 Oct 2023 11:45:12 +0200 Subject: [PATCH] fix: avoid --open optimization if preTransformRequests is disabled (#14666) --- packages/vite/src/node/server/index.ts | 41 ++++++++++++++------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 5a8ad8997101f1..e887ce2e6ba793 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -451,27 +451,30 @@ export async function _createServer( // We know the url that the browser would be opened to, so we can // start the request while we are awaiting the browser. This will // start the crawling of static imports ~500ms before. - setTimeout(() => { - httpGet( - path, - { - headers: { - // Allow the history middleware to redirect to /index.html - Accept: 'text/html', + // preTransformRequests needs to be enabled for this optimization. + if (server.config.server.preTransformRequests) { + setTimeout(() => { + httpGet( + path, + { + headers: { + // Allow the history middleware to redirect to /index.html + Accept: 'text/html', + }, }, - }, - (res) => { - res.on('end', () => { - // Ignore response, scripts discovered while processing the entry - // will be preprocessed (server.config.server.preTransformRequests) + (res) => { + res.on('end', () => { + // Ignore response, scripts discovered while processing the entry + // will be preprocessed (server.config.server.preTransformRequests) + }) + }, + ) + .on('error', () => { + // Ignore errors }) - }, - ) - .on('error', () => { - // Ignore errors - }) - .end() - }, 0) + .end() + }, 0) + } _openBrowser(path, true, server.config.logger) } else {