From a8b636d3469cced7a1b6ec5b6e2803ee01088ac5 Mon Sep 17 00:00:00 2001 From: Romuald Brillout Date: Wed, 4 Sep 2024 12:40:27 +0200 Subject: [PATCH] fix: throw error upon wrong vite setup --- vike/node/runtime/renderPage.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/vike/node/runtime/renderPage.ts b/vike/node/runtime/renderPage.ts index c29dff76613..581808afa49 100644 --- a/vike/node/runtime/renderPage.ts +++ b/vike/node/runtime/renderPage.ts @@ -91,6 +91,7 @@ async function renderPage< assertArguments(...arguments) assert(hasProp(pageContextInit, 'urlOriginal', 'string')) assertEnv() + assertIsNotViteRequest(pageContextInit.urlOriginal) if (isIgnoredUrl(pageContextInit.urlOriginal)) { const pageContextHttpResponseNull = getPageContextHttpResponseNull(pageContextInit) @@ -473,16 +474,17 @@ function getRequestId(): number { } function isIgnoredUrl(urlOriginal: string): boolean { - const isViteRequest = urlOriginal.endsWith('/@vite/client') || urlOriginal.startsWith('/@fs/') - assertWarning( + return urlOriginal.endsWith('/favicon.ico') || !isUrl(urlOriginal) +} +function assertIsNotViteRequest(urlOriginal: string) { + const isViteRequest = + urlOriginal.endsWith('/@vite/client') || urlOriginal.startsWith('/@fs/') || urlOriginal.endsWith('/__vite_ping') + assertUsage( !isViteRequest, - `The vike middleware renderPage() was called with the URL ${urlOriginal} which is unexpected because the HTTP request should have already been handled by Vite's development middleware. Make sure to 1. install Vite's development middleware and 2. add Vite's middleware *before* Vike's middleware, see https://vike.dev/renderPage`, - { onlyOnce: true } - ) - return ( - urlOriginal.endsWith('/__vite_ping') || urlOriginal.endsWith('/favicon.ico') || !isUrl(urlOriginal) || isViteRequest + `The vike middleware renderPage() was called with the URL ${urlOriginal} which is unexpected because the HTTP request should have already been handled by Vite's development middleware. Make sure to 1. install Vite's development middleware and 2. add Vite's middleware *before* Vike's middleware, see https://vike.dev/renderPage` ) } + function normalizeUrl(pageContextInit: { urlOriginal: string }, httpRequestId: number) { const { trailingSlash, disableUrlNormalization, baseServer } = getGlobalContext() if (disableUrlNormalization) return null