Skip to content

fix(prefill): respect loadOnScroll flag in _prefillNext to prevent auto-load in trigger mode (#886)#888

Open
Hoang130203 wants to merge 1 commit intowebcreate:masterfrom
Hoang130203:fix/trigger-mode-unexpected-prefill-on-reload
Open

fix(prefill): respect loadOnScroll flag in _prefillNext to prevent auto-load in trigger mode (#886)#888
Hoang130203 wants to merge 1 commit intowebcreate:masterfrom
Hoang130203:fix/trigger-mode-unexpected-prefill-on-reload

Conversation

@Hoang130203
Copy link
Copy Markdown

Problem

Fixes #886

When using trigger mode, a page load is triggered automatically on reload — even though the user never clicked the trigger button.

Root cause

The flow on reload with trigger mode:

  1. IAS initialises with loadOnScroll: true (default — user doesn't need to set loadOnScroll: false explicitly when using a trigger)
  2. BINDED event fires, handlers execute in registration order:
    • Trigger.bind()update(pageIndex) → voter returns truedisableLoadOnScroll()loadOnScroll = false
    • prefill.prefill()_prefillNext() → checks distance() → if the browser restored scroll position near the sentinel (within negativeMargin), distance <= 0this.ias.next() is called unconditionally

_prefillNext() called next() directly without checking loadOnScroll, bypassing the trigger mode guard entirely.

Fix

Add a loadOnScroll check at the top of _prefillNext():

_prefillNext() {
  if (!this.ias.loadOnScroll) {
    return;  // trigger mode (or explicit loadOnScroll: false) — don't auto-load
  }
  // ... rest unchanged
}

This is consistent with how the main HIT event handler in infinite-ajax-scroll.js already guards next():

this.on(Events.HIT, () => {
  if (!this.loadOnScroll) {
    return;
  }
  this.next();
});

Prefill should respect the same flag.

Repro steps

  1. Configure IAS with a trigger (no explicit loadOnScroll: false)
  2. Scroll down until the trigger button is visible in the viewport
  3. Reload the page (browser restores scroll position)
  4. Before fix: next page loads automatically
  5. After fix: trigger button is shown, no auto-load occurs

…to-load in trigger mode (webcreate#886)

When using trigger mode, Trigger.bind() calls ias.disableLoadOnScroll()
during the BINDED event. However, prefill._prefillNext() was calling
ias.next() directly without checking the loadOnScroll flag, bypassing
trigger mode entirely.

This caused an unwanted automatic page load on reload when:
1. The user configured trigger mode (no loadOnScroll: false explicitly)
2. The browser restored scroll position near the sentinel
3. Prefill ran and saw distance <= 0, firing next() unconditionally

Fix: guard _prefillNext() with a loadOnScroll check so that when trigger
mode (or any other mechanism) disables auto-loading, prefill respects it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected page load on reload when using trigger mode

1 participant