Skip to content

Unable to render _error page, renders 404 page instead #435

@stefee

Description

@stefee

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

3.25.0

Plugin version

7.0.0

Node.js version

16.13.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

11.6.1

Description

The plugin uses app.render under the hood, which explicitly disallows rendering _app, _document and _error pages:

https://github.com/vercel/next.js/blob/e75361fd03872b097e817634c049b3185f24cf56/packages/next/server/base-server.ts#L1704

Attempting to render the _error path (as described in the readme) results in a 404 Not Found response.

If you need to render with Next.js from within a custom handler (such as an error handler), use reply.nextRender

app.setErrorHandler((err, req, reply) => {
  reply.status(err.statusCode || 500)
  return reply.nextRender('/_error')
})

Steps to Reproduce

See description.

Expected Behavior

The plugin should either:

  1. Decorate the request with the app instance, so that app.renderError can be called manually
  2. Decorate fastify with a reply.nextRenderError which proxies the app.renderError similar to how reply.nextRender works

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions