#Unable to navigate within a useEffect

10 messages · Page 1 of 1 (latest)

hard barn
#

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",

stable terrace
#

can you log this before the if statement ?

#

also, is there no way for you to put that in the route loader instead ?

hard barn
stable terrace
#

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

hard barn
#

While I appreciate the suggestion @stable terrace 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.

hard barn
#

I've figured it out. There was an instant navigation back to /$workspace/onboarding so we never saw /$workspace navigated to.

stable terrace
#

glad you worked it out