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

Can not stop polling after page navigation changes. #100

Closed
vinitsharma87 opened this issue Jan 1, 2020 · 5 comments · Fixed by #113
Closed

Can not stop polling after page navigation changes. #100

vinitsharma87 opened this issue Jan 1, 2020 · 5 comments · Fixed by #113

Comments

@vinitsharma87
Copy link

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:

  • I have my main page M1 in which I am rendering a partial P1 through render_async with a set interval of 30 seconds.
  • The problem I found is that, when M1 is navigated by clicking on some link, in that case the partial P1's part does not gets shown at all (on first load) and instead the html part shown for asynchronous waiting time is getting shown until 30 seconds is passed and a refresh occurs.
  • And when I am already on page M1 and hit a refresh (Ctrl.+ F5), in this case the partial P1 part gets shown properly after page gets loaded.

Can anyone help with above problems please.

Thanks.

@nikolalsvk
Copy link
Owner

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
Copy link
Owner

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

@tristang
Copy link

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 nikolalsvk reopened this Apr 14, 2020
@nikolalsvk
Copy link
Owner

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

@nikolalsvk
Copy link
Owner

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

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

Successfully merging a pull request may close this issue.

3 participants