SSR cache example doesn't work
See original GitHub issueBug 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:
http://localhost:3000/blog/firstgives 404 page. This seems to be a problem with queryParam.- If I fix 1st error,
http://localhost:3000/blog/firstwill 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:
- Go to https://github.com/zeit/next.js/tree/canary/examples/ssr-caching
- Follow steps to setup app.
- Run
yarn dev - Go to:
http://localhost:3000/blog/first - 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:
- Created 3 years ago
- Reactions:18
- Comments:7 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This is a hack, I believe the method
app.renderToHTMLshould return the renderedHTML, but in the meanwhile, this is working for me using LRU cache: https://gist.github.com/leanazulyoro/23c6581fb4379ec311e3bc8538715687@timneutkens @HaNdTriX I can try to investigate this one?