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

Path function to returns null on init #776

Closed
otterslide opened this issue Mar 26, 2018 · 6 comments
Closed

Path function to returns null on init #776

otterslide opened this issue Mar 26, 2018 · 6 comments
Labels

Comments

@otterslide
Copy link

When my path function returns null/false/undefined, it causes an error.
I have logic that at a certain point, the path function returns null, meaning no more pages.
How can I tell infinite scroll there are no more pages to load?

@desandro
Copy link
Member

Thanks for reporting this issue. Can you provide a reduced test case? Try forking this demo which uses a path function: https://codepen.io/desandro/pen/ZxXNgR/

@otterslide
Copy link
Author

Ok, it seems that it only happens if the initial call to the path function is null:
https://codepen.io/otterslide/pen/mxBZJP

infinite-scroll.pkgd.js:851 Uncaught TypeError: Cannot read property 'match' of null
at InfiniteScroll.proto.updateGetAbsolutePath (VM500 infinite-scroll.pkgd.js:851)
at InfiniteScroll.proto.create (VM500 infinite-scroll.pkgd.js:658)
at new InfiniteScroll (VM500 infinite-scroll.pkgd.js:620)
at VM501 pen.js:18

I should probably check if there are additional pages before even initializing infinite scroll in this case. I was checking in the Path function.

@desandro
Copy link
Member

Thanks for that! I've added a fix that will go out in the next release.

@desandro desandro added the bug label Mar 26, 2018
@desandro desandro changed the title Path function to return Null Path function to returns null on init Mar 26, 2018
@desandro
Copy link
Member

🎉 v3.0.4 has been released with this fix added. Please update!

@matthiasprieth
Copy link

matthiasprieth commented Dec 20, 2018

Hi, thanks for the fix. :)

  • I came across the error message you've added & realized that my loader-ellips infinite-scroll-request-class is still showing up & not set to display: none. So when the error is thrown I guess the logic to hide it via script (and maybe showing "End of content" instead) is still missing.
    In my case I just resolved it by setting loader-ellips infinite-scroll-request to display: none via a hidden class in my css-file at first render.
<div class="page-load-status">
  <div class="loader-ellips infinite-scroll-request hidden">
    <span class="loader-ellips__dot"></span>
    <span class="loader-ellips__dot"></span>
    <span class="loader-ellips__dot"></span>
    <span class="loader-ellips__dot"></span>
  </div>
  <p class="infinite-scroll-last">End of content</p>
  <p class="infinite-scroll-error">No more pages to load</p>
</div>
  • Also It would be nice to have something else than "console.error" echoing the message. It looks like an error but it isn't?

@dstopp
Copy link

dstopp commented May 31, 2019

for responseType: "text", i tried returning either nothing or null from path: option on end of data, but what i got was: infinite-scroll.pkgd.js:1265 GET http://127.0.0.1:8000/opus/null 404 (Not Found).
Looking at the code w/a cursory glance, it seems that:

function request( url, responseType, onLoad, onError, onLast ) {
  var req = new XMLHttpRequest();
  req.open( 'GET', url, true );

needs to check to see if url is undefined or empty string but it doesn't; it treats it like a regular value. This seems to be really unfabulous...

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

No branches or pull requests

4 participants