#Custom server renderToHTML does not work with next 13.5.1

2 messages · Page 1 of 1 (latest)

dreamy sparrow
#

Link to the code that reproduces this issue or a replay of the bug
https://github.com/thilohaas/nextjs-custom-server/tree/main
https://codesandbox.io/p/github/thilohaas/nextjs-custom-server/main

To Reproduce

  1. Start a new nextjs project with npx create-next-app@latest
  2. Add a server.js https://github.com/thilohaas/nextjs-custom-server/blob/main/server.js
  3. Change the package.json dev script to: "dev": "node server.js",
  4. run npm run dev
  5. open http://localhost:3001
    Current vs. Expected behavior
    I expect it to display the welcome page but instead i get an error from the next server:

Error: Invariant ensurePage called outside render worker

For me this problem is also related to this one: https://github.com/vercel/next.js/issues/53466
Obstacles have appeared in large projects with their own infrastructure (Kube).
These problems are associated with the use of Custom-Server, which is a great need for additional collection of metrics, custom logging, control of response headers and status, etc. I also need the ability to run in one thread so that the AsyncLocalStorage context is saved and other global mechanics work.

On versions higher than 13.4.12 (I confirm, the problem appears with 13.4.13-canary.0) it became impossible to create a custom-server. Now when calling methods, and even render, I get errors when calling server methods: Invariant ... called outside render worker.

The Next server is initializing, but it seems to be isolated from my Fastify server, or the new code is broken.
It seems to me that vercel-team added these changes that affected an important part of the community.

GitHub

Created with CodeSandbox. Contribute to thilohaas/nextjs-custom-server development by creating an account on GitHub.

GitHub

Created with CodeSandbox. Contribute to thilohaas/nextjs-custom-server development by creating an account on GitHub.

GitHub

Verify canary release I verified that the issue exists in the latest Next.js canary release Provide environment information Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Versi...

neat ginkgoBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)