Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
javivelasco committed Dec 15, 2021
1 parent f672aa6 commit b4b11d0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/next/shared/lib/router/router.ts
Expand Up @@ -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',
Expand All @@ -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
Expand Down

0 comments on commit b4b11d0

Please sign in to comment.