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: Cannot read property 'length' of undefined when using steps #163

Closed
mulder-brewing opened this issue Jun 13, 2019 · 8 comments
Closed

Comments

@mulder-brewing
Copy link

I am using the steps, which is working great. The problem is when I navigate from a index page which has a list of things with many pages and go to say a static page like my home page, and resize the window, I'm getting a ton of errors in the console and they won't stop coming until I navigate to a page other than my Rails app. It seems like the window listener is still trying to fire on the page resizing and it doesn't like that there's no pagy on the static page. If there's something I can be doing differently, please let me know.

Pagy::VARS[:steps] = { 0 => [1,0,0,1], 540 => [1,2,2,1], 720 => [1,4,4,1], 992 => [1,7,7,1], 1200 => [1,9,9,1], 1400 => [1,11,11,1], 1600 => [1,13,13,1], 1800 => [1,15,15,1], 1900 => [1,17,17,1] }

image

image

@ddnexus
Copy link
Owner

ddnexus commented Jun 13, 2019

That looks like a bug... I will look into it during the weekend. Thanks.

@ddnexus
Copy link
Owner

ddnexus commented Jun 16, 2019

I tried it, but it works well here.

Could you create a minimal app that has the problem, so I could try reproduce it?
You should be able to avoid any DB (removing the paginated elements, showing only the pagy navs), or please use sqlite, so I will be able to use it without installing anything.
Thanks

@mulder-brewing
Copy link
Author

Thanks for checking. I tried creating a whole new app with similar setup and didn't have luck reproducing it in that app yet. I will dive into it more tomorrow and hopefully reproduce it or figure out what's wrong in my main app.

@ddnexus
Copy link
Owner

ddnexus commented Jun 22, 2019

Please, let me know what is the problem even if it is in your own app: it might be worth a warning in the doc, helping other users to avoid it.

@mulder-brewing
Copy link
Author

I was able to reproduce it. It has to do with the Rails link_to and probably turbolinks? This app is setup with a home page with a link to a index page and then a link back to the home page. There is a seed to seed it with some test data. If you click the link to go to the index page, and then click the link to go back to the home page, and then resize the window, the errors start flowing. If you don' use the link and just type the localhost URL or use your browser bookmark to go back to the home page, no errors.

https://github.com/mulder-brewing/pagy_bug_app

@ddnexus
Copy link
Owner

ddnexus commented Jun 23, 2019

That's a very useful app and analysis. I will look into that ASAP. Thank you!

@ddnexus
Copy link
Owner

ddnexus commented Jul 2, 2019

@mulder-brewing please, try the dev branch. It should be fixed.

@mulder-brewing
Copy link
Author

Awesome, no more errors! Thanks so much!

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

No branches or pull requests

2 participants