From c2e36422957868aa44e01671fe65226b00d51489 Mon Sep 17 00:00:00 2001 From: lilnasy <69170106+lilnasy@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:39:02 +0000 Subject: [PATCH] avoid extra variable --- packages/astro/src/core/app/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 4cd7753806b94..3dce1d9e32243 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -272,7 +272,6 @@ export class App { return this.#mergeResponses(response, originalResponse, override); } const mod = await this.#getModuleForRoute(errorRouteData); - let usedMiddleware = false; try { const newRenderContext = await this.#createRenderContext( url, @@ -284,16 +283,16 @@ export class App { const page = (await mod.page()) as any; if (runMiddleware && mod.onRequest) { this.#pipeline.setMiddlewareFunction(mod.onRequest as MiddlewareEndpointHandler); - usedMiddleware = true; } if (!runMiddleware) { + // make sure middleware set by other requests is cleared out this.#pipeline.unsetMiddlewareFunction(); } const response = await this.#pipeline.renderRoute(newRenderContext, page); return this.#mergeResponses(response, originalResponse); } catch { // Middleware may be the cause of the error, so we try rendering 404/500.astro without it. - if (runMiddleware && usedMiddleware) { + if (runMiddleware && mod.onRequest) { return this.#renderError(request, { status, response: originalResponse, runMiddleware: false }); } }