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

Handle <script async> transparently #1099

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ See [Upgrading React on Rails](./docs/basics/upgrading-react-on-rails.md) for mo
Changes since last non-beta release.

*Please add entries here for your pull requests that are not yet released.*
- 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).

#### Changed
- 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).
Expand Down Expand Up @@ -87,7 +88,7 @@ both the gem and the node package get the updates. This change ensures that the

### [10.1.3] - 2018-02-28
#### Fixed
- 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).
- 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).

### [10.1.2] - 2018-02-27
#### Fixed
Expand Down
26 changes: 21 additions & 5 deletions node_package/src/clientStartup.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,27 @@ export function clientStartup(context) {

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

window.setTimeout(() => {
if (!turbolinksInstalled() || !turbolinksSupported()) {
if (document.readyState === 'complete' ||

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this break if the readyState is interactive?

(document.readyState !== 'loading' && !document.documentElement.doScroll)
) {
debugTurbolinks(
'NOT USING TURBOLINKS: DOM is already loaded, calling reactOnRailsPageLoaded',
);

reactOnRailsPageLoaded();
} else {
document.addEventListener('DOMContentLoaded', () => {
debugTurbolinks(
'NOT USING TURBOLINKS: DOMContentLoaded event, calling reactOnRailsPageLoaded',
);
reactOnRailsPageLoaded();
});
}
}
});

document.addEventListener('DOMContentLoaded', () => {
// Install listeners when running on the client (browser).
// We must do this check for turbolinks AFTER the document is loaded because we load the
Expand All @@ -216,11 +237,6 @@ export function clientStartup(context) {
document.addEventListener('page:before-unload', reactOnRailsPageUnloaded);
document.addEventListener('page:change', reactOnRailsPageLoaded);
}
} else {
debugTurbolinks(
'NOT USING TURBOLINKS: DOMContentLoaded event, calling reactOnRailsPageLoaded',
);
reactOnRailsPageLoaded();
}
});
}