-
Notifications
You must be signed in to change notification settings - Fork 27.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Rendered more hooks than during previous render" when using router.replace
#63121
Comments
router.replace
+1 |
I have dig into this issue and found that call of 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 |
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.
And the page at
|
This comment has been minimized.
This comment has been minimized.
My error stack here
|
/**
* The global router that wraps the application components.
*/
function Router({
actionQueue,
assetPrefix,
}: {
actionQueue: AppRouterActionQueue
assetPrefix: string
}) {
const [state, dispatch] = useReducer(actionQueue)
const { canonicalUrl } = useUnwrapState(state)
// Add memoized pathname/query for useSearchParams and usePathname.
const { searchParams, pathname } = useMemo(() => { // <-- this line
const url = new URL(
canonicalUrl,
typeof window === 'undefined' ? 'http://n' : window.location.href
)
return {
// This is turned into a readonly class in `useSearchParams`
searchParams: url.searchParams,
pathname: hasBasePath(url.pathname)
? removeBasePath(url.pathname)
: url.pathname,
}
}, [canonicalUrl]) |
@himself65 did you solve this? |
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
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023 Binaries: Node: 20.11.0 npm: 10.2.4 Yarn: 1.22.19 pnpm: 8.15.1 Relevant Packages: next: 14.1.0 eslint-config-next: 14.1.0 react: 18.2.0 react-dom: 18.2.0 typescript: 5.3.3 Next.js Config: output: N/A
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
The text was updated successfully, but these errors were encountered: