question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SSR cache example doesn't work

See original GitHub issue

Bug report

Example https://github.com/zeit/next.js/blob/canary/examples/ssr-caching is broken.

Describe the bug

There are two problems with this app:

  1. http://localhost:3000/blog/first gives 404 page. This seems to be a problem with queryParam.
  2. If I fix 1st error, http://localhost:3000/blog/first will return correct blog page but prints following on server console:
(node:95446) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (_http_outgoing.js:485:11)
    at /codes/ssr/ssr-caching-app/node_modules/cacheable-response/index.js:40:9
    at /codes/ssr/ssr-caching-app/node_modules/cacheable-response/index.js:108:5
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:95446) 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(). (rejection id: 2)

It seems that renderToHTML executes end command on the response and cacheable-response tries to add header after this.

To Reproduce

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

  1. Go to https://github.com/zeit/next.js/tree/canary/examples/ssr-caching
  2. Follow steps to setup app.
  3. Run yarn dev
  4. Go to: http://localhost:3000/blog/first
  5. 404 page is returned.

Expected behavior

Blog page should have been returned with no error.

System information

  • OS: macOS
  • Version of Next.js: 9.3
  • Version of Node.js: 10

Additional context

Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:18
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
leanazulyorocommented, Apr 20, 2020

This is a hack, I believe the method app.renderToHTML should return the renderedHTML, but in the meanwhile, this is working for me using LRU cache: https://gist.github.com/leanazulyoro/23c6581fb4379ec311e3bc8538715687

1reaction
enoent4400commented, Apr 19, 2020

@timneutkens @HaNdTriX I can try to investigate this one?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Skip SSR in NextJS when I already have the data cached and ...
Skip SSR in NextJS when I already have the data cached and not stale in the client · 1. Yes, it exists, nextjs.org/docs/routing/shallow-routing....
Read more >
How to cache all pages in Next.js at server side | by Igor Data
Next.js repo at Github has a source code of the example app where it caches SSR'ed pages in the memory. But it caches...
Read more >
Best practices to increase the speed for Next.js apps
In the above example, whenever the user visits the SSR page, the getServerSideProps() ... Next.js has built-in caching so pages load faster.
Read more >
Server-Side Rendering Optimization - Spartacus Documentation
The rendered SSR pages should be cached (for example, using CDN) to ensure subsequent requests do not hit the SSR server. This reduces...
Read more >
How To Avoid SSR Load Issues in Node.js - NodeSource
Our sample application · Initial load test · Making things worse · Watching it blow up · Taking control · Adding a cache...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found