fastify / fastify-nextjs

React server side rendering support for Fastify with Next
Other
528 stars 62 forks source link

nextRenderError is not working #1011

Open breftejk opened 3 months ago

breftejk commented 3 months ago

Prerequisites

Fastify version

4.28.0

Plugin version

10.0.1

Node.js version

22.2.0

Operating system

macOS

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

15.0

Description

I am unable to get @fastify/nextjs to render an error page.

Everything else works perfectly, except for the error page rendering.

The error handler is being called, and it logs “error handler called”. However, the request keeps loading indefinitely until it eventually times out.

I have tried various approaches, such as returning the error, making the error a string, returning JSON, and more. Despite these efforts, the request just hangs without any further errors.

Here is my code:

import type { Theme } from "@discord-dashboard/typings";
import type { Dashboard } from "@discord-dashboard/core";

import FastifyNextJS from "@fastify/nextjs";
import * as path from "node:path";

export default class BaseTheme extends Theme {
    name = "Base";

    async Initialize(dashboard: Dashboard) {
        await dashboard.fastify.register(FastifyNextJS, {
            logLevel: dashboard.Environment.log_level,
            dir: path.join(__dirname, "../")
        });

        dashboard.fastify.next('/fugg', async (app, request, reply) => {
            throw new Error("me");
        });

        dashboard.fastify.setErrorHandler(async (error, request, reply) => {
            console.log("error handler called");
            await reply.nextRenderError(error);
        });
    }
}

Link to code that reproduces the bug

No response

Expected Behavior

It is expected to render an error page.

mcollina commented 3 months ago

I have a rough feeling we would need to deprecate this module. Some of the intricacies of Next.js are too hard to overcome :(.