From b4b11d0967df41d934009d2249d0316aac767f86 Mon Sep 17 00:00:00 2001 From: Javi Velasco Date: Wed, 15 Dec 2021 12:04:20 +0100 Subject: [PATCH] Bug fix --- packages/next/shared/lib/router/router.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/next/shared/lib/router/router.ts b/packages/next/shared/lib/router/router.ts index 2d4826e278fa83a..14bb4adb5a5e2d6 100644 --- a/packages/next/shared/lib/router/router.ts +++ b/packages/next/shared/lib/router/router.ts @@ -1133,12 +1133,14 @@ export default class Router implements BaseRouter { resolvedAs = delLocale(delBasePath(resolvedAs), this.locale) + const route = removePathTrailingSlash(pathname) + /** - * If the route update was triggered for client-side hydration then - * do not check the preflight request. Otherwise when rendering - * a page with refresh it might get into an infinite loop. + * If the route update was triggered for client-side hydration and + * the rendered route is not dynamic do not check the preflight + * request as it is not necessary. */ - if ((options as any)._h !== 1) { + if ((options as any)._h !== 1 || isDynamicRoute(route)) { const effect = await this._preflightRequest({ as, cache: process.env.NODE_ENV === 'production', @@ -1158,14 +1160,12 @@ export default class Router implements BaseRouter { } else if (effect.type === 'redirect' && effect.destination) { window.location.href = effect.destination return new Promise(() => {}) - } else if (effect.type === 'refresh') { + } else if (effect.type === 'refresh' && as !== window.location.pathname) { window.location.href = as return new Promise(() => {}) } } - const route = removePathTrailingSlash(pathname) - if (isDynamicRoute(route)) { const parsedAs = parseRelativeUrl(resolvedAs) const asPathname = parsedAs.pathname