bjoluc / next-redux-cookie-wrapper

Sync a subset of your Redux state with cookies in Next.js :cookie: :sparkles:
MIT License
114 stars 4 forks source link

Bug: "Cannot set headers after they are sent to the client" #39

Open sbue opened 2 years ago

sbue commented 2 years ago

Hey all, anyone come across this issue? Not sure how to reproduce / where to start

listenerMiddleware/error Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at new NodeError (node:internal/errors:372:5)
    at Proxy.setHeader (node:_http_outgoing:576:11)
    at Object.setCookie (/Users/username/project/node_modules/nookies/dist/index.js:89:17)
    at StateCookies.set (/Users/username/project/node_modules/next-redux-cookie-wrapper/dist/next-redux-cookie-wrapper.cjs.development.js:217:13)
    at /Users/username/project/node_modules/next-redux-cookie-wrapper/dist/next-redux-cookie-wrapper.cjs.development.js:386:29
    at /Users/username/project/node_modules/next-redux-cookie-wrapper/dist/next-redux-cookie-wrapper.cjs.development.js:250:22
    at Immer.produce (/Users/username/project/node_modules/immer/dist/immer.cjs.development.js:792:20)
    at walkState (/Users/username/project/node_modules/next-redux-cookie-wrapper/dist/next-redux-cookie-wrapper.cjs.development.js:246:11)
    at /Users/username/project/node_modules/next-redux-cookie-wrapper/dist/next-redux-cookie-wrapper.cjs.development.js:382:17
    at /Users/username/project/node_modules/@reduxjs/toolkit/dist/redux-toolkit.cjs.development.js:1792:22 {
  code: 'ERR_HTTP_HEADERS_SENT'
} { raisedBy: 'effect' }
bjoluc commented 2 years ago

Hi @sbue,

I remember #25 was related to this. My answer there should apply to you as well. I'll think about preventing this error and logging a helpful error message instead.