Show loading indicator and placeholder when an amp-list refetches#13782
Show loading indicator and placeholder when an amp-list refetches#13782aghassemi merged 18 commits intoampproject:masterfrom
Conversation
src/custom-element.js
Outdated
| return; | ||
| } | ||
|
|
||
| if (state && !this.implementation_.doesReuseLoadingIndicator() && |
There was a problem hiding this comment.
any reason this block moved down?
There was a problem hiding this comment.
Not that I remember. I'm not sure how this got moved. I moved it back now.
src/base-element.js
Outdated
| } | ||
|
|
||
| /** | ||
| * Returns is reused again after the render. |
There was a problem hiding this comment.
Returns whether loading indicator is reused...
extensions/amp-list/0.1/amp-list.js
Outdated
| } | ||
|
|
||
| /** @override */ | ||
| doesReuseLoadingIndicator() { |
There was a problem hiding this comment.
I like to suggest renaming to isLoadingReused. doesprefix is not commonly used in AMP and other related loading-related methods just say loading instead of loadingIndicator
extensions/amp-list/0.1/amp-list.js
Outdated
| throw user().createError('Error fetching amp-list', error); | ||
| }); | ||
| }) | ||
| .then(() => { |
There was a problem hiding this comment.
nit: no new line needed here
extensions/amp-list/0.1/amp-list.js
Outdated
| } | ||
| } | ||
|
|
||
| /** @override */ |
There was a problem hiding this comment.
a bit of comment to clarify what's happening here, something along the lines of amp-list reuses the loading indicator when list is fetched again via bind mutation or refresh action
extensions/amp-list/0.1/amp-list.js
Outdated
| if (!this.element.getAttribute('src')) { | ||
| return Promise.resolve(); | ||
| } | ||
| this.togglePlaceholder(true); |
There was a problem hiding this comment.
This feature is technically is breaking UI change and I can see cases where one may not want this feature at all. I recommend putting this behind an attribute show-loading-on-refresh or similar. I will bring it up in our design review tomorrow morning to see what others think.
There was a problem hiding this comment.
Makes sense. Let me know the outcome of the design review and I'll update the code accordingly.
There was a problem hiding this comment.
Added to #13718 (comment).
tl;dr: reset-on-refresh attribute needed as opt-in signal to get this behaviour.
aghassemi
left a comment
There was a problem hiding this comment.
Thanks for making the changes. Few small comments and we should be good to go after.
| // Hide in case fallback was displayed for a previous fetch. | ||
| this.toggleFallbackInMutate_(false); | ||
| } | ||
| this.togglePlaceholder(false); |
There was a problem hiding this comment.
this is a change from previous code. These should happen automatically anyway. I recommend keeping the old code structure to eliminate any regressions e.g.
const fetch =...
fetch.then() {
if(fallback) etc...
}
return fetch;
There was a problem hiding this comment.
You mean move this .then(...) block back to layoutCallback()? That doesn't work because then the loading and placeholder don't go away after a reload (either from the refresh action or an amp-bind change). I just tried it now.
| this.toggleFallbackInMutate_(true); | ||
| this.togglePlaceholder(false); | ||
| } else { | ||
| throw error; |
There was a problem hiding this comment.
ditto, if we stick with the old code structure, this should not be needed.
| attrs: { name: "items" } | ||
| attrs: { name: "max-items" } | ||
| attrs: { name: "single-item" } | ||
| attrs: { name: "reset-on-refresh" } |
There was a problem hiding this comment.
please add value="" that would ensure reset-on-refresh can not be given a value and is treated as a binary flag.
also alphabetical ordering of the attributes names
|
@josh313 PR LGTM, I am gonna do some manual edge case testing and then merge it. |
|
@josh313 Meanwhile, could you please take a look at the failing test? |
|
@aghassemi Thanks. I fixed the unit tests now. The integration tests appear to have just stalled. I'm guessing that's unrelated to my change. Is there a way to restart it? |
|
@josh313 failure was due some whitespace nits in the validator test file. added a fix, they should pass now. I will let you know when I finish testing and merging this, will happen this week for sure. |
|
@aghassemi Sounds great. Thanks! |
|
Rebased and did some local testing, looks good. will merge and do more testing on production sites with Canary that's cut tomorrow. Update: (3/21) |
|
@aghassemi From when we will be able to use this? |
|
@yajiv185 It will be in dev channel tomorrow so you can play with the feature, having your AMP pages validate with this feature is ~ 2-3 weeks away. |
|
These validator changes will be live everywhere within an hour. |
cc @aghassemi @choumx