Open codemonkey800 opened 1 month ago
hmm something interesting I found:
Kent C Dodds bypasses the re-rendering + re-executing loader by using window.history.replaceState
instead of using useSearchParams()
directly. this might useful if we want to try and fix the re-rendering issues without refactoring everything to global state
I might need to think about this more, this seems like it might be an anti-pattern in remix: https://remix.run/docs/en/main/discussion/state-management#how-remix-simplifies-state
A majority of our state lives in URL parameters accessible via the
useSearchParams
hook. While this works well because of its simplicity, it's not very performant nor maintainable in its current state.Search parameter state usage is more or less scattered around the codebase and has no standardization around how it's managed, with the exception of
useDownloadModalQueryParamState()
. Using a state management solution would allow us to more easily organize our state.Using search parameters as state also causes more unnecessary re-renders because calling
setSearchParams()
will result a re-render of the entire page rather than the components that are using that state. Furthermore, extra care is required when updating the parameters because successive calls tosetSearchParams()
are not batched, resulting in possibly additional re-renders. Moving our state into a state management library would allow us to set up a subscriber to update the URL parameters locally usinghistory.replaceState()
which would be more efficientFor example, here's how it's done on napari-hub:
Because of this, we should consider migrating all of our state into
jotai
to reap the benefits in performance and maintainability.