Comments (13)
@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.
Ok, thanks, sorry in a crunch and have not been able to do more testing yet. Thanks again.
from render_async.
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.
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.
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.
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.
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.
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.
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.
@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.
@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.
from render_async.
Awesome, @vanboom, can you please create another issue as a feature request that will start polling on load? 🙇
from render_async.
Related Issues (20)
- preventDefault() in toggle code interferes with other UI functionality HOT 2
- Feature idea: Render async with ActiveJob & ActionCable HOT 2
- Render_async on header HOT 2
- Duplication of injected JS for nested async templates HOT 1
- Start polling immediately option when toggle is specified HOT 1
- Manual retry based on JS event HOT 3
- Idea: only fire the AJAX request on scroll (Lazy Partials) HOT 1
- Event driven reloads. HOT 3
- Polling: vanilla js has code that runs before document has finished loading HOT 2
- Feature request: Refresh with event HOT 5
- Feature: Append or prepend content on toggle HOT 1
- Content flashes on page revisit even with Turbolinks enabled HOT 6
- render_async issues with container_id and turbolinks : not reloading or JS not firing on new visit depending on configuration HOT 5
- Add Support for Turbo HOT 3
- Add delay before performing async call HOT 4
- content_for :render_async does nothing. HOT 1
- With Caching enabled, event_name is not triggered as content_for is missing on page reload HOT 5
- Turbo: Toggable selector not executing the event_listener function set by _setUpToggle on a new visit HOT 1
- JS scripts not loading synchronously HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from render_async.