josefarias / hotwire_combobox

An accessible autocomplete for Ruby on Rails.
https://hotwirecombobox.com
MIT License
436 stars 26 forks source link

Retrieving paginated results seems to arbitrarily stop appending to the results list #156

Closed aseroff closed 3 months ago

aseroff commented 3 months ago

Bug description

Paginated async results seem to stop loading pages after an arbitrary amount of time

To Reproduce

Steps to reproduce the behavior:

  1. Have an endpoint that has 5+ pages
  2. Scroll down to load more results. After 3 or 4 pages, no more results are appended

Expected behavior

Results are appended until the final page is reached

Code

# app/views/library/textbooks/index.turbostream.haml
= async_combobox_options @textbooks, render_in: { partial: 'library/textbooks/search_result' }, next_page: (@pagination_info[:page] < @pagination_info[:total_pages] ? (@pagination_info[:page] + 1) : nil)

Version Numbers

HotwireCombobox info

Desktop info (if applicable)

Additional context

Confirmed that it wasn't my pagination logic by replacing @pagination_info[:page] < @pagination_info[:total_pages] with true, problem persisted.

josefarias commented 3 months ago

Hey @aseroff, this was reported once before by @dixpac but I couldn't reproduce.

I'm going to need a link to a rails app I can run locally and debug in order to fix this.

Alternatively, did you ever figure this one out @dixpac?

aseroff commented 3 months ago

Reassuring that it's not just me. I can point you to https://staging.open.umn.edu/opentextbooks for a live example, but I'll have to get back to you on a cloneable repo.

Appears to work fine in mobile however.

josefarias commented 3 months ago

@aseroff thanks for the live example, that's very helpful!

I see what's happening. The pagination trigger at the bottom of the options list isn't triggering because Turbo's intersection observer doesn't consider it visible. Interesting how this doesn't happen every time. Might be an artifact of the custom styles, or a browser-specific issue.

The fix should be simple — just give the trigger a small height so it's guaranteed to be visible. I'll get to work on that.

Thanks!

josefarias commented 3 months ago

@aseroff I've just released v0.2.4

Could I get you to update the gem please (remember to also update the JS package if you're not using importmaps) and let me know if it's working now, please? Thanks! Closing for now but will reopen if not solved.

josefarias commented 3 months ago

Ope, make that v0.2.5 sorry (will release shortly) — missed this: https://github.com/josefarias/hotwire_combobox/pull/158

aseroff commented 3 months ago

Bumped and confirmed the fix. Thank you!

dixpac commented 3 months ago

@josefarias I can confirm that this fixes issue I've been seeing 👍