Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix middleware prefetch cases #43056

Merged
merged 1 commit into from Nov 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 26 additions & 19 deletions packages/next/shared/lib/router/router.ts
Expand Up @@ -2097,13 +2097,13 @@ export default class Router implements BaseRouter {
data?.json && !wasBailedPrefetch
? data
: await fetchNextData({
dataHref:
data?.dataHref ||
this.pageLoader.getDataHref({
href: formatWithValidation({ pathname, query }),
asPath: resolvedAs,
locale,
}),
dataHref: data?.json
? data?.dataHref
: this.pageLoader.getDataHref({
href: formatWithValidation({ pathname, query }),
asPath: resolvedAs,
locale,
}),
isServerRender: this.isSsr,
parseJSON: true,
inflightCache: wasBailedPrefetch ? {} : this.sdc,
Expand Down Expand Up @@ -2272,6 +2272,7 @@ export default class Router implements BaseRouter {
let parsed = parseRelativeUrl(url)

let { pathname, query } = parsed
const originalPathname = pathname

if (process.env.__NEXT_I18N_SUPPORT) {
if (options.locale === false) {
Expand Down Expand Up @@ -2320,10 +2321,13 @@ export default class Router implements BaseRouter {
if (rewritesResult.externalDest) {
return
}
resolvedAs = removeLocale(
removeBasePath(rewritesResult.asPath),
this.locale
)

if (!isMiddlewareMatch) {
resolvedAs = removeLocale(
removeBasePath(rewritesResult.asPath),
this.locale
)
}

if (rewritesResult.matchedPage && rewritesResult.resolvedHref) {
// if this directly matches a page we need to update the href to
Expand Down Expand Up @@ -2365,7 +2369,10 @@ export default class Router implements BaseRouter {
fetchData: () =>
fetchNextData({
dataHref: this.pageLoader.getDataHref({
href: formatWithValidation({ pathname, query }),
href: formatWithValidation({
pathname: originalPathname,
query,
}),
skipInterpolation: true,
asPath: resolvedAs,
locale,
Expand Down Expand Up @@ -2408,13 +2415,13 @@ export default class Router implements BaseRouter {
this.pageLoader._isSsg(route).then((isSsg) => {
return isSsg
? fetchNextData({
dataHref:
data?.dataHref ||
this.pageLoader.getDataHref({
href: url,
asPath: resolvedAs,
locale: locale,
}),
dataHref: data?.json
? data?.dataHref
: this.pageLoader.getDataHref({
href: url,
asPath: resolvedAs,
locale: locale,
}),
isServerRender: false,
parseJSON: true,
inflightCache: this.sdc,
Expand Down