Skip to content

bug: Infinite scroll - scrolling to the top test is flaky on CI with Safari #30423

Closed

Description

@gnbm

Activity

  1. added
    help wanted
    type: bug
    on May 25, 2025
  2. ionitron-bot commented on May 25, 2025

    @ionitron-bot

    This issue has been labeled as help wanted. This label is added to issues that we believe would be good for contributors.

    If you'd like to work on this issue, please comment here letting us know that you would like to submit a pull request for it. This helps us to keep track of the pull request and make sure there isn't duplicated effort.

    For a guide on how to create a pull request and test this project locally to see your changes, see our contributing documentation.

    Thank you!

  3. ManthanBhatt commented on Mar 30, 2026

    @ManthanBhatt

    I investigated this and found the top-positioned infinite scroll test starts with scrollTop = 0, so the previous assertion path was depending on a racy initial scroll state. I’ve prepared a test fix that first scrolls down, waits until the content is actually offset, and then scrolls back to the top before waiting for ionInfiniteComplete. It passes locally for me in both Chrome and Safari.

  4. TheDerbiedOne commented on May 27, 2026

    @TheDerbiedOne

    I took a look at the flaky Safari CI test (core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts).

    Hypothesis
    On Safari CI the page can start the test already at (or extremely near) scrollTop=0. In that case scrollToTop(0) becomes a no-op and may never trigger ionInfiniteComplete, so the test can hang/fail.

    Proposed fix
    Force a small non-zero scroll offset first, wait until it’s observed, then scroll back to top and wait for ionInfiniteComplete. This avoids fixed timeouts.

    Patch (unified diff):

    diff --git a/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts b/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts
    index 4ca25b7e8d..9f1c0bb111 100644
    --- a/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts
    +++ b/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts
    @@ -1,16 +1,40 @@
     import { expect } from '@playwright/test';
    
     import { configs, test } from '@utils/test/playwright';
    
     configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
       test.describe(title('infinite-scroll: top'), () => {
         test('should load more items when scrolled to the top', async ({ page }) => {
           await page.goto('/src/components/infinite-scroll/test/top', config);
    
           const ionInfiniteComplete = await page.spyOnEvent('ionInfiniteComplete');
    
           const content = page.locator('ion-content');
           const items = page.locator('ion-item');
    
           expect(await items.count()).toBe(30);
    
    +      // Safari CI can start this test already at the top (or too close to it),
    +      // making scrollToTop a no-op that never triggers ion-infinite.
    +      // Force a non-zero scroll offset first, then scroll back to top.
    +      await content.evaluate(async (el: HTMLIonContentElement) => {
    +        const scrollEl = await el.getScrollElement();
    +        scrollEl.scrollTop = 100;
    +      });
    +
    +      await expect
    +        .poll(async () => {
    +          return await content.evaluate(async (el: HTMLIonContentElement) => {
    +            const scrollEl = await el.getScrollElement();
    +            return scrollEl.scrollTop;
    +          });
    +        })
    +        .toBeGreaterThan(0);
    +
           await content.evaluate((el: HTMLIonContentElement) => el.scrollToTop(0));
    
           await ionInfiniteComplete.next();
    
           expect(await items.count()).toBe(60);
         });
       });
     });
  5. TheDerbiedOne commented on May 27, 2026

    @TheDerbiedOne

    Hi! I drafted a small patch to stabilize the Safari CI flake described in #30423.

    Hypothesis: On Safari CI the test can start already at (or extremely near) scrollTop=0, so scrollToTop(0) becomes a no-op and never triggers ionInfiniteComplete.

    Fix: force a small non-zero scroll offset first (and verify it), then scroll back to top and wait for ionInfiniteComplete.

    Patch (unified diff):

    diff --git a/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts b/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts
    index 4ca25b7e8d..9f1c0bb111 100644
    --- a/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts
    +++ b/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts
    @@ -1,16 +1,40 @@
     import { expect } from '@playwright/test';
     
     import { configs, test } from '@utils/test/playwright';
     
     configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
       test.describe(title('infinite-scroll: top'), () => {
         test('should load more items when scrolled to the top', async ({ page }) => {
           await page.goto('/src/components/infinite-scroll/test/top', config);
     
           const ionInfiniteComplete = await page.spyOnEvent('ionInfiniteComplete');
     
           const content = page.locator('ion-content');
           const items = page.locator('ion-item');
     
           expect(await items.count()).toBe(30);
    +
    +      // Safari CI can start this test already at the top (or too close to it),
    +      // making scrollToTop a no-op that never triggers ion-infinite.
    +      // Force a non-zero scroll offset first, then scroll back to top.
    +      await content.evaluate(async (el: HTMLIonContentElement) => {
    +        const scrollEl = await el.getScrollElement();
    +        scrollEl.scrollTop = 100;
    +      });
    +
    +      await expect
    +        .poll(async () => {
    +          return await content.evaluate(async (el: HTMLIonContentElement) => {
    +            const scrollEl = await el.getScrollElement();
    +            return scrollEl.scrollTop;
    +          });
    +        })
    +        .toBeGreaterThan(0);
     
           await content.evaluate((el: HTMLIonContentElement) => el.scrollToTop(0));
     
           await ionInfiniteComplete.next();
     
           expect(await items.count()).toBe(60);
         });
       });
     });
  6. TheDerbiedOne commented on May 27, 2026

    @TheDerbiedOne

    I think this Safari CI flake can happen when the test starts already at (or extremely near) scrollTop=0, so scrollToTop(0) becomes a no-op and never triggers ionInfiniteComplete.
    Proposed fix: force a small non-zero scroll offset first (and poll until it’s observed), then scroll back to top and await ionInfiniteComplete.

    Patch (unified diff):

    diff --git a/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts b/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts
    index 4ca25b7e8d..9f1c0bb111 100644
    --- a/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts
    +++ b/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts
    @@ -1,16 +1,40 @@
    import { expect } from '@playwright/test';

    import { configs, test } from '@utils/test/playwright';

    configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
    test.describe(title('infinite-scroll: top'), () => {
    test('should load more items when scrolled to the top', async ({ page }) => {
    await page.goto('/src/components/infinite-scroll/test/top', config);

       const ionInfiniteComplete = await page.spyOnEvent('ionInfiniteComplete');
    
       const content = page.locator('ion-content');
       const items = page.locator('ion-item');
    
       expect(await items.count()).toBe(30);
    
    •  // Safari CI can start this test already at the top (or too close to it),
      
    •  // making scrollToTop a no-op that never triggers ion-infinite.
      
    •  // Force a non-zero scroll offset first, then scroll back to top.
      
    •  await content.evaluate(async (el: HTMLIonContentElement) => {
      
    •    const scrollEl = await el.getScrollElement();
      
    •    scrollEl.scrollTop = 100;
      
    •  });
      
    •  await expect
      
    •    .poll(async () => {
      
    •      return await content.evaluate(async (el: HTMLIonContentElement) => {
      
    •        const scrollEl = await el.getScrollElement();
      
    •        return scrollEl.scrollTop;
      
    •      });
      
    •    })
      
    •    .toBeGreaterThan(0);
      
       await content.evaluate((el: HTMLIonContentElement) => el.scrollToTop(0));
      
       await ionInfiniteComplete.next();
      
       expect(await items.count()).toBe(60);
      
      });
      });
      });
  7. TheDerbiedOne commented on May 27, 2026

    @TheDerbiedOne

    I took a pass at stabilizing the Safari CI flake described here.

    Hypothesis:
    On Safari CI, the test can start already at (or extremely near) scrollTop=0. In that case scrollToTop(0) becomes a no-op and doesn’t trigger the ionInfiniteComplete event, causing a hang/failure.

    Proposed fix:
    Before calling scrollToTop(0), force a small non-zero scroll offset, wait until that offset is observed, then scroll to top and wait for ionInfiniteComplete. This avoids adding fixed timeouts.

    Patch (unified diff):

    diff --git a/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts b/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts
    index 4ca25b7e8d..9f1c0bb111 100644
    --- a/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts
    +++ b/core/src/components/infinite-scroll/test/top/infinite-scroll.e2e.ts
    @@ -1,16 +1,40 @@
     import { expect } from '@playwright/test';
    
     import { configs, test } from '@utils/test/playwright';
    
     configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
       test.describe(title('infinite-scroll: top'), () => {
         test('should load more items when scrolled to the top', async ({ page }) => {
           await page.goto('/src/components/infinite-scroll/test/top', config);
    
           const ionInfiniteComplete = await page.spyOnEvent('ionInfiniteComplete');
    
           const content = page.locator('ion-content');
           const items = page.locator('ion-item');
    
           expect(await items.count()).toBe(30);
    +
    +      // Safari CI can start this test already at the top (or too close to it),
    +      // making scrollToTop a no-op that never triggers ion-infinite.
    +      // Force a non-zero scroll offset first, then scroll back to top.
    +      await content.evaluate(async (el: HTMLIonContentElement) => {
    +        const scrollEl = await el.getScrollElement();
    +        scrollEl.scrollTop = 100;
    +      });
    +
    +      await expect
    +        .poll(async () => {
    +          return await content.evaluate(async (el: HTMLIonContentElement) => {
    +            const scrollEl = await el.getScrollElement();
    +            return scrollEl.scrollTop;
    +          });
    +        })
    +        .toBeGreaterThan(0);
    
           await content.evaluate((el: HTMLIonContentElement) => el.scrollToTop(0));
    
           await ionInfiniteComplete.next();
    
           expect(await items.count()).toBe(60);
         });
       });
     });
  8. added a commit that references this issue on Nov 20, 2026
    7a70c50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedionfw-internship-2025type: bug

    Type

    Fields

    Stage

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions