Example https://github.com/zeit/next.js/blob/canary/examples/ssr-caching is broken.
There are two problems with this app:
http://localhost:3000/blog/first gives 404 page. This seems to be a problem with queryParam.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.
Steps to reproduce the behavior, please provide code snippets or a repository:
yarn devhttp://localhost:3000/blog/firstBlog page should have been returned with no error.
Add any other context about the problem here.
@timneutkens seems like app.renderToHTML is actually calling res.end.
Call Stack:
Object.sendPayloadDevServer.renderToHTMLWithComponentsDevServer.renderToHTMLDuplicate of: #11665, #12019
@timneutkens @HaNdTriX I can try to investigate this one?
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
@HaNdTriX @timneutkens to be backward compatible, a flag could be added to not call sendPayload and always return html. I can raise a PR for that.
as https://github.com/zeit/next.js/issues/11665 mentioned, the ERR_HTTP_HEADERS_SENT start at v9.3.1, downgrade to [email protected] fix this warning temporary
Most helpful comment
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