-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Install newest @tanstack/react-router #4384
Conversation
|
How much should each component with a navigation action know about the At the moment, their state is governed by the However, because search params =/= Just to understand what each components responsibility should be, I created a small flow diagram. ---
title: Dashboard state and navigation
---
flowchart TB
subgraph ENTRY
direction TB
BrowserArrives([Browser navigates to page]) -->
ServerRenders[Server responds with HTML with site data encoded] -->
SiteIsParsed[Site data is decoded from HTML] -->
ReactAppMounts[React app mounts with the parsed site]
end
subgraph INITIAL
direction LR
RouterMounts([Initial browser path and search params are parsed]) -->
QueryContextMounts[Parsed search params and saved or hardcoded defaults are made available as `query` within the app]
end
subgraph ANY LIST LIFECYCLE
direction TB
AnyListMounts([Based on the browser path and `query`, a list component makes an API call and renders list items]) -->
AnyNavigationLinkMounts[A list item is able to set the browser path and new search params, with the new URL visible on hover] -- link clicked -->
RouterReloads[New browser path and search params are parsed] -->
QueryContextReloads[Query context recalculates query based on the new search value]
--> AnyListMounts
end
ENTRY --> INITIAL
INITIAL --> AnyListMounts
|
605cb5b
to
572f29e
Compare
Do you have a proposal for how it could be avoided? In general I don't think it's a problem for components to know about |
As we discussed synchronously, it's OK that components are aware of the query. It's just that right now, they also simultaneously need to be aware of search params. That's because we affect the query by using links that change search params. (This is good UX because users can easily open different selections of the dashboard in separate tabs if they need to.) One potential improvement is to provide components with a utility that allows them to fill Link/navigate search property by knowing only what query change they need to affect: function PageDrilldownLink({ page }) {
const { set } = useQueryContext();
return <Link to={rootRoute.to} search={set.pageFilter(page)}>{page.name}</Link>
} That said, while search.filters ~~ query.filters && search.labels ~~ query.labels, we're pretty safe. |
Changes
This PR replaces
react-router-dom
with latest@tanstack/react-router
. The reasoning is that we're using@tanstack/query
to manage API response state in the application, and both packages depend on the same core logic package. We can expect these two to be complementing each other.PlausibleSearchParams
with astringifySearch
andparseSearch
method, performed automatically on location change by the new routerfalse
used to be the way to remove the search param, but I wasn't able to keep this behavior, now setting the value tonull
is the way to do itTests
Changelog
Documentation
Dark mode