-
Notifications
You must be signed in to change notification settings - Fork 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
Sites: Use Redux state preference for recent sites #7478
Conversation
The race condition sounds similar to the one we had for settings: #1167 In this case, what if we added some state when we switch sites that lets the preferences reducer know not to override the recent site preference, but lets it update everything else. |
return <div className="site-selector__recent">{ recentSites }</div>; | ||
return ( | ||
<div className="site-selector__recent"> | ||
{ reduce( sites, ( memo, site ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remember to update this later when we have a bit more ported. We should be able to avoid reducing over all sites.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remember to update this later when we have a bit more ported. We should be able to avoid reducing over all sites.
Yeah, I had the same thought while refactoring. If we had sites already indexed by ID (which is the case for Redux where we can use getSite
), we'd be able to map
over the recentSites
array instead of the other way around. As-is, this way is still much more performant than previously, where for each recent site we'd filter over the entire sites array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where for each recent site we'd filter over the entire sites array.
😄 oh that's a fun one
👍 Didn't find any regressions. Let's 🚢 |
a413d82
to
4d8dd43
Compare
Some last minute testing revealed a few oddities and opportunities for improvement which I've addressed in the latest batch of commits:
|
ping me after you rebase, and I can take the branch for another spin |
cd25a32
to
2149332
Compare
Thanks for the heads-up on conflicts. Guessing #7315 will hit quite a few open PRs. Pushed a rebase. |
Good call with removing the pure option, it feels much faster without it. 👍 Retested this on the main my-sites routes, and verified that the behavior looks correct for recent sites. |
2149332
to
7a409b6
Compare
I was pretty wary about the Redux render context issues, so went through and tried to find and update as many @sirbrillig do the changes in 31f18f5 make sense to you? |
@aduth Yeah, it looks great! (With one exception - commented inline - that may be fine but I don't fully understand.) |
Splice does not work as intended when inserting indices out of order.
Sites object can change internally, which can be monitored via observe mixin until we’ve migrated to Redux-based state
7a409b6
to
603ef85
Compare
Related: #7323, #7413
This pull request is a continuation of #7323, migrating the
<SiteSelector />
component toward using Redux-based global state for recent site preferences. It completes the migration, removing recent site logic from thesites-list
module.Toward #7413, it resolves a warning logged in development environments related to the
preferences
prop passed to the rendereddiv
by the legacy<PreferencesData />
component.Testing instructions:
There should be no changes in behavior from the master branch. Notably, confirm that your recent sites are shown in the correct order, and that selecting a new site updates this order and is persisted between page sessions.
Caveats / Open Questions:
<SiteSelector />
doesn't render a<QueryPreferences />
component of its own, instead depending on the one rendered in the top-level<Layout />
component. This is to avoid excessive requests when toggling the visibility of the<SiteSelector />
component. It could be argued that this is desirable to keep the preferences data fresh (which would probably resolve the issue in the first noted caveat), but with<QueryPreferences />
guaranteed to be rendered on every screen by<Layout />
, it should be safe to rely on this as the source of preference data./cc @mtias @gwwar
Test live: https://calypso.live/?branch=update/site-selector-preferences