GithubHelp home page GithubHelp logo

Comments (13)

vanboom avatar vanboom commented on May 23, 2024 3

@nikolalsvk, EDIT - 2.1.6 still exhibits this issue, sorry. The render_async javascript is being delayed beyond where I am attempting to trigger the polling. My view code looks like this...

  = render_async job_path(@job_id), interval: 1250, toggle:{selector: '#render_async_control', event: 'toggle_polling'}

:javascript
  $(document).ready(function(){
    $("#render_async_control").trigger("toggle_polling");
  });

Unfortunately I am not able to reproduce or understand the bug described in #90 that prompted this change. I suspect that the bug reported in #90 was caused by the content_for(:render_async) block being placed before the view code in the layout.

This work around works to effectively delay the click trigger...

$(window).bind('load', function() {
  $("#id-of-your-button").trigger('click');
});

CAUTION: $(window).bind('load'...) event is not called if the view is rendered in a modal or popup so this solution will not work everywhere.

from render_async.

vanboom avatar vanboom commented on May 23, 2024 1

Ok, thanks, sorry in a crunch and have not been able to do more testing yet. Thanks again.

from render_async.

vanboom avatar vanboom commented on May 23, 2024

This works...

  $(window).bind('load', function(){
    $("#async-trigger").trigger('click');
  });

See _request.jquery.js.erb;116
_setUpToggle is now being delayed until after document loaded which I guess happens after the $(document).ready() phase?

from render_async.

nikolalsvk avatar nikolalsvk commented on May 23, 2024

Hey, @vanboom! Thanks for submitting an issue about this. I'm sorry your functionality got broken with the new 2.1.5 version.

This behavior was intended to happen, I'll update the release info after this. 2.1.5 version brought a change where toggle event listeners would add after the page has loaded. This fixed a bug where event handlers would try to attach to elements that were not yet loaded.

Hope this explained a bit more why this happened.

As for the solution to your problem, I suggest the following. Since you're using jQuery, turn on jQuery logic for render_async. You mentioned that this part of the code was working before

  $(document).ready(function() {
    $("#async-trigger").trigger('click');
  });

And it should work with jQuery turned on.

# This will render jQuery code, and skip Vanilla JS code
RenderAsync.configuration.jquery = true

Can you try this out and let me know how it goes? 🙏

from render_async.

vanboom avatar vanboom commented on May 23, 2024

Unfortunately I am already using jQuery - in my case my call to trigger('click') is happening before the call to _setupToggle();

I suspect that this is due to the placement of my content_for :render_async block which is near the end of the html body. For some reason, I am not able to reproduce the issue as described in #90, perhaps that is caused by a similar placement issue of the content_for and the view-rendered javascript.

from render_async.

nikolalsvk avatar nikolalsvk commented on May 23, 2024

Right, can you post some code on how you call trigger('click') in your code? Have you tried wrapping it inside

$(document).ready(function() {
  $("#id-of-your-button").trigger('click');
});

Also, are you using Turbolinks by any chance?

from render_async.

nikolalsvk avatar nikolalsvk commented on May 23, 2024

If this still doesn't work due to the position of the triggering JS code and the render_async JS code, we'd have to add a new event. The new event would trigger when all the event listeners are attached in the _setupToggle() function.

Please check the previous comment, and respond if it's working for you so we can figure out the next steps :)

from render_async.

nikolalsvk avatar nikolalsvk commented on May 23, 2024

Can you try this out in the new 2.1.6 version. Maybe it will work with what you originally posted here #108 (comment)

If it's still a problem, we can reopen this issue and deal with it.

from render_async.

nikolalsvk avatar nikolalsvk commented on May 23, 2024

Hey, @vanboom, I'm wondering, is it necessary to trigger render_async using JavaScript in your project?

You could just start polling immediately, without having to toggle polling. Is this an option for you?

from render_async.

vanboom avatar vanboom commented on May 23, 2024

@nikolalsvk, good idea, however as I understand, to allow the user to start/stop polling the toggle feature has to be used, which will not start polling immediately by default?

from render_async.

nikolalsvk avatar nikolalsvk commented on May 23, 2024

@vanboom exactly, I was thinking of adding an option to start polling immediately with the toggle feature. For example, render_async will start polling on the page load, but the user can still turn polling on/off after that if he wants. Would this be something you are interested in?

from render_async.

vanboom avatar vanboom commented on May 23, 2024

from render_async.

nikolalsvk avatar nikolalsvk commented on May 23, 2024

Awesome, @vanboom, can you please create another issue as a feature request that will start polling on load? 🙇

from render_async.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.