ensure router.reload data replaces query params #2416
Closed
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.
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:
items: [1, 2]
.data: { items: [3, 4] }
. The props correctly update to['3', '4']
.data: { items: [99] }
.['99', '4']
, because theitems[1]=4
parameter from the previous URL was not cleared during the new request.This change modifies how
GET
requests handle thedata
option. The provideddata
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 handlesonly
andexcept
is a separate process and remains untouched.Fixes: #2285