router icon indicating copy to clipboard operation
router copied to clipboard

useMatch Invariant failed with react 17

Open kbrah opened this issue 2 years ago • 2 comments

Describe the bug

I'm using React 17. I have const match = useMatch(addRoute.id) in my component. When I navigate to a different route. I get Invariant failed. image Also this error image

My route is like this

export const addRoute = rootRoute.createRoute({
  path: "add",
  component: Add,
  validateSearch: z
    .object({
      ids: z.array(z.string()).optional(),
    })
    .optional(),
});

The navigation and all the functionality works however.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-nyjcvm?file=src/main.tsx

Steps to Reproduce the Bug or Issue

In the basic example, change the React version to 17. (done in the linked stackblitz) Navigate from posts to home tab

Expected behavior

no errors

Screenshots or Videos

No response

Platform

  • OS: Linux
  • Browser: Chromium
  • Version: 0.0.1-beta.36

Additional context

No response

kbrah avatar Dec 08 '22 12:12 kbrah

You can use useMatch(addRoute.id, {strict: false }) if you do not always expect your route to match, it will return optional result.

Xazzzi avatar Dec 09 '22 00:12 Xazzzi

I do expect it to always match. Anyways if I add strict: false, I still get a lot of errors in the console.

kbrah avatar Dec 09 '22 10:12 kbrah

Fixed now.

tannerlinsley avatar Feb 06 '23 04:02 tannerlinsley