Skip to content
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

bug: useIsFirstRender broken with NextJs App router #389

Closed
technophile-04 opened this issue Oct 3, 2023 · 1 comment · Fixed by #477
Closed

bug: useIsFirstRender broken with NextJs App router #389

technophile-04 opened this issue Oct 3, 2023 · 1 comment · Fixed by #477
Labels
bug Something isn't working

Comments

@technophile-04
Copy link

technophile-04 commented Oct 3, 2023

Demo :

It seems that useIsFirstRender always returns false in NextJs App router, here is an example :

Screen.Recording.2023-10-03.at.2.48.58.PM.mov

So localhost:8080 serves the page from app dir and localhost:8080/pagedir serves it from pages dir

As we can see when on localhost:8080 useUpdateEffect runs directly instead on localhost:8080/pagedir it does not since its it first render

here is minimal reproducible repo : https://github.com/technophile-04/useIsFirstRender-mrr

Its just a new create-next-app with usehooks-ts installed and utilizing useDarkMode which internally rely's on useIsFirstRender


Possible reason :

Maybe it's because Nextjs might be running useIsFirstRender in server before serving it to client, saying this because I came across this vercel/next.js#52566 (comment) which states some hooks can be ran on server like useId etc and useRef might be one of them 🤔 but I maybe completely wrong here !!

Update :

It seems that disabling reactStrictMode in App router solves the issue but its bad idea to do so :(

@juliencrn
Copy link
Owner

useDarkMode is no longer based on useIsFirstRender, this should be fixed right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants