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

Duplicate router created when Routes is rerendered #181

Closed
ethanwu10 opened this issue Oct 23, 2024 · 1 comment · Fixed by #182
Closed

Duplicate router created when Routes is rerendered #181

ethanwu10 opened this issue Oct 23, 2024 · 1 comment · Fixed by #182

Comments

@ethanwu10
Copy link
Contributor

ethanwu10 commented Oct 23, 2024

Describe the Bug

In the fix for #180, the browser router was changed to being created during each render of the Routes component:

const router = () => createBrowserRouter(routes)
export const Routes = () => <RouterProvider router={router()} />

Thus, each time the Routes component was rendered, a completely new router is created and used.

This causes the same issues with e.g. loaders firing multiple times as seen in #180, but instead when using the Routes component (and not when creating your own Router).

Generouted Version

1.19.7

Your Example Website or App or Reproduction

https://stackblitz.com/edit/sb1-1ln2g2?file=src%2Fpages%2Findex.tsx

Steps to Reproduce the Bug or Issue

  1. Navigate using a link
  2. Navigate back using browser buttons
  3. Observe that the loader count went up by 2 and that in the console, the loader fired twice in a row for the same navigation

Note that since StrictMode is enabled, all render functions are called twice per render - thus 2 routers are created and we see loaders firing twice. If the component containing <Routes /> rerenders for any other reason, more routers will be created.

Expected Behavior

The loader should only have been executed once

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Firefox 131

Additional context

No response

@oedotme
Copy link
Owner

oedotme commented Oct 24, 2024

Fixed in v1.19.8 — Thanks for the follow up and for your contributions!

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 a pull request may close this issue.

2 participants