Repeating Group shows extra item with :items until

Hi,

I am running into a strange issue with pagination in a Repeating Group. It keeps showing 7 items instead of 6 on the second page.

Page & Data Reference

Item Description
Page name home_whats_new
Data source - App data Whats_News

Custom States

Name Type Default Value Description
total_page number total items / page_size Total number of pages
current_page number 1 Tracks the current page the user is on
page_size number 6 Number of items to display per page
start_index number The index of the first item on the current page
end_index number The index of the last item on the current page

Workflow

  • Next page
    • Button_next is clicked
      • Only when: home_whats_new’s current_page < home_whats_new”s total page
    • Step 1: Set states
      • Element: home_whats_new
      • Custom state: current_page
      • Value: home_whats_new’s current_page + 1
    • Step 2: Set states
      • Element: home_whats_new
      • Custom state: start_index
      • Value: home_whats_new’s current_page - 1 * home_whats_new’s page_size + 1
      • Custom state: end_index
      • Value: home_whats_new’s current_page * home_whats_new’s page_size
  • Previous page
    • Button_previous is clicked
      • Only when: home_whats_new’s current_page > 1
    • Step 1: Set states
      • Element: home_whats_new
      • Custom state: current_page
      • Value: home_whats_new’s current_page - 1
    • Step 2: Set states
      • Element: home_whats_new
      • Custom state: start_index
      • Value: home_whats_new’s current_page - 1 * home_whats_new’s page_size + 1
      • Custom state: end_index
      • Value: home_whats_new’s current_page * home_whats_new’s page_size

Repeating Group - Data source

Search for Whats_New:items from #home_whats_new’s start_index:items until #home_whats_new’s end_index

Settings for Repeating Group “Do a search for”

  • Type: Whats_New
  • Sort by: Created Date
  • Descending: “yes”

Step-by-Step Observation with Pause Test

In Step-by-step mode, all custom states update correctly:

  • current_page, start_index, and end_index match expectations (e.g., page 2: 7 - 12)
  • page_size stays at 6

I added a pause at the very end of the workflow. Before the pause, the Repeating Group shows 6 items as expected. However, the moment I press “Run next”, it immediately shows 7 items instead of 6.
I am wondering if the issue is likely Bubble’s Repeating Group render timing. I’m not sure how to fix this, so I would greatly appreciate any advice or guidance from anyone who has experienced something similar.

The debugger has its own misleading view that workflow steps are run with updated values at each step.

The workflow actually caches some values at the start of the workflow, at least those it doesn’t understand have been updated by an earlier step.

To fix, swap steps 1 & 2 and rewrite the calculation for start_index and end_index to use the original value of current_page.

1 Like

Thanks for willing to help on this mystery, @mishav. I updated workflow as your suggestion. Unfortunately, It’s still not working.

Setup: There are 13 data entries in App data Whats_News.

Behavior

  1. :check_mark: The page successfully load 6 items in the beginning.
  2. :cross_mark: Click Button_next on P. 1: P. 2 still shows 7 items (no. 7 - no. 13) in stead of 6 item (no. 7 - no. 12).
  3. :cross_mark: Click Button_previous on P. 2: P. 1 only shows 1 item which is no. 13 in stead of 6 items (no. 1 - no. 6).
  4. :check_mark: Click Button_next on P. 2: P. 3 correctly shows 1 item which is no. 13.
  5. :cross_mark: Click Button_previous on P. 3: P. 2 only shows 0 item instead of 6 items (no. 1 - no. 6).

Update Workflow

  • Next page
    • Button_next is clicked
      • Only when: home_whats_new’s current_page < home_whats_new”s total page
    • Step 1: Set states
      • Element: home_whats_new
      • Custom state: start_index
      • Value: home_whats_new’s current_page * home_whats_new’s page_size + 1
      • Custom state: end_index
      • Value: home_whats_new’s current_page + 1 * home_whats_new’s page_size
    • Step 2: Set states
      • Element: home_whats_new
      • Custom state: current_page
      • Value: home_whats_new’s current_page + 1
  • Previous page
    • Button_previous is clicked
      • Only when: home_whats_new’s current_page > 1
    • Step 1: Set states
      • Element: home_whats_new
      • Custom state: start_index
      • Value: home_whats_new’s current_page * home_whats_new’s page_size + 1
      • Custom state: end_index
      • Value: home_whats_new’s current_page + 1 * home_whats_new’s page_size
    • Step 2: Set states
      • Element: home_whats_new
      • Custom state: current_page
      • Value: home_whats_new’s current_page - 1

Hi @WMD I was wrong about the workflow caching the custom state values, your original workflow is fine after all :smiling_face_with_tear:

Here is where the issue is, it becomes more clear if the expression parenthesis is turned on …

(Search for Whats_New:items from #home_whats_new’s start_index):items until #home_whats_new’s end_index

01 02 03 04 05 06 07 08 09 10 11 12 13

-> :items from # start_index = 7
                07 08 09 10 11 12 13

-> :items to # end_index = 12, applies to the reduced list
                07 08 09 10 11 12 13

Replacing end_index with page_size gets the following…

(Search for Whats_New:items from #home_whats_new’s start_index):items until #home_whats_new’s page_size

01 02 03 04 05 06 07 08 09 10 11 12 13

-> :items from # start_index = 7
                07 08 09 10 11 12 13

-> :items to # page_size = 6, applies to the reduced list
                07 08 09 10 11 12

I hope this helps!

Edit - the RG source can, with a little messing around, be convinced to use just current_page and page_size, at the expense of simplicity haha …

(Search for Whats_New:items from #(((home_whats_new’s current_page - 1) * home_whats_new’s page_size) + 1)) :items until #home_whats_new’s page_size

1 Like

Issue fixed!!:tada: Thank you @mishav . :folded_hands: You reminded me to check the definition of …:items until# and …:items from# in Bubble Docs. The issue is fixed by switch the operations!

Search for Whats_New:items until #home_whats_new’s end_index:items from #home_whats_new’s start_index

1 Like