Loader function is not executed, when optional params are not set. Bug? #1839
Unanswered
itshallrun
asked this question in
Q&A
Replies: 2 comments
-
@SeanCassiere could you please take a brief look at this? Does it deserve a bug report, or is it a misunderstanding on my side? |
Beta Was this translation helpful? Give feedback.
0 replies
-
this will be fixed by #1907 here is your reproducer with the pre-release package: https://stackblitz.com/edit/tanstack-router-cd6bqy?file=src%2Froutes%2F__root.tsx |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I could narrow the issue down, and here is a basic reproduction of it.
When navigation from anything else then tanstack router without setting the optional search params in the URL to at least an empty value, the loader function is not run, and the data is not fetched.
The consecutive Components which rely on the loader data, obviously fail then.
The example is very basic. It has two links. A tanstack link, and a non tanstack link.

Click on both, and you will see that the non Tanstack link, does not execute the loader.
I am using a non tanstack link here, just to visualize, that there is a problem.
The problem also arises, when reloading a page, where the optional search params are missing:
For more examples, here are some videos I recorded with the basic-default-search-params example
Bildschirmaufnahme.2024-06-27.um.11.41.51.mov
router_error2.mov
As you can see, reloading the page, or redirecting with anything other than tanstack link, leads to an error.
In the video I used
window.location.href
for the demonstrationThis is fine
window.location.href = "http://localhost:5174/posts/post?postId=2&color=red¶mWithoutDefault="
Leads to an error
window.location.href = "http://localhost:5174/posts/post?postId=2&color=red"
The error is thrown, because the Loader function is not executed:
This is how it should be, and is when the params are all set:

This is how it looks, when I reload the page and one of the optional params is not set:
It seems like there is a bug with the loader function
Beta Was this translation helpful? Give feedback.
All reactions