TanStack / router

🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering.
https://tanstack.com/router
MIT License
7.19k stars 486 forks source link

fix(react-router): changing path params without specifying the `to` destination #1548

Closed DogPawHat closed 2 weeks ago

DogPawHat commented 2 weeks ago

Add fixes and tests for router.navigate when using the params: (prevParams) => newParams option (with no extra to or from option).

Thanks to @SeanCassiere for the suggestion to patch router.ts

Fixes #1525 Should also fix https://github.com/TanStack/tanstack.com/issues/218

DogPawHat commented 2 weeks ago

I think were golden, the fix has been added.

SeanCassiere commented 2 weeks ago

It's 4.30am here. I'll check this out later and run some tests in the examples.

schiller-manuel commented 2 weeks ago

please update the title of this PR since now this not only adds tests but also fixes a abug

nx-cloud[bot] commented 2 weeks ago

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 4502848359ae6c188db38a8cbb13017baff6b542. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets - [`nx affected --targets=test:format,test:eslint,test:unit,test:build,build --parallel=3`](https://cloud.nx.app/runs/eV7hxNgjLK?utm_source=pull-request&utm_medium=comment) - [`nx affected --target=test:types --exclude=examples/**`](https://cloud.nx.app/runs/JmAvrJ37t8?utm_source=pull-request&utm_medium=comment)

Sent with 💌 from NxCloud.

SeanCassiere commented 2 weeks ago

Tested this locally and can confirm it works.

ruiaraujo012 commented 2 weeks ago

After this release, I'm getting an error when changing the search of a route:

navigate({
    search: { tab: newTab },
});

I have a screen with multiple tabs that are controlled by the search param tab. The first render (navigation) works well /area-reservada/minhas-credenciacoes/credenciacoes/d0efbc00-7ac7-4869-b3af-f6115a9b52ef?tab=estado-pedido, but when I change tabs, it throws an error:

{
    "status": "resolved",
    "routerCode": "BEFORE_LOAD"
}
image

@DogPawHat @SeanCassiere any advice? Is there any way of using the current state of the route (params) if the to and from are not specified? Because if I specify the to it works as pretended.

SeanCassiere commented 2 weeks ago

@ruiaraujo012 please reference this PR and create an issue with a reproduction. I'll check it out over the weekend.

ruiaraujo012 commented 2 weeks ago

Ok, thanks, I'll do it tomorrow.

ruiaraujo012 commented 2 weeks ago

I'm unable to replicate it, I have a complex UI with multiple tabs. Maybe the problem is mine, but it only appears after I update the package, if I roll back it works again. If I put the to prop it works as well.

If I have more time, I'll try to replicate it again closer to what I have on my codebase.

ruiaraujo012 commented 2 weeks ago

Forget what I said, If I use a layout, it causes the error, I'll open an issue with the reproduction.