Skip to content

memoize router creation using useMemo#1169

Closed
theAnuragMishra wants to merge 1 commit intojoinmarket-webui:develfrom
theAnuragMishra:devel
Closed

memoize router creation using useMemo#1169
theAnuragMishra wants to merge 1 commit intojoinmarket-webui:develfrom
theAnuragMishra:devel

Conversation

@theAnuragMishra
Copy link
Copy Markdown
Contributor

@theAnuragMishra theAnuragMishra commented Mar 23, 2026

This PR memoizes router creation using useMemo . prevents router from being recreated every time app state other than the dependencies change.

while this works, i think there are other better options, maybe. like moving to react 19 which does memoization automatically (not really sure if the compiler would memoize cases like these). or just removing conditional routing and adding state guards in the components for the routes.

fixes #1155

prevents router from being recreated every time app state other than the dependencies change
@theborakompanioni
Copy link
Copy Markdown
Collaborator

Hey @theAnuragMishra. Thanks for the PR.
I think the ticket is specifically about v2 -> can you check the branch?

@theAnuragMishra
Copy link
Copy Markdown
Contributor Author

ah yes sorry. i missed [v2] . i will close this one and try to fix in the v2 branch.

@theAnuragMishra
Copy link
Copy Markdown
Contributor Author

@theborakompanioni before i try to work on the issue in v2, i'd like to confirm what appraoch would be preferable. like i described, we could make a simple fix by memoizing, or follow what you may call the idiomatic way, that is, create a stable router once outside App and the route elements read state themselves instead of passing a lot of props into the route elements.

@theborakompanioni
Copy link
Copy Markdown
Collaborator

@theborakompanioni before i try to work on the issue in v2, i'd like to confirm what appraoch would be preferable. like i described, we could make a simple fix by memoizing, or follow what you may call the idiomatic way, that is, create a stable router once outside App and the route elements read state themselves instead of passing a lot of props into the route elements.

Yeah, if that is possible, let's do it.
I am not an too familiar with the best practices - I'll learn a thing or two from your upcoming PR 🙂

@theAnuragMishra
Copy link
Copy Markdown
Contributor Author

#1175 . some more work needs to be done though. but let's move the discussion there and close this pr.

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.

[v2] avoid recreating browser router on every app render

2 participants