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
-
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.
![image](https://private-user-images.githubusercontent.com/21173275/343746173-6d76d146-ceb9-45ac-8428-50043c70057c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQzMTYxOTcsIm5iZiI6MTcyNDMxNTg5NywicGF0aCI6Ii8yMTE3MzI3NS8zNDM3NDYxNzMtNmQ3NmQxNDYtY2ViOS00NWFjLTg0MjgtNTAwNDNjNzAwNTdjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIyVDA4MzgxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNlNWY1ZjgwNGVlZjAwNTk3MmY3ZWUyOGMzNTVkZjhlODlhYmIyZmMyNDlmNDdiODlhNjk4NzU3MTM1MGY0ZWQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.QzuTPN2V95x9EBcjMWpoV2vIDe1WMT5qeP1_-QVHh4Y)
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:
![image](https://private-user-images.githubusercontent.com/21173275/343739040-7267f5d6-4ca8-4001-b982-565f738191fa.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQzMTYxOTcsIm5iZiI6MTcyNDMxNTg5NywicGF0aCI6Ii8yMTE3MzI3NS8zNDM3MzkwNDAtNzI2N2Y1ZDYtNGNhOC00MDAxLWI5ODItNTY1ZjczODE5MWZhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIyVDA4MzgxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZkZDhhMjJlZjhjZTdkZjRkMTAwNWQ1MDFmZWE5NzczM2Y4MmRhNDEwYzY1NTM4MjM4NTg5NjhkNGRlZmViYTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.8jtmBeSKkEKO2ISwnSnMFgiK9fucagEB8fdUoWkNLX8)
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