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

Router.Replace With Shallow:True Persists Shallow Flag In History State, Causing GetServerSideProps To Be Skipped On Browser Back Navigation

When router.replace is called with shallow: true in Next.js Pages Router, the shallow flag is stored in the browser history state. On subsequent browser back navigation to that entry, the router reuses the flag and skips getServerSideProps, rendering stale data.

highConfidence 90%Next.jsPages RouterApp RouterReact Server Components

Origin Analysis

The Next.js router stores the entire options object (including shallow) in window.history.state for both push and replace operations. When handling popstate, the router reads the stored options and applies shallow routing again, causing getServerSideProps to be bypassed on back navigation.
1. Call router.push('/page1') (data fetch occurs). 2. Call router.replace('/page1?count=1', { shallow: true }) (no data fetch, URL updates). 3. Call router.push('/page2') (data fetch occurs). 4. Call router.replace('/page2?count=1', { shallow: true }) (no data fetch). 5. Click browser back to return to '/page1?count=1'. 6. Observe that getServerSideProps is not called and the page shows stale data.

Fixing Code Block

Edge Case Audit

The patch modifies the shape of the history state by overriding the shallow flag. If any custom code or Next.js internal logic relies on reading history.state.options.shallow, it may be affected. However, shallow is not meant to be persisted. The fix is safe for standard navigation but should be thoroughly tested in applications that use custom history management or third-party routing wrappers. To roll back, revert the change to store the original options object. Note that the patch must be applied to the correct Next.js source file and a rebuild is required; using a prebuilt dist may require patching the compiled file, which is not recommended.

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