Skip to content

Comments

fix: handle undefined children in isSameRoute for sibling layouts#14788

Open
scott-memco wants to merge 2 commits intoremix-run:mainfrom
scott-memco:fix/rsc-sibling-layout-navigation
Open

fix: handle undefined children in isSameRoute for sibling layouts#14788
scott-memco wants to merge 2 commits intoremix-run:mainfrom
scott-memco:fix/rsc-sibling-layout-navigation

Conversation

@scott-memco
Copy link

Summary

Fixes RSC navigation crashing with "can't access property 'every', newRoute.children is undefined" when navigating between routes in sibling layouts.

Root Cause

In isSameRoute() (packages/react-router/lib/router/router.ts), when comparing pathless layout routes during patchRoutesOnNavigation:

  1. The server returns route patches as flat objects without a children property
  2. The "both empty" check (lines 5374-5379) only returns true when both routes lack children
  3. When newRoute.children is undefined but existingRoute.children has items, the condition evaluates to false and falls through to newRoute.children!.every(...) which crashes

Fix

Add an explicit guard after the joint empty-children check: if either route has children but the other doesn't, they are definitively different routes. This prevents the null dereference and is semantically correct — two pathless layouts with mismatched children structures are distinct routes.

// New guard: asymmetric children means different routes
if (!newRoute.children?.length || !existingRoute.children?.length) {
  return false;
}

This also removes the non-null assertion (!) on newRoute.children since the guard guarantees both sides have children at that point.

Reproduction

From the issue's minimal repro:

// This crashes when navigating from route-a to route-b:
layout("layouts/layout-a.tsx", [route("/route-a", "routes/route-a.tsx")]),
layout("layouts/layout-b.tsx", [route("/route-b", "routes/route-b.tsx")]),

Fixes #14777

Made with Cursor

When navigating between routes in sibling layouts via RSC, the server
returns route patches without a children property. In isSameRoute(),
the "both empty" check on lines 5374-5379 only returns true when
both routes lack children. When newRoute.children is undefined but
existingRoute.children has items, execution falls through to the
.every() call which crashes with "can't access property 'every',
newRoute.children is undefined".

Add an explicit guard after the joint empty-children check: if either
route has children but the other doesn't, they are definitively
different routes. This also removes the non-null assertion on
newRoute.children since the guard ensures both sides have children.

Fixes: remix-run#14777
Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot
Copy link

changeset-bot bot commented Feb 8, 2026

⚠️ No Changeset found

Latest commit: 904d43a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Feb 8, 2026

Hi @scott-memco,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

Co-authored-by: Cursor <cursoragent@cursor.com>
@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Feb 8, 2026

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RSC] Navigation fails between sibling layouts with "can't access property 'every', newRoute.children is undefined"

2 participants