Skip to content

If validateSearch rewrites URL, router nav works but initial load fails (with strange behavior) #1928

@bhaugeea

Description

@bhaugeea

Describe the bug

If the validation function not only validates but also returns something other than what it got (e.g. get empty input, return object with defaults), then the URL gets rewritten and page load fails. When using router navigation the URL is not rewritten and page load is successful.

What I mean by "page load fails": Not sure exactly what is going wrong, but in my repro the manifestation is that throw notFound() gets ignored and the route's match status is erroneously "success".

The repro uses a validateSearch function from the docs so I assume it's supposed to work.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-uyzm48?file=src%2Froutes%2Fposts.%24postId.tsx

Steps to Reproduce the Bug or Issue

  1. Use one of the links to get to a /posts/<something> route (WORKS)
  2. Refresh (DOESN'T WORK)
    • See that it was automatically rewritten to /posts/<something>?page=1&filter=&sort=newest (I think this is the thing that isn't handled well)
  3. Refresh again (WORKS)
    • It wasn't rewritten this time because it was already filled

Expected behavior

Full page load and router navigation should share the same URL rewriting (or non-rewriting) behavior. They should result in the same page behavior as well. A validateSearch function that returns extra defaults or something else not strictly the same as its input should not cause a throw notFound() error to be ignored or any other strange behavior.

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Chrome
  • Version: 126.0.6478.127

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions