Open mynameisankit opened 8 months ago
+1
I have dig into this issue and found that call of useThenable
inside of use
hook doesn't seem to work properly.
So, I tried change the implementation of useUnwrapState like this in my local machine, it worked.
function useUnwrapState(_state: ReducerState): AppRouterState {
const [state, setState] = useState(_state);
useEffect(()=>{
if (isThenable(_state)) {
_state.then(setState);
} else {
setState(_state)
}
}, [_state])
return state
}
Maybe is it related to use
hook and startTransition
issue?
We're seeing this with a component that renders nothing and only redirects where another component is calling router.replace. Probably not the best code but still feels like we shouldn't see a varying amount of hooks rendering.
export default function OnboardingCheckComplete({
onboardingStatus,
}: {
onboardingStatus: OnboardingStatus
}) {
const router = useRouter()
const pathname = usePathname()
useEffect(() => {
if (
pathname !== "/onboarding/welcome" &&
onboardingStatus.onboarding.currentStep === OnboardingStatusComplete
) {
router.replace("/onboarding/welcome")
router.refresh()
}
}, [pathname, onboardingStatus.onboarding.currentStep, router])
}
And the page at /onboarding
export default async function OnboardingPage() {
const status = await gateway.onboarding.status.get()
if (status.onboarding.currentStep === OnboardingStatusNotStarted) {
redirect("/onboarding/start")
} else {
throw new Error(
`Invalid onboarding status ${status.onboarding.currentStep}`
)
}
}
+1
Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote š on the issue description or subscribe to the issue for updates. Thanks!
Link to the code that reproduces this issue
Link
To Reproduce
<base-url>/versions/v1
Goto Version v2
Current vs. Expected behavior
I expected to be redirected to
<base-url>/versions/v2
but instead a client-side react error is triggered with the following stack traceProvide environment information
Which area(s) are affected? (Select all that apply)
App Router
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)
Additional context
I tested my reproduction on the following versions:-
13.4.19
14.1.0