-
Notifications
You must be signed in to change notification settings - Fork 503
Prevent duplicate render of the initial page in React #2377
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
Conversation
Broken after merging #2379, investigating now. |
@pascalbaljet what is broken? I tried your change with both using my variable or an entra variable and it works fine |
@chack1172 I'm not sure yet, but the CI fails: https://github.com/inertiajs/inertia/actions/runs/15702617146/job/44240823829 Both variants work locally, so I hope it's just a CI issue and not some timing issue due to the CI being slow. |
@pascalbaljet I found the issue. In playwright tests, the dump function in router.init() is called at first render, instead of the swap component set later on useEffect. In browser it works correctly and call the correct swapComponent. |
@chack1172 Thanks, got it! |
@pascalbaljet you reverted the variable back inside the App component, this can cause issues |
Whoops! Thanks for pointing out, I've opened #2381 for this. |
This took some serious debugging, but I found the reason why the React package renders the initial page twice!
If you follow in the core package:
router.init()
=>InitialVisit.handle()
=>InitialVisit.handleDefault()
, thenhandleDefault
will callset()
on thecurrentPage
page instance. At the end of that method, it will callthis.swap
which essentially calls theswapComponent
callback from the packages.So, in the React package we have:
This would call
setCurrent
but with the same object as that was initially set inuseState()
, which then leads to a rerender. I've introduced acurrentIsInitialPage
variable to prevent this from happening, just once on the initial page.