Skip to content

Commit d164e75

Browse files
committed
Run reactOnRailsPageLoaded() even when DOM was already loaded
This handles <script async> transparently
1 parent e86090f commit d164e75

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ See [Upgrading React on Rails](./docs/basics/upgrading-react-on-rails.md) for mo
99
Changes since last non-beta release.
1010

1111
*Please add entries here for your pull requests that are not yet released.*
12+
- Handle <script async> for Webpack bundle transparently. Closes [issue #290](https://github.com/shakacode/react_on_rails/issues/290) [PR 1099](https://github.com/shakacode/react_on_rails/pull/1099) by [squadette](https://github.com/squadette).
1213

1314
#### Changed
1415
- Document how to manually rehydrate XHR-substituted components on client side. [PR 1095](https://github.com/shakacode/react_on_rails/pull/1095) by [hchevalier](https://github.com/hchevalier).
@@ -87,7 +88,7 @@ both the gem and the node package get the updates. This change ensures that the
8788

8889
### [10.1.3] - 2018-02-28
8990
#### Fixed
90-
- Improved error reporting on version mismatches between Javascript and Ruby packages. [PR 1025](https://github.com/shakacode/react_on_rails/pull/1025) by [theJoeBiz](https://github.com/squadette).
91+
- Improved error reporting on version mismatches between Javascript and Ruby packages. [PR 1025](https://github.com/shakacode/react_on_rails/pull/1025) by [squadette](https://github.com/squadette).
9192

9293
### [10.1.2] - 2018-02-27
9394
#### Fixed

node_package/src/clientStartup.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,27 @@ export function clientStartup(context) {
196196

197197
debugTurbolinks('Adding DOMContentLoaded event to install event listeners.');
198198

199+
window.setTimeout(() => {
200+
if (!turbolinksInstalled() || !turbolinksSupported()) {
201+
if (document.readyState === 'complete' ||
202+
(document.readyState !== 'loading' && !document.documentElement.doScroll)
203+
) {
204+
debugTurbolinks(
205+
'NOT USING TURBOLINKS: DOM is already loaded, calling reactOnRailsPageLoaded',
206+
);
207+
208+
reactOnRailsPageLoaded();
209+
} else {
210+
document.addEventListener('DOMContentLoaded', () => {
211+
debugTurbolinks(
212+
'NOT USING TURBOLINKS: DOMContentLoaded event, calling reactOnRailsPageLoaded',
213+
);
214+
reactOnRailsPageLoaded();
215+
});
216+
}
217+
}
218+
});
219+
199220
document.addEventListener('DOMContentLoaded', () => {
200221
// Install listeners when running on the client (browser).
201222
// We must do this check for turbolinks AFTER the document is loaded because we load the
@@ -216,11 +237,6 @@ export function clientStartup(context) {
216237
document.addEventListener('page:before-unload', reactOnRailsPageUnloaded);
217238
document.addEventListener('page:change', reactOnRailsPageLoaded);
218239
}
219-
} else {
220-
debugTurbolinks(
221-
'NOT USING TURBOLINKS: DOMContentLoaded event, calling reactOnRailsPageLoaded',
222-
);
223-
reactOnRailsPageLoaded();
224240
}
225241
});
226242
}

0 commit comments

Comments
 (0)