Skip to content

Remove setSwapComponent method and cleanup after PR #2379 #2383

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
merged 6 commits into from
Jun 20, 2025

Conversation

pascalbaljet
Copy link
Member

@pascalbaljet pascalbaljet commented Jun 18, 2025

This is a cleanup of PR #2379.

  • isRouterInitialized has been renamed to routerIsInitialized.
  • The routerIsInitialized bool was enough to fix the problem. The additional setSwapComponent logic doesn't seem to provide any benefits. Perhaps this was needed before currentIsInitialPage was introduced, but I can't reproduce it.
  • The setSwapComponent has been removed to prevent introducing another public method on the core router. The swapping of the swapComponent method is now handled internally in App.ts. swapComponent is now simply a variable that gets replaced in the useEffect hook.
  • There was already a test for this (can reload on mount in manual-visits.spec.ts) but in the React implementation it was using a setTimeout to overcome the initial problem. The setTimeout is removed now.

@chack1172
Copy link
Contributor

chack1172 commented Jun 18, 2025

@pascalbaljet it was because react was complaining about using setCurrent outside of useEffect caused by the swapComponent called at first render, so checking the variable inside fixed the problema and the setSwapComponent can be safely removed

@pascalbaljet
Copy link
Member Author

@chack1172 Thanks for clarifying!

@pascalbaljet
Copy link
Member Author

Though the tests pass, navigation is broken in the Playground with this change, so let's see if there's a solution by using useEffect but without setSwapComponent.

Can't perform a React state update on a component that hasn't mounted yet. This indicates that you have a side-effect in your render function that asynchronously later calls tries to update the component. Move this work to useEffect instead.

@pascalbaljet
Copy link
Member Author

I seem to have found a solution by moving the swapComponent method into a ref and then replacing it in the useEffect hook 👌

@pascalbaljet
Copy link
Member Author

Closing this PR as it leads to other problems. Gonna have a fresh look at it.

@pascalbaljet pascalbaljet reopened this Jun 19, 2025
@pascalbaljet
Copy link
Member Author

Moved the variables back outside of the App component again, as well as the swapComponent method, which now gets replaced in the useEffect hook.

@chack1172
Copy link
Contributor

It seems working fine!

@pascalbaljet pascalbaljet merged commit c76f35b into master Jun 20, 2025
10 checks passed
@pascalbaljet pascalbaljet deleted the cleanup-router-init branch June 20, 2025 07:38
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