AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Pages Router Does Not Use Updated Cookies From Proxy Response.Cookies.Set()

When using proxy (middleware) to set cookies via response.cookies.set(), Pages Router's getServerSideProps still sees the old cookies from the initial request, whereas App Router's cookies() function correctly reflects the new value. This inconsistency breaks applications relying on middleware-set cookies in getServerSideProps.

highConfidence 70%Next.jsHydrationnext buildServer ActionsAffected V16.2.0-Canary.51

Origin Analysis

The Pages Router data fetching pipeline (getServerSideProps) reads cookies from the original incoming request object (req.cookies) and does not merge or override them with cookies set by middleware on the response. The App Router path was fixed in PR #65008 to read from the middleware-updated request, but Pages Router was not updated accordingly.
1. Create a Next.js app with proxy.ts that sets a cookie via response.cookies.set(). 2. Create a Pages Router page with getServerSideProps that reads ctx.req.cookies. 3. Visit the page; the rendered component shows the old cookie value (or undefined) instead of the new one. Refresh the page and the new value appears because the browser sent the updated cookie.

Fixing Code Block

Edge Case Audit

This change may affect all Pages Router requests that pass through middleware, potentially causing side effects if middleware sets cookies conditionally and the page relies on the original request cookies. Test thoroughly with cookie deletion, multiple cookies, and concurrent requests. Rollback: revert the patch or set an environment flag to disable the merge.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state