Next.js: SSR caching example is broken (UnhandledPromiseRejectionWarning: TypeError: argument entity is required)

Created on 31 Aug 2020  路  9Comments  路  Source: vercel/next.js

Bug report

Describe the bug

The SSR caching login is broken with the error below.

(node:14465) UnhandledPromiseRejectionWarning: TypeError: argument entity is required
    at etag (/home/omar/Desktop/ssr-caching-app/node_modules/etag/index.js:72:11)
    at /home/omar/Desktop/ssr-caching-app/node_modules/cacheable-response/index.js:95:32
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:14465) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:14465) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to https://github.com/vercel/next.js/tree/canary/examples/ssr-caching
  2. Run locally
  3. Access the website
  4. See error in the terminal (notice the speed and the missing headers in the response)

Expected behavior

It should cache pages normally.

System information

  • OS: Ubuntu 18.04
  • Browser (if applies): Chrome
  • Version of Next.js: 9.5.2(latest)
  • Version of Node.js: 12.16.2

Additional context

It was working fine on our project, until it didn't when I upgraded to v9.5.2 from v9.5.1
So I thought of testing the official example, just to find out the same issue!

good first issue

Most helpful comment

https://github.com/vercel/next.js/issues/14737#issuecomment-680092517

Refer to @Charioteer鈥榮 ideas

Modify the get method of ssr-caching demo

get: async ({ req, res }) => {
      const rawResEnd = res.end
      const data = await new Promise((resolve) => {
          res.end = (payload) => {
              if (res.statusCode === 200) {
                  resolve(payload)
              } else {
                  resolve()
              }
          }
          app.render(req, res, req.path, {
              ...req.query,
              ...req.params,
          })
      })
      res.end = rawResEnd
      return { data }
},     

Currently we can write like this first 馃槉

Since the response needs to be terminated correctly when the send is executed, the res.end modified in get needs to be restored

All 9 comments

9.5.1 is not working for me 馃槀
a new user of next wants to configure ssr-caching and is very frustrated

Any update on this?

It is related to:

Not sure what is the plan here, is it safe to still use renderToHTML or is it gonna be made private soon

This is so sudden, they've already broke our production application. There should be a quick alternative.

https://github.com/vercel/next.js/issues/14737#issuecomment-680092517

Refer to @Charioteer鈥榮 ideas

Modify the get method of ssr-caching demo

get: async ({ req, res }) => {
      const rawResEnd = res.end
      const data = await new Promise((resolve) => {
          res.end = (payload) => {
              if (res.statusCode === 200) {
                  resolve(payload)
              } else {
                  resolve()
              }
          }
          app.render(req, res, req.path, {
              ...req.query,
              ...req.params,
          })
      })
      res.end = rawResEnd
      return { data }
},     

Currently we can write like this first 馃槉

Since the response needs to be terminated correctly when the send is executed, the res.end modified in get needs to be restored

I have the same error in Next.js rendering with serverless target. I can't see how exactly is this connected to our app code from this stack trace. Is this a problem with the vendor etag package?

Versions are:
Next.js 9.5.3
[email protected]

TypeError: argument entity is required,
            at etag (/var/task/node_modules/next/dist/compiled/etag/index.js:1:738),
            at sendPayload (/var/task/node_modules/next/dist/next-server/server/send-payload.js:1:473),
            at renderReqToHTML (/var/task/pages/_error.js:732:13),
            at processTicksAndRejections (internal/process/task_queues.js:97:5),
            at async Module.render (/var/task/pages/_error.js:801:22),
            at async handleOriginRequest (/var/task/index.js:5531:9),
            at async Runtime.handler$1 [as handler] (/var/task/index.js:5398:20)

I have the same problem.

@ppbl Even with that workaround, the issue still occurs.
Perhaps it's time for Nextjs team to take action.

We rely on renderToHtml in order to modify the raw html server side before sending it to the client, it seems like that鈥檚 on shaky ground. Can we get an alternate solution for rendering out raw HTML using nextjs?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

havefive picture havefive  路  3Comments

kenji4569 picture kenji4569  路  3Comments

renatorib picture renatorib  路  3Comments

irrigator picture irrigator  路  3Comments

formula349 picture formula349  路  3Comments