next.js: SRS Caching - The caching stopped working after updating the NextJs version
What example does this report relate to?
srs-caching
What version of Next.js are you using?
10.2.1
What version of Node.js are you using?
14.15.1
What browser are you using?
Chrome
What operating system are you using?
Windows
How are you deploying your application?
Custom server - Express
Describe the Bug
The caching stopped working after upgrading from version 10.2.0 to 10.2.1, and there are ajax calls that never finish, although the page loads.
Also, there is an unhandled server-side exception:
(node:2028) UnhandledPromiseRejectionWarning: TypeError: argument entity is required
at etag (E:\dev\apps\sv-smiley\node_modules\etag\index.js:72:11)
at E:\dev\apps\sv-smiley\node_modules\cacheable-response\index.js:93:32
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2028) 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:2028) [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.
Expected Behavior
The response is cached and served. There are no exceptions.
To Reproduce
Copy the example code and try to start the custom server.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (5 by maintainers)
For anyone who wants a quick workaround:
Disabling Next.js built-in compression solves this issue:
Optionally, you could then compress your files using express middleware.
npm install compressionHi, @gokulmhegde,
I’m using Express Js as a Custom Server and the app.render() method of Next Js.
What I noticed is that after updating the version of Next Js, I’m always getting an “undefined” payload
The solution suggested by @awareness481 seems to fix the issue for me and I can confirm that the cache is also working. I tested it by putting a trace in
getmethod ofcachableResponsejust beforeapp.renderwhich only gets called if there is no cached response.Also testing the blog pages via
Postman, I am getting headerX-Cache-StatusasHITafter first call and response time has reduced from>300to<20