can useSearch be used from inside a portal?
I have a component that if the width of the screen is smaller than 992 renders the content inside a portal outside the div that contains the main react app
If I don't use the portal everything works as expected, but if I add the portal, the useSearch works as expected when loading, but, when moving to a different page I get
Could not find a nearest match!
I'm using just strict false as the useSearch parameters, inspecting the error I think I found why this is happening, inside the useMatch function called by the useSearch, its not returning a match (image 1) since my nearestMatchId
is /category/_category/$casual
(which is the page I was previously on) and state.matches
only includes root route and the route im going to.
9 Replies
eastern-cyan•8mo ago
can you provide a minimal complete example please?
itchy-amethystOP•8mo ago
im unable to reproduce in the stackblitz examples environment, but i strip down my code to this and its still happening, any suggestion? i also tried updating tanstack router to the latest version but its still happening


eastern-cyan•8mo ago
you could use
useMatch
directly instead of useSearch
and pass shouldThrow: false
itchy-amethystOP•8mo ago
yea i saw that, its not an ideal solution but should work, but any ideas to why this is happening? thanks for the help!
eastern-cyan•8mo ago
don't know how the portal behaves upon navigation
if you can provide a minimal reproducer, please file a github issue
itchy-amethystOP•8mo ago
using useMatch throws
Uncaught (in promise) Error: Invariant failed: Could not find match for from: /search
thrown from inside the class Router > buildLocation > build
(not the actual useMatch)
also when navigating and only from inside a portal
im navigating from /search to /
@Manuel Schiller this seems to be a preact problem, switched to reactand its fixed
eastern-cyan•8mo ago
great!
itchy-amethystOP•8mo ago
is there anything i can do here? i dont really want to switch to react ATM, ill keep investigating but im not sure this will be something ill be able to fix, can i open a issue for this or is preact not supported?
eastern-cyan•8mo ago
we don't officially support preact
if you find out what the issue is, and there is a reasonable change in router to fix it, we can do it
I would start by producing a minimal complete reproducer that triggers this