router icon indicating copy to clipboard operation
router copied to clipboard

Context is undefined when search validation fails

Open geoff-harper opened this issue 1 year ago • 1 comments

Describe the bug

I've discovered that the missing context bug isn't fully fixed in 1.33.7. Also sorry for sort of spamming the other closed issue, I thought I'd open a new one.

I'm not completely sure of what's triggering it or if there's more cases but these are the steps in my own app

  1. open a route with no search validation (not sure this part is relevant)
  2. directly enter a route into the address bar that has search validation, but don't include any search params in the address
  3. navigate to the route, context should be undefined

My schema catches and fills values like the docs suggest. In step 3 when the error component is fired, it does still put the caught values into the url. I broke the validateSearch method into pieces instead of directly returning a schema, and it specifically fails when anything is returned in the method.

Your Example Website or App

https://stackblitz.com/edit/github-spzf56-us3fam?file=src%2Froutes%2F_layout.index.tsx

Steps to Reproduce the Bug or Issue

  1. Go to the about route
  2. Go to index route through address bar, omit search params

Expected behavior

Context should be defined in all cases

Screenshots or Videos

No response

Platform

  • Browser: all
  • Version: 1.33.7

Additional context

No response

geoff-harper avatar May 23 '24 19:05 geoff-harper

I found this in v1.34.9 as well, causing context to become undefined if the route that throws the redirect has search params that are being validated through validateSearch, and the validation fails/throws (e.g. with zod).

Here's a complete repro: https://stackblitz.com/edit/tanstack-router-qbczsv?file=src%2Froutes%2Findex.tsx

melv-n avatar Jun 03 '24 19:06 melv-n

this will be fixed by #1907

reproducer with the pre-release package: https://stackblitz.com/edit/tanstack-router-93gdrp?file=src%2Froutes%2Findex.tsx

schiller-manuel avatar Jul 06 '24 20:07 schiller-manuel