fix(proxy): strip malformed Next-Router-State-Tree headers #70
Merged
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
zachsmith1
approved these changes
Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After deployments, clients that had the login page open retain stale router state.
When they navigate, Next.js App Router sends an RSC request with a malformed
Next-Router-State-Treeheader — specifically[""]instead of the full routingtree. Next.js fails to parse this and throws an unhandled error:
This surfaces on the
/(main)/(illustration)/loginname/pageroute and is trackedin Sentry:
https://sentry.prod.env.datum.net/organizations/sentry/issues/1918/events/105a342aff4e46f8946d950cb8c6a6bc/
Fix
Added a check in
proxy.tsthat validates theNext-Router-State-Treeheaderbefore the request reaches the Next.js rendering pipeline. If the value cannot be
parsed as JSON or is structurally incomplete (fewer than 2 elements), the RSC-related
headers (
Next-Router-State-Tree,Rsc,Next-Router-Prefetch) are stripped.Without these headers, Next.js falls back to a full SSR page render, which resets
the client's router state and serves the page correctly.
Impact on normal users
Next-Router-State-Treeheader present, code is a no-op.