nikolalsvk / render_async

render_async lets you include pages asynchronously with AJAX
https://rubygems.org/gems/render_async/
MIT License
1.08k stars 75 forks source link

Can not stop polling after page navigation changes. #100

Closed vinitsharma87 closed 4 years ago

vinitsharma87 commented 4 years ago

Hi, Is there a way to stop the polling once user navigates to a different page other than the one in which a 'render_async' partial is rendered.

Another problem case I found is as under:

Can anyone help with above problems please.

Thanks.

nikolalsvk commented 4 years ago

Hi, @vinitsharma87! Thanks for submitting the issue.

There's a way to start and stop polling when interacting with an element on the page. There's no option to do it when you switch pages because when you switch pages, new JavaScript gets loaded.

Are you maybe using Turbolinks? It sounds to me like you are. There's a way to use render_async with Turbolinks, maybe that helps.

Tell me if this solves your problem!

nikolalsvk commented 4 years ago

I'm closing this due to inactivity. If this still persists, feel free to reopen the issue or comment!

tristang commented 4 years ago

Hi @nikolalsvk. I'm actually having this problem too.

I've set the config to turbolinks = true as instructed in the docs, but find that when I load one page with a render_async element with an interval set, then navigate away (using Turbolinks), the setInterval continues firing on the new page. It successfully fetches the content each time, but throws an error because the target element to put it in is no longer in the page (Uncaught TypeError: Cannot set property 'innerHTML' of null at XMLHttpRequest.request.onreadystatechange).

It looks as though the turbolinks config option handles removing event listeners on turbolinks:load, but I don't see anywhere that clearInterval is called in response to a Turbolink navigation.

Let me know if this sounds right.

Thanks for your work on this project!

nikolalsvk commented 4 years ago

Thanks for the info @tristang! I'll look more into this

nikolalsvk commented 4 years ago

Hey, folks (@vinitsharma87 and @tristang), I released a fix for this in 2.1.6. Let me know if it works out for you!