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

TypeError: elem is undefined - custom query #779

Closed
p-drolima opened this issue Mar 28, 2018 · 6 comments
Closed

TypeError: elem is undefined - custom query #779

p-drolima opened this issue Mar 28, 2018 · 6 comments
Labels

Comments

@p-drolima
Copy link

p-drolima commented Mar 28, 2018

Hi Desandro,

Hope you well. I am not 100% sure what this error means but I really cant see a solution for this so perhaps might be some kind of bug?

I have a custom wordpress query for which I get the correct return from server but then infinite scroll gives me TypeError: elem is undefined when loading next page.

http://www.dawaf.co.uk/usfew/site/page/2/

Can you please see what is going on here?

Thank you in advance!

@p-drolima
Copy link
Author

if you go to that link you will see a var_dump of count($query->posts) which means the query does return the correct amount of posts for next page but it does not display them which is the job of infnite-scroll

@desandro
Copy link
Member

Thanks for reporting this bug. I'm not seeing it occur when I visit. Were you able to resolve this?

@p-drolima
Copy link
Author

Hi,

Sorry, my client changed a setting. Let me put back the right setting.

@p-drolima
Copy link
Author

ok, its back if you want to check. I have debug set to true

@desandro
Copy link
Member

Thanks for that. Looks like you're running into a bug with Infinite Scroll because the second page does not contain any elements used for append:

append: '.uf-grid-item',

Two fixes. 1 add .uf-grid-item elements to page/2. 2: add this code to main.js before initializing Infinite Scroll prevent Infinite Scroll from causing the error:

InfiniteScroll.prototype.onAppendHistory = function( response, path, items ) {
  if ( !items || !items.length ) {
    return;
  }
  var firstItem = items[0];
  var elemScrollY = this.getElementScrollY( firstItem );
  // resolve path
  link.href = path;
  // add page data to hash
  this.scrollPages.push({
    top: elemScrollY,
    path: link.href,
    title: response.title,
  });
};

I'll be adding this fix in the next release.

@desandro
Copy link
Member

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

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

2 participants