Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last page error - Bad InfiniteScroll path option. Next link not found #691

Closed
einkoro opened this issue Jul 17, 2017 · 12 comments
Closed

Last page error - Bad InfiniteScroll path option. Next link not found #691

einkoro opened this issue Jul 17, 2017 · 12 comments

Comments

@einkoro
Copy link

einkoro commented Jul 17, 2017

If you load the last page of results directly where the path selector will no longer match any nodes it will throw the following error:

Bad InfiniteScroll path option. Next link not found: .page-numbers .next
Disabling InfiniteScroll
Uncaught TypeError: this.getPath is not a function
$( '.archive .products' ).infiniteScroll( {
    path: '.page-numbers .next',
    append: '.product',
    debug: true
} );

Test case: http://mmcurate.com/test/test-case-page-2.html

@desandro
Copy link
Member

Thanks for reporting this issue! I'll be adding a fix in the next release that will stop if getPath has not been set. Thanks so much for proving a test case 😄

@desandro desandro added the bug label Jul 19, 2017
@ogabrielsantos
Copy link

When a new release is planned @desandro?

desandro added a commit that referenced this issue Aug 4, 2017
@desandro
Copy link
Member

desandro commented Aug 4, 2017

v3.0.1 has been released with this fix added. Please update! Closing this issue has resolved 🌈🐻

@ogabrielsantos
Copy link

Receiving same error when we have only one page.

@raihan004
Copy link

this issue isn't fixed yet, or did miss something?
I'm using latest version.

@desandro desandro reopened this Oct 22, 2017
@zuicis
Copy link

zuicis commented Oct 24, 2017

Version: Infinite Scroll PACKAGED v3.0.2

Bad InfiniteScroll path option. Next link not found: .next a
Disabling InfiniteScroll

Issue on
a) on first page (if second not exist (small record count or user filtered content))
b) on last page (if you have multiple pages)

'pluginOptions' => [
'prefill' => true,
'append' => '.items > li',
'history' => true,
'path' => '.next a',
'debug' => false,
'status' => '.page-load-status',
//'hideNav' => '.pagination',
],

@vahidrk
Copy link

vahidrk commented Nov 2, 2017

Same issue here. Also in my case, pagination and loader both get visible.

@kavin-90
Copy link

same issue here.

@desandro
Copy link
Member

desandro commented Jan 12, 2018

To be clear, The Uncaught TypeError: this.getPath is not a function should be fixed as of v3.0.2. The other error messages still occur.

As of v3.0.2 the intended behavior is on last pages where Infinite Scroll is initialized and path is set to a selector string, and that selected element is not available; Infinite Scroll will log two error messages:

Bad InfiniteScroll path option. Next link not found: .pagination__next
Disabling InfiniteScroll

These are error messages and not thrown JS errors, so they will not disrupt JS. These messages are useful for users who have set path to the wrong element, or are trying to use Infinite Scroll on a page with out a next link in the HTML. It does mean that the error will occur on final pages. If this bugs you can you set your Infinite Scroll code in a conditional:

// jQuery
if ( $('.pagination__next').length ) {
  $('.container').infiniteScroll({
    path: '.pagination__next',
  });
}
// vanilla JS
if ( document.querySelector('.pagination__next') ) {
  var infScroll = new InfiniteScroll({
    path: '.pagination__next',
  });
}

@desandro desandro changed the title Last page results in Uncaught TypeError: this.getPath is not a function Bad InfiniteScroll path option. Next link not found error Jan 12, 2018
@desandro desandro changed the title Bad InfiniteScroll path option. Next link not found error Last page error - Bad InfiniteScroll path option. Next link not found Jan 12, 2018
@desandro desandro removed the bug label Aug 28, 2018
@desandro desandro closed this as completed Dec 6, 2020
@PetrDlouhy
Copy link

I don't think, that this is fixed properly, not even in 4.0.1.

When the single page result is loaded, infinite-scroll doesn't modify the page-load-status and doesn't hide pagination.

@PetrDlouhy
Copy link

I found out, that infinite-scroll probably expects those controls to be hidden on page load. This fixed the problem for me:

   $('.pagination').hide();
   $('.page-load-status').hide();

@subfighter3
Copy link

subfighter3 commented Jul 12, 2023

if ( document.querySelector('.pagination__next') ) {
  var infScroll = new InfiniteScroll({
    path: '.pagination__next',
  });
}

I tried to add this conditional but it broke the infinite scroll capability to load next pages in Safari only!

Here a screenshot of what happens with the conditional applied in Safari (left) and Firefox (right).
Looks like enclosing the infScroll variable in the conditional block prevent infinite scroll from loading the following pages!

Screenshot 2023-07-12 at 19 25 37

That said, probably it's not a good practice to enclose the infinite scroll code in a conditional, and maybe the "red" errors might become "yellow" alerts instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

9 participants