-
Notifications
You must be signed in to change notification settings - Fork 4.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
Data views: Update empty/loading states #59437
Conversation
Size Change: +3 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
Can't test this now, but spinner instead of text is good! |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
The code change itself looks good to me, but the loading state is not visible in my environment. When I reload the browser, it shows "No results" and then the data. Is anyone able to reproduce this problem?
ece92ff96e2e236043d93f35980d2bb3.mp4
Interesting, I see the same thing on the Templates data view. Pages is fine. Patterns is somewhere in between – I see a flash of 'No results' before the spinner. It seems that there's a 'No results' state that appears before the loading state, perhaps that's caused by a delay while Perhaps @ntsekouras has an idea. |
The state in which the DataView is rendered should depend on I think it might be better to rely on After a little debugging, the status changes as shown below. You can see that
If it makes sense to use <DataViews
data={ data || EMPTY_ARRAY }
isLoading={ ! hasResolved }
view={ view }
/> In any case, this is outside the scope of this PR, so it might be okay to merge this PR first, but I think we also need to resolve this state discrepancy in DataViews🤔 cc @youknowriad I assume you are familiar with the |
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.
LGTM, thanks!
Good catch @t-hamano! It would be good to figure out why this happens and see if it affects other usages in our code base. I'll cc @adamziel because he might have a super quick answer for this..
We can land this and follow up with at least the hasResolved
usage.
It seems the isResolving
is not very reliable based on this:
Returns the raw
isResolving
value for a given selector name,
and arguments set. May be undefined if the selector has never been resolved
or not resolved for the given set of arguments, otherwise true or false for
resolution started and completed respectively.
and I'm wondering what's the true value of it, if we can just use the hasResolved
value. 🤔
I'm not sure which gutenberg/packages/core-data/src/hooks/use-query-select.ts Lines 112 to 115 in 941d580
It seems like the underlying gutenberg/packages/data/src/redux-store/metadata/reducer.ts Lines 51 to 57 in 941d580
gutenberg/packages/core-data/src/resolvers.js Lines 28 to 38 in 941d580
gutenberg/packages/core-data/src/actions.js Lines 35 to 41 in 941d580
My guess is the data flow goes like:
This would explain the moment when we both have data and Note that configuration could happen in another, completely valid state:
I'm not sure how |
The If you want to know whether the selector is currently resolving, you should call the The table of values that @t-hamano shares in #59437 (comment) is correct and expected. The values are a bit out of sync between rows 3 and 4, but that should be harmless. As @adamziel points out, it happens because the data update and resolution state update don't happen atomically, but in two separate actions. |
What?
Spinner
Why?
Spinner
is more consistent with loading states found elsewhereTesting Instructions
Spinner
states.mp4
Note: It would be nice to delay the appearance of the spinner by a second or two, then fade it in. Often times the data loads quickly and the display of the spinner (or 'Loading...' text) is a bit distracting.
Note 2: We might embellish the 'No results' state to include conditional messaging. E.g. when there are no records at all include an 'Add' button. When the lack of results is due to filter config; display a prominent 'Reset filters' button.