Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Don't load isSidebarOpened preference from localStorage on mobile. #3331
This PR aims to close #2816. When loading preferences from the localStorage if we are on mobile it sets isSidebarOpened to false instead of using what is stored. The technique used to define if we are on mobile is the same that is already used to set the default value for the isSidebarOpened when not loading from localStorage.
Resize your window on to mobile sizes (or test on mobile). Open sidebar if it is not already open. Refresh the page and see sidebar is now closed.
@@ Coverage Diff @@ ## master #3331 +/- ## ========================================== + Coverage 34.85% 34.93% +0.08% ========================================== Files 261 263 +2 Lines 6717 6730 +13 Branches 1224 1228 +4 ========================================== + Hits 2341 2351 +10 - Misses 3692 3694 +2 - Partials 684 685 +1
storePersist utility was created to be a generic solution for store persistence. The changes here introduce editor-specific awareness into rehydration logic, against this goal.
I could see this being:
- An editor-specific middleware monitoring
REDUX_REHYDRATEand overriding the
- A condition within the reducer itself? Maybe too much environment awareness for a reducer.
- Callback on the
storePersistutility to manipulate the restored value before it is rehydrated?
It seems like you can pass the result of execution wp_is_mobile together with other settings when creating an editor instance and Redux state. Here is the place in the code where it could be included:
Hi @gziolo the problem with wp_is_mobile is that it is based on user agent and not on screen sizes. There are situations where even during the execution when a breakpoint changes (because the window resized) we want to execute some action.
Yes in this case that was true because this function just needs to be applied on load when loading the prefs from localstorage. But I applied an improvement so we don't use the constant.