Skip to content

Initialize router before components in React #2379

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

Merged

Conversation

chack1172
Copy link
Contributor

@chack1172 chack1172 commented Jun 14, 2025

As reported in #2366 if we try to run make a request with router inside a useEffect() and the page is the first page loaded it will fail because router is not initialized yet because of how react executes the order of useEffects (bottom to top).

To fix it I splitted the router init, adding a setter for the swapComponent handler to set it inside an useEffect (mandatory).

@chack1172 chack1172 marked this pull request as draft June 14, 2025 01:36
@chack1172 chack1172 marked this pull request as ready for review June 14, 2025 02:39
@pascalbaljet pascalbaljet merged commit 8f1f0d4 into inertiajs:master Jun 17, 2025
6 checks passed
@pascalbaljet
Copy link
Member

Confirmed this fixes it. Thanks!

@pascalbaljet
Copy link
Member

Follow-up in #2379

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants