Skip to content

Commit

Permalink
revert dynamic routes render change
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jun 17, 2022
1 parent 9d078d2 commit 2bd30cf
Showing 1 changed file with 74 additions and 21 deletions.
95 changes: 74 additions & 21 deletions packages/next/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1761,35 +1761,88 @@ export default abstract class Server<ServerOptions extends Options = Options> {
const bubbleNoFallback = !!query._nextBubbleNoFallback
delete query._nextBubbleNoFallback

let result
let error
let page = pathname
let params: Params | undefined = undefined
const getOriginalappPath = (appPath: string) => {
if (this.nextConfig.experimental.appDir) {
const originalappPath = this.appPathRoutes?.[appPath]

// Ensure a request to the URL /accounts/[id] will be treated as a dynamic
// route correctly and not loaded immediately without parsing params.
if (!isDynamicRoute(page)) {
try {
result = await this.renderPage(ctx, params, page, bubbleNoFallback)
if (result) return result
if (!originalappPath) {
return null
}

if (this.dynamicRoutes) {
for (const dynamicRoute of this.dynamicRoutes) {
params = dynamicRoute.match(page) || undefined
if (params) {
page = dynamicRoute.page
break
return originalappPath
}
return null
}

try {
// Ensure a request to the URL /accounts/[id] will be treated as a dynamic
// route correctly and not loaded immediately without parsing params.
if (!isDynamicRoute(pathname)) {
const appPath = getOriginalappPath(pathname)

if (typeof appPath === 'string') {
page = appPath
}
const result = await this.findPageComponents(page, query)
if (result) {
try {
return await this.renderToResponseWithComponents(ctx, result)
} catch (err) {
const isNoFallbackError = err instanceof NoFallbackError

if (!isNoFallbackError || (isNoFallbackError && bubbleNoFallback)) {
throw err
}
}
}
result = await this.renderPage(ctx, params, page, bubbleNoFallback)
if (result) return result
} catch (err) {
error = err
}
}

if (error) {
if (this.dynamicRoutes) {
for (const dynamicRoute of this.dynamicRoutes) {
const params = dynamicRoute.match(pathname)
if (!params) {
continue
}
page = dynamicRoute.page
const appPath = getOriginalappPath(page)

if (typeof appPath === 'string') {
page = appPath
}

const dynamicRouteResult = await this.findPageComponents(
page,
query,
params
)
if (dynamicRouteResult) {
try {
return await this.renderToResponseWithComponents(
{
...ctx,
pathname: page,
renderOpts: {
...ctx.renderOpts,
params,
},
},
dynamicRouteResult
)
} catch (err) {
const isNoFallbackError = err instanceof NoFallbackError

if (
!isNoFallbackError ||
(isNoFallbackError && bubbleNoFallback)
) {
throw err
}
}
}
}
}
} catch (error) {
const err = getProperError(error)
if (err instanceof NoFallbackError && bubbleNoFallback) {
throw err
Expand Down

0 comments on commit 2bd30cf

Please sign in to comment.