-
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
Save the last-non-editor-route in redux instead of calculating it #44724
Save the last-non-editor-route in redux instead of calculating it #44724
Conversation
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.
WordPress Desktop CI Failure for job "wp-desktop-source".
@p-jackson please inspect this job's build steps for breaking changes at this link. For temporal failures, you may try to "Rerun Workflow from Failed".
Please also ensure this branch is rebased off latest Calypso.
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~176 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~109 bytes removed 📉 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
@p-jackson I can confirm the UI tests are working as written in the PR description. I have a question about some other scenarios.
I have no idea if this falls into the issue that this PR solves. Only curious as I was playing around. |
@autumnfjeld This PR isn't aiming to address that. I'm not sure, but I imagine that's by design. There's a few explicit places the user will be taken back to, not to just any old place in Calypso. It's a good real-world example of React/Redux integration actually.
Taking a look at |
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.
I'll go ahead a leave my new-automattician-summary here. 🥇
Here is my recap of this PR, that is PR learning experience (combining info from Redux docs, PR, and wp-calypso docs).
Each redux state has a folder in wp-calypso/client/state/ and the root module /state/index.js exports a single reducer function.
The redux store is created with this single reducer function in that index.js. (Side note: Reducers create new State from the previous State and an ACTION instruction)
This PR alters the existing /state/route reducer by adding a sub-reducer, last-non-editor-route, as is evident in the combineReducer function in /state/route/reducer.js
The last-non-editor-route
reducer will be responsible for saving the url string of the last non-editor page the user was on.
The lastNonEditorRoute uses withSchemeValidation , which causes the state to be persisted in IndexedDB and causes the reducer to go through json schema validation.
I read through the data-persistence doc, and wanted to summarize to make sure I understand.
I get the broad idea that storing the Redux state in browser storage is desirable for a peppy page load. The initial paragraphs lead me to believe this is done for the whole Redux state tree. Then follows discussion on issues & caveats with subtrees and then describes how serialization overcomes these issues, and instructs to use hasCustomPersistence = true in these problematic subtree situations. (At least that is my takeaway, admittedly I don’t have a deep feel for some of these concepts.)
Then doc goes on to describe another issue, which is data shape changing over time. This makes sense. And then schema validation is discussed as a solution to the evolving data shape issue. Makes sense.
My first takeaway was, that the whole Redux state IS indeed stored in IndexedDB. But sometimes special handling of some parts of the state is needed.
But then the very end of the doc says “Opt-in to Persistence” using withSchemaValidation, which is what you said Phillip. I suppose I find it confusing that the actual ‘how to’ for making a part of the state persistent is at the very end of the doc.
When closing the block editor, we take the user back to the last non-editor page they were on. We determine the last non-editor state by searching through the action log.
The problem is that the action log isn't saved to
localStorage
, so if the user refreshes the page then we lose where they came from and just go to a default location. This bug is made even worse by the navigation sidebar because navigating between items in the sidebar refreshes the page too.We can't persist the whole action log because that's going to grow unbounded. Instead we'll store just the info we want as a new bit of state in the redux store. Unfortunately that means there's data duplication. 🤞 the redux pattern helps us keep it in sync.
Changes proposed in this Pull Request
lastNonEditorRoute
state to redux storelastNonEditorRoute
state using thewithSchemaValidation
higer-order-reducergetLastNonEditorRoute
selector so it doesn't depend on the action logLuckily, block editor navigation is the only user of the
getLastNonEditorRoute
selector, so we don't have to worry about this change breaking any other features.Testing instructions