Skip to content

Commit

Permalink
catch find page and rendering error thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jun 17, 2022
1 parent b05f2e5 commit 9d078d2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
74 changes: 38 additions & 36 deletions packages/next/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1762,51 +1762,34 @@ export default abstract class Server<ServerOptions extends Options = Options> {
delete query._nextBubbleNoFallback

let result
let error
let page = pathname
let params: Params | undefined = undefined

// map the route to the actual bundle name
const getOriginalAppPath = (appPath: string) => {
if (this.nextConfig.experimental.appDir) {
const originalAppPath = this.appPathRoutes?.[appPath]

if (!originalAppPath) {
return null
}

return originalAppPath
}
return null
}

// 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)) {
const appPath = getOriginalAppPath(page)
if (typeof appPath === 'string') {
page = appPath
}
result = await this.renderPage(ctx, params, page, bubbleNoFallback)
if (result) return result
}
try {
result = await this.renderPage(ctx, params, page, bubbleNoFallback)
if (result) return result

if (this.dynamicRoutes) {
for (const dynamicRoute of this.dynamicRoutes) {
params = dynamicRoute.match(page) || undefined
if (params) {
page = dynamicRoute.page
break
if (this.dynamicRoutes) {
for (const dynamicRoute of this.dynamicRoutes) {
params = dynamicRoute.match(page) || undefined
if (params) {
page = dynamicRoute.page
break
}
}
}
result = await this.renderPage(ctx, params, page, bubbleNoFallback)
if (result) return result
} catch (err) {
error = err
}
}

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

try {
result = await this.renderPage(ctx, params, page, bubbleNoFallback)
if (result) return result
} catch (error) {
if (error) {
const err = getProperError(error)
if (err instanceof NoFallbackError && bubbleNoFallback) {
throw err
Expand Down Expand Up @@ -1862,7 +1845,26 @@ export default abstract class Server<ServerOptions extends Options = Options> {
page: string,
bubbleNoFallback: boolean
) {
// map the route to the actual bundle name
const getOriginalAppPath = (appPath: string) => {
if (this.nextConfig.experimental.appDir) {
const originalAppPath = this.appPathRoutes?.[appPath]

if (!originalAppPath) {
return null
}

return originalAppPath
}
return null
}

const { query } = ctx
const appPath = getOriginalAppPath(page)
if (typeof appPath === 'string') {
page = appPath
}

const result = await this.findPageComponents(page, query, params)
if (result) {
try {
Expand Down
4 changes: 2 additions & 2 deletions packages/next/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1515,8 +1515,8 @@ export default class NextNodeServer extends BaseServer {
}

protected async runEdgeFunction(params: {
req: BaseNextRequest
res: BaseNextResponse
req: BaseNextRequest | NodeNextRequest
res: BaseNextResponse | NodeNextResponse
query: ParsedUrlQuery
params: Params | undefined
page: string
Expand Down

0 comments on commit 9d078d2

Please sign in to comment.