[amp-bind] amp-list evaluation does not wait for amp-state's src request to be resolved
Bindings are evaluated when an amp-list template is rendered. However, these bindings don't wait until an amp-state's remote src has been resolved (which they should to ensure an deterministic behavior).
Example:
An amp-state element using a JSON endpoint:
<amp-state id="favorite"
credentials="include"
src="/favorite-with-count?RANDOM">
</amp-state>
The amp-list binds an element to the amp-state:
<amp-list ... src="/favorite-with-count?RANDOM">
<template type="amp-mustache">
<div class="favorite-count" [text]="favoriteWithCount.count ? favoriteWithCount.count : ''">{{count}}</div>
</template>
</amp-list>
This results in a race-condition, where the text is either null or 123 depending on whether the amp-state has already been resolved or not.
I noticed this while working on this sample: https://ampbyexample.com/advanced/favorite_button/
//cc @choumx @ericlindley-g
Good eye. 😄 This is an interesting one. The fundamental tension is the fact that both amp-state and amp-list elements are fetching the same data. Maybe we can add the ability for amp-list to explicitly reference an amp-state element by id as its data source.
If they’re fetching the exact same data it works due to request caching. Only when they’re different it may result in a race condition.
Being able to reference state from amp-list without having to provide a src would be a lot cleaner. We’d still need to delay amp-list rendering until amp-state has been resolved though.
On Thu, 9 Nov 2017 at 20:04, William Chou [email protected] wrote:
Good eye. 😄 This is an interesting one. The fundamental tension is the fact that both amp-state and amp-list elements are fetching the same data. Maybe we can add the ability for amp-list to explicitly reference an amp-state element by id as its data source.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ampproject/amphtml/issues/11998#issuecomment-343275059, or mute the thread https://github.com/notifications/unsubscribe-auth/AAXOOCova7ofyuRYe0FJk6OMlryH6bIEks5s01q4gaJpZM4QYMeE .
This issue hasn't been updated in awhile. @choumx Do you have any updates?
Please allow referencing <amp-state> as a data source for <amp-list>.
This issue hasn't been updated in awhile. @choumx Do you have any updates?
@choumx brought up the concern that at this point, we probably don't want to fix this within version 0.1 due to this fix not being backcompat. There could be many sites relying on the current racing behavior (specifically that amp-list doesn't wait for amp-state to load).
We'd need to bump the version to 0.2
Now that we can use amp-state as a data source for amp-list, I think this issue is worth closing. That method will wait for amp-state to complete loading before render.
For reasons explained directly above, this may not be worth fixing in amp-list 0.1.
@sebastianbenz WDYT?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.