amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

[Master feature] Element-level infinite scroll

Open ericlindley-g opened this issue 8 years ago • 61 comments

Feature description:

Support element-level infinite scroll, such that when the user reaches the end of a list of items (search results, product cards, etc), a call can be made to an arbitrary endpoint to populate the list with more items. For the best user experience, users should never see a loading spinner, but instead should either be presented with already-loaded results, or a button to tap to load more.

Update

This feature is available for origin trial per https://github.com/ampproject/amphtml/pull/20592 as of release https://github.com/ampproject/amphtml/issues/20587.

Related demos

Basic demos https://amp-infinite-scroll.glitch.me/ https://amp-infinite-scroll.glitch.me/flex.html Pretty Demo TODO: Add animation (slide up / slide in / fade in) TODO: Variable heights Example with a finite number of pages https://amp-infinite-scroll.glitch.me/finite.html Example with bad URL https://amp-infinite-scroll.glitch.me/bad-url.html Example with slow loading URL https://amp-infinite-scroll.glitch.me/latency.html Use Slow 3G network tab option or 2g poor on any of the examples Manual load more Example with finite number of pages https://amp-infinite-scroll.glitch.me/finite-2.html Example with bad URL https://amp-infinite-scroll.glitch.me/bad-url-2.html Example with slow loading URL https://amp-infinite-scroll.glitch.me/latency-2.html

Related issues

#19502

Related PRs

https://github.com/ampproject/amphtml/pull/19519 https://github.com/ampproject/amphtml/pull/19399

ericlindley-g avatar Mar 16 '18 18:03 ericlindley-g

This issue doesn't have a category which makes it harder for us to keep track of it. @ericlindley-g Please add an appropriate category.

ampprojectbot avatar Jun 05 '18 06:06 ampprojectbot

we need this feature urgently. when do you think you can release a version?

mofidsky avatar Jul 11 '18 07:07 mofidsky

@mofidsky We're targeting release this quarter— @cathyxz, who is working on the implementation, may or may not be able to offer a better estimate.

We'd love to hear feedback when you're able to try it out—if you can share an examples of how you plan to use it that could help us make sure we're capturing relevant use cases.

ericlindley-g avatar Jul 12 '18 01:07 ericlindley-g

@ericlindley-g We're trying to build a news web site so that contents are loaded when users scroll down, something like Facebook web site or Instagram app for instance.

mofidsky avatar Jul 12 '18 10:07 mofidsky

@mofidsky — Thanks! That sounds like the general use-case we're building for.

I should note that amp-next-page supports infinite scroll for entire documents of content (as opposed to infinite scroll for elements within a single page), in case you're interested in that experience.

ericlindley-g avatar Jul 12 '18 16:07 ericlindley-g

@ericlindley-g, @cathyxz We are also have a use case for this component on the product detail pages of our e-commerce aggregator. We compare offers from different merchants selling the same product, in the case of marketplaces they even have multiple offers of the same product. We allow the user to browse for the merchant/marketplace first and then drill-down into the respective offer. Right now we are pre-loading all the content into the HTML and just playing with the visibility, that bloats the HTML quite significantly though.

For an example, check out the following page: https://iprice.my/compare/apple-iphone-8/ and scroll to the "Compare Prices" section.

This is quite high in our backlog right now, happy to help in the development or testing of the component, let us know how we can contribute.

heiwen avatar Oct 25 '18 02:10 heiwen

My current approach is using the recursive template mustache. This template has 2 parts. First one for loop items, another one for next items. The next section consist a form which using this template again. Check the image bellow: image Im thinking if we add high trust event for amp-position-observer we will have real infinity scroll :).

buihoanghai avatar Oct 25 '18 06:10 buihoanghai

@buihoanghai We are working a first-class support for this. It is under development but you can give it a try experimentally ( not valid in Prod ) using amp-load-more experiment (sample: https://github.com/ampproject/amphtml/blob/master/test/manual/amp-list-load-more.amp.html ) ETA for launch is Dec/Jan.

We are not planning to make position-observer emit hight-trust events as scroll is not a strong user-interaction signal to be allowed to relayout the page.

aghassemi avatar Oct 25 '18 16:10 aghassemi

Thanks @heiwen — I defer to @cathyxz if additional help would speed up the timeline here, but we appreciate the info on your use case either way

By the way — great AMP-first implementation of your site! It's awesome to see AMP used to build great experiences on the main version of a site like yours

ericlindley-g avatar Nov 02 '18 19:11 ericlindley-g

@ericlindley-g Nice to see this feature is on the radar, is there anyway we can contribute and build this thing together to achieve infinite scroll to load more data like this along with Masonry / Waterfall layout like what pinterest is having ? we are looking forward to contribute and share the workload together, but with concern of not knowing what's the current state for these components and how to step in. Please advise.

/cc @cathyxz

leonahliang90 avatar Nov 08 '18 06:11 leonahliang90

Thanks for reaching out, @leonalicious — @cathyxz is in the best position to know if there are opportunities to contribute on this component, so I'll let her answer that aspect. My guess is that the most important place to contribute is in testing the component when it's feature complete and experimentally available, but @cathyxz may know of opportunities to contribute to the development itself.

ericlindley-g avatar Nov 08 '18 15:11 ericlindley-g

It's experimentally available under amp-list-load-more, with an in-progress demo here. I'm trying to resolve the amp-list-resizable-children right now, and will be iterating on various corner cases for infinite scroll after that.

cathyxz avatar Nov 08 '18 19:11 cathyxz

It's experimentally available under amp-list-load-more, with an in-progress demo here. I'm trying to resolve the amp-list-resizable-children right now, and will be iterating on various corner cases for infinite scroll after that.

Cool, any timeline for the infinite scroll ? May I assist you ? which branch are you using for development of this feature ?

leonahliang90 avatar Nov 12 '18 07:11 leonahliang90

@cathyxz good day there ! it has been a while since we last heard the update from you, any progress / assistance I may offer please?

leonahliang90 avatar Nov 19 '18 03:11 leonahliang90

Hi @leonalicious ! The target launch date for this is going to be mid January. The main challenges remaining here are:

  1. Building out enough examples to get a good coverage of potential use cases.
  2. Handling loading state / end state / load failed states with the proper UI affordances (there's some debugging and UX tweaking still in progress here).
  3. Checking compatibility (or at least non-breakability) with existing features like reset-on-refresh, refresh action, changing src via bind etc.
  4. Cross browser / device QA.

I think what would be the most helpful here, would be help with building examples, testing, and feedback on our API. I can document what we have experimentally if you'd like to try it out and give us feedback.

For reference, this is what's being worked on from our burndown list:

  • [ ] Show buttons (overflow, load failed, etc.) underneath content instead of overlaid on top of content.
  • [ ] Implement reload (button) after loading failed (reuse overflow element).
  • [ ] Documentation
  • [ ] Add "load finished" element and gracefully handle end state (bookmark = null, empty array items, etc.)
  • [ ] Implement defaults for loading element, overflow element, load failed, load end elements
  • [ ] Examples / bugs / FRs for client/server-side filtering

cathyxz avatar Nov 20 '18 18:11 cathyxz

Hey @cathyxz, nice work ! I have tried with the infinite Scroll example and it works like a charm. But one thing I realize it is something pure amp-list approach without amp-bind. Because of the complexity of some business use cases, there are some scenario might need to include params with amp-bind when fetching for data with infinite scroll based on user selection, do you think is it possible to have trigger an amp-form event like form-filter.submit with amp-list's load-more property ? or any workaround to work amp-list infinite scroll with amp-bind please ?

Here is the example that requires to include variety of params while fetching data with amp-list image

leonahliang90 avatar Dec 03 '18 16:12 leonahliang90

Hi @leonalicious ! Thanks for trying this out and for your thoughtful feedback. So here's what we're thinking on client-side and server-side filtering.

  1. Server Side Filtering The [src] component of amp-list will be bindable (as it already is), and you can bind that on button clicks to alter the [src] of the entire list. This would result in the amp-list deleting its current items and showing new items according to the filter. What we still need to do to make this work is primarily make sure that amp-list resizes correctly.

  2. Client Side Filtering This you can do by toggling CSS via amp-bind. Again, the main outstanding work here is to make sure resizing works correctly.

It seems like what you're trying to do here is change the next fetch url without changing the items currently within the list. What's happening with the implementation under the hood is basically I have a class variable loadMoreSrc_, that is being retrieved from the bookmark expression, and set as [src] for the next fetch.

Here are a few options that I'm thinking:

  1. Make the bookmark url bindable. For example, add a load-more-next bindable attribute to amp-list. Let's say your json looks like:
{ ..., "next": "/api/search?a=1&b=2"} 

You can bind [load-more-next] on amp-list entirely to change this to https://www.new.com/api/search2?a=4&b=5. 2. Split the bookmark url into base-url and params, make params bindable via [load-more-next-params]. For example, your JSON looks like:

{..., "next": "/api/search?", "params": "a=7&b=10" }

It seems like in most cases (correct me if wrong) that people mainly just want to change the parameters.

~I'm currently seeing this as a non-launch-blocking feature request, since I think technically this can be achieved with CSS-based client-side filtering, and would primarily serve as an optimisation for returning fewer (unnecessary) items from the server. Does that sound right to you?~

It seems like the filtering functionality (size, color, shipping, etc) can be achieved with server side filtering, but the sorting (e.g. Best Match, Price, etc.) would require something like what I described above, since it's basically a client-side sort and passing in a sortBy parameter to the server for all new fetches. It seems like that parameter would need to be bound.

EDITED

cathyxz avatar Dec 03 '18 20:12 cathyxz

Hey @cathyxz , thank you for your clarification & sorry for the late reply, hmmmm, I personally think either splitting the params or not will not make much impacts, simply because the params returned from API should be simple, those params which are complicated are mainly based on user behavior, they should remains at client side. There, I am thinking lets keep it as simple as option 1 you mentioned earlier.

After understanding how this entire flow works, I think the most possible solution I would take is stated as below:

Provided I do have a amp-state which contains all the params:

 <amp-state id="refineState">
        <script type="application/json">
            {
                "categoryId": "",
                "minPrice": "",
                "maxPrice": "",
                "freeShipping": "",
                "onePiece": "",
                "pop": "",
                "shipFromCountry": "",
                "shipToCountry": "",
                "searchTags": "",
                "brandIds": "",
                "shoppingCoupon": ""
            }
        </script>
    </amp-state>

Based on your suggestion I think I will only be using load-more="auto" and bind the [src] of amp-list, by pointing the [src]='m.aliexpress.com/api/search?categoryId=123' + keys(refineState).map((filterParamKey, index) => '&' + filterParamKey + '=' + refineState[filterParamKey]).join('') , and everything should work by charms , thoughts?

Lastly, why should we bother and keep calculating the height of the amp-list ? cant we just set the height to something dynamic and let it be what it is based on its content ?

leonahliang90 avatar Dec 13 '18 09:12 leonahliang90

Someone knows how to fix this validation errors? screen shot 2018-12-13 at 12 58 50

I'm working on a infinite scroll with amp, but so far I couldn't make any progress in validating my HTML with the infinite scroll.

LuisKrotz avatar Dec 13 '18 15:12 LuisKrotz

Hi @LuisKrotz, amp-list-load-more is currently under experiment and not launched, so it won't validate. We're still working through it and may potentially make API changes at this point, so feel free to play with it, but note that it won't work in production until launch (approximate ETA is mid Jan).

cathyxz avatar Dec 13 '18 20:12 cathyxz