T
TanStack3mo ago
solid-orange

Unable to navigate within a useEffect

I'm in a useEffect and calling navigate() , but nothing happens. I've tried calling navigate() via useNavigate() and redirect(). The strange thing is that when I save a file to kick HMR, then the navigation kicks in. I am navigating from '/xx/onboarding' to '/x', one level back, in case that has something to do with it. I am using Tanstack Start and Vite, e.g. already done the devinxi migration. Not sure if this was happening pre-devinxi or not. My versions: "@tanstack/react-router": "^1.121.27", "@tanstack/react-router-devtools": "^1.121.27", "@tanstack/react-start": "^1.121.32",
No description
6 Replies
unwilling-turquoise
unwilling-turquoise3mo ago
can you log this before the if statement ?
No description
unwilling-turquoise
unwilling-turquoise3mo ago
also, is there no way for you to put that in the route loader instead ?
solid-orange
solid-orangeOP3mo ago
Yeah, we're definitely entering the navigate call - I did add logs inside the statement to verify that. And no, the member is actually streamed in with SSE. When "has_completed_onboarding" changes, we'll navigate.
unwilling-turquoise
unwilling-turquoise3mo ago
then i would do that check in the SSE handler, not a useEffect no need for double rerenders if that member is a global state, that means you're updating it somewhere (ie the SSE handler): do the navigation there
solid-orange
solid-orangeOP3mo ago
While I appreciate the suggestion @notKamui and definitely agree, I wasn't trying to get help with React best practices. Regardless of where those functions are called in the state we're in, the navigation doesn't take place. I just noticed a warning now, not sure if that appeared after I updated all our deps. "Could not find match for from: /$workspace/onboarding" The user is on /$workspace/onboarding when the navigate() call takes place, and is navigatin to /$workspace. I've figured it out. There was an instant navigation back to /$workspace/onboarding so we never saw /$workspace navigated to.
unwilling-turquoise
unwilling-turquoise3mo ago
glad you worked it out the warning is a known bug btw ; but it seems to be nothing more than a warning

Did you find this page helpful?