Skip to content

ensure router.reload data replaces query params #2416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

HamidRezaLS
Copy link

PR fixes a bug where router.reload({ data: { ... } }) would incorrectly merge new data with existing query string parameters instead of replacing them.

The Problem:
The old behavior was unpredictable and led to incorrect state. During local testing, I observed the following scenario:

  1. A page loads with a prop, for example items: [1, 2].
  2. A reload is triggered with data: { items: [3, 4] }. The props correctly update to ['3', '4'].
  3. A second reload is then triggered with data: { items: [99] }.
  4. The Bug: The props incorrectly become ['99', '4'], because the items[1]=4 parameter from the previous URL was not cleared during the new request.

This change modifies how GET requests handle the data option. The provided data object is now treated as the single source of truth for the new query string, completely overwriting any old parameters.

For developers using Inertia, this makes the router.reload function significantly more predictable and easier to reason about, which helps prevent unexpected behavior in applications.

I've also confirmed that this does not change or break the documented behavior of partial reloads. This fix only affects how the request URL is constructed in url.ts. The client-side prop merging that handles only and except is a separate process and remains untouched.

Fixes: #2285

Fixes the bug where 
outer.reload would merge new data
with existing query params instead of replacing them.

With this change, the provided data object is now treated
as the single source of truth for the new query string, which
makes the behavior predictable.

Fixes: #2285
@pascalbaljet
Copy link
Member

pascalbaljet commented Jul 2, 2025

Thanks for this! Your change also removes other keys from the query string, so I've opened PR #2417 to handle it more gracefully.

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.

router.reload with data containing arrays gets accumulated instead of replaced
2 participants