Skip to content

fix(router-core): handle constructor search fields without throwing - #8350

Open
Tnalxmsk wants to merge 1 commit into
TanStack:mainfrom
Tnalxmsk:fix/router-core-search-constructor
Open

fix(router-core): handle constructor search fields without throwing#8350
Tnalxmsk wants to merge 1 commit into
TanStack:mainfrom
Tnalxmsk:fix/router-core-search-constructor

Conversation

@Tnalxmsk

@Tnalxmsk Tnalxmsk commented Sep 11, 2026

Copy link
Copy Markdown

🎯 Changes

Visiting /?constructor=null with the default search parser throws during client router initialization, before validateSearch can run, even with search.strict: true. Client navigation with the same search value also throws. A JSON constructor object whose prototype.hasOwnProperty is not callable triggers a similar failure.

isPlainObject reads the input's constructor field as constructor metadata. Guard the nullable prototype access and use the existing hasOwn helper instead of calling a method on that metadata.

Add regression coverage for initial loading with strict search validation and for preserving constructor search values during client navigation. The failing inputs were reproduced with @tanstack/react-router@1.170.35 in a production browser bundle; with the fix, the route renders and subsequent navigation works.

Validation

  • Before the fix, three of the five new regression cases fail; all five pass with the fix.
  • Router Core unit tests, all six configured TypeScript checks, lint, and build pass locally. The production browser reproduction also initializes and navigates successfully after the fix.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed router initialization and navigation crashes when search parameters include a constructor field.
    • Search parameters with null, numeric, text, or object values are now safely encoded, parsed, and preserved in the URL and router state.
    • Improved handling of search parameter objects with missing constructors or custom hasOwnProperty values.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 1bbff3ae-bec8-44bd-9a80-afec2ab0920f

📥 Commits

Reviewing files that changed from the base of the PR and between 6494e75 and 47f1db3.

📒 Files selected for processing (3)
  • .changeset/green-areas-shine.md
  • packages/router-core/src/utils.ts
  • packages/router-core/tests/search-constructor.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The router now safely processes search parameters with a constructor key. The plain-object check handles null constructors and objects that shadow hasOwnProperty. Tests cover initial URL parsing and client navigation.

Changes

Constructor search parameter handling

Layer / File(s) Summary
Safe plain-object checks and router coverage
packages/router-core/src/utils.ts, packages/router-core/tests/search-constructor.test.ts, .changeset/green-areas-shine.md
isPlainObject guards missing constructors and uses the shared hasOwn helper. Tests cover constructor values during initialization and navigation. A patch changeset records the fix.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 47f1d

Constructor-valued search parameters are handled safely during router initialization and client navigation, with the reported crash paths covered by tests.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the router-core fix for failures caused by constructor search fields.
Description check ✅ Passed The description explains the failure, implementation, regression tests, validation results, checklist completion, and changeset release impact.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant