Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app.render returns undefined in SSR cache example #16372

Closed
prasanna1211 opened this issue Aug 20, 2020 · 3 comments
Closed

app.render returns undefined in SSR cache example #16372

prasanna1211 opened this issue Aug 20, 2020 · 3 comments
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@prasanna1211
Copy link

prasanna1211 commented Aug 20, 2020

Bug report

Describe the bug

In the SSR cache example, exactly in this line the data seems to be undefined when debugging. Because of this the SSR response couldn't be cached.

const ssrCache = cacheableResponse({
  ttl: 1000 * 60 * 60, // 1hour
  get: async ({ req, res }) => {

   // --> The value of data is always null
    const data = await app.render(req, res, req.path, {
      ...req.query,
      ...req.params,
    })

    // Add here custom logic for when you do not want to cache the page, for
    // example when the page returns a 404 status code:
    if (res.statusCode === 404) {
      res.end(data)
      return
    }

    return { data }
  },
  send: ({ data, res }) => res.send(data),
})

The value of data should actually be the response HTML that gets cached.

To Reproduce

1. curl https://codeload.github.com/vercel/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/ssr-caching
2. cd ssr-caching
3. npm install and npm run dev

Expected behavior

The value of data should actually be the response HTML that gets cached in the next step.

Screenshots

Screenshot 2020-08-20 at 10 57 07 AM

Screenshot 2020-08-20 at 10 56 58 AM

System information

  • OS: Mac OS
  • Browser: Chrome
  • Version of Next.js: 9.5.2
  • Version of Node.js: 12.16.3

Additional context

An unhandledPromiseRejection error is thrown due to the data being undefined.

@prasanna1211 prasanna1211 changed the title app.render returns null in SSR cache example app.render returns undefined in SSR cache example Aug 20, 2020
@timneutkens timneutkens added the good first issue Easy to fix issues, good for newcomers label Aug 21, 2020
@SiZapPaaiGwat
Copy link

Yeah, got the same problem.The example does not work.

@leerob
Copy link
Member

leerob commented Feb 7, 2021

#18786

@leerob leerob closed this as completed Feb 7, 2021
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants