-
-
Notifications
You must be signed in to change notification settings - Fork 632
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
React on Rails and async loading of application.js #290
Comments
@SqueezedLight Any research you can do this topic would be greatly appreciated! I think this already does what you need:
We simply need to export the function and expose it here in the main ReactOnRails js class. Can you try that out and send a PR including:
Thanks! |
@justin808 Thanks, i didn't see that in the first place. I'm on it... |
@SqueezedLight Any update? Should we leave this issue open? |
@justin808 Sorry, i had to manage some really stressful days... Yes, there is some progress: Exposing So i managed to get everything working with async script loading. I hope i can make the PR on the weekend. |
Merged with version 6.0.0-rc.1 |
If I want to load the js async, do I just add Or is there more settings I need to configure? |
@xiaopow I don't know off the top of my head. Please research this and report back to us, and that will help the community. |
@xiaopow, @nateberkopec has some done some amazing research into this area. Nate, can you give us a few links to your materials? |
I ran into the same problem, where my javascript wasn't executed reliably when loading my generated A quick workaround was this snippet:
I am not sure if I need the event listener since this might be what react_on_rails is doing to initialize the components and it will fail if the DOM had finished loading when the JS is loaded. Maybe someone knows a better way, or did I miss something from the docs? Nowadays it should be the preferred way to load the JS async (especially when prerendering components). |
Dropped about 200ms from page load time on `posts#index` locally. Some folks [have reported issues](shakacode/react_on_rails#290) with this, but it seems to be working fine for me. I calculated page load time with this: ``` var loadTime = window.performance.timing.domContentLoadedEventEnd - window.performance.timing.navigationStart; ```
Fixes #290, transparently handling <script async> tag. If the document was already loaded, the DOMContentLoaded event handler no longer fires, so we just execute it directly, the same way as jQuery does in $.ready(). Co-authored-by: Alexey Makhotkin
* Handle <script async> transparently #1099 Fixes #290, transparently handling <script async> tag. If the document was already loaded, the DOMContentLoaded event handler no longer fires, so we just execute it directly, the same way as jQuery does in $.ready(). * Added async tag to spec/dummy Co-authored-by: Alexey Makhotkin
Is there an official way of doing this in React on Rails now, instead of the solution @dpuscher mentioned above? |
@julianguyen I'm sure this is somewhere in the docs. Here's an example: you need to use defer: <!-- NOTE: Must use defer and not async to keep async scripts loading in correct order -->
<%= javascript_pack_tag('vendor-bundle', 'data-turbolinks-track': true, defer: true) %>
<%= javascript_pack_tag('app-bundle', 'data-turbolinks-track': true, defer: true) %> |
@justin808 Why does |
@julianguyen If you don't use turbolinks, you get problems. #1150 |
@julianguyen if you are not using turbolinks, remove that part. |
Hi guys,
i'm wondering if there is any possibility to use react on rails with async loading like:
In this case, the
componentDidMount
does not get fired. The issue is well known, described and fixed here: reactjs/react-rails#218What i'm searching for is a hook, like
ReactRailsUJS.mountComponents()
. Right now i'm trying to write something likemountComponents()
but i did not have success until now. That's why i'm wondering if i'm missing something?Thanks a lot in advance.
The text was updated successfully, but these errors were encountered: