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

Disable Turbolinks support when not supported #650

Merged
merged 1 commit into from
Dec 26, 2016
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
##### Changed
- By using the hook on `turbolinks:before-visit` to unmount the components, we can ensure that components are unmounted even when Turbolinks cache is disabled. Previously, we used `turbolinks:before-cache` event hook. [#644](https://github.com/shakacode/react_on_rails/pull/644) by [volkanunsal](https://github.com/volkanunsal).
- Added support for Ruby 2.0 [#651](https://github.com/shakacode/react_on_rails/pull/651) by [bbonamin](https://github.com/bbonamin).
- Disable Turbolinks support when not supported. [#650](https://github.com/shakacode/react_on_rails/pull/650) by [ka2n](https://github.com/ka2n).

## [6.3.2] - 2016-12-5
##### Fixed
Expand Down
32 changes: 19 additions & 13 deletions node_package/src/clientStartup.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ function turbolinksVersion5() {
return (typeof Turbolinks.controller !== 'undefined');
}

function turbolinksSupported() {
return Turbolinks.supported;
Copy link
Member

Choose a reason for hiding this comment

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

  1. Is this compatible with v2 and v5 turbolinks?
  2. What browsers are not supported?

@ka2n

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Is this compatible with v2 and v5 turbolinks?

refer to turbolinks/turbolinks and turbolinks/turbolinks-classic repo and it's README.md,

  1. What browsers are not supported?

A browser that doesn't supporthistory.pushState nor requestAnimationFrame, Turbolinks.supported will return false. e.g. IE9-IE10 😩

In my use case, I don't find suitable polyfills/shims for that browser APIs.
But ReactDOM still supporting that old browsers, so React itself works fine.

}

function delegateToRenderer(componentObj, props, railsContext, domNodeId, trace) {
const { name, component, isRenderer } = componentObj;

Expand Down Expand Up @@ -175,23 +179,25 @@ export function clientStartup(context) {
// We must do this check for turbolinks AFTER the document is loaded because we load the
// Webpack bundles first.

if (!turbolinksInstalled()) {
if (turbolinksInstalled() && turbolinksSupported()) {
if (turbolinksVersion5()) {
debugTurbolinks(
'USING TURBOLINKS 5: document added event listeners ' +
' turbolinks:before-visit and turbolinks:load.');
document.addEventListener('turbolinks:before-visit', reactOnRailsPageUnloaded);
document.addEventListener('turbolinks:load', reactOnRailsPageLoaded);
} else {
debugTurbolinks(
'USING TURBOLINKS 2: document added event listeners page:before-unload and ' +
'page:change.');
document.addEventListener('page:before-unload', reactOnRailsPageUnloaded);
document.addEventListener('page:change', reactOnRailsPageLoaded);
}
} else {
debugTurbolinks(
'NOT USING TURBOLINKS: DOMContentLoaded event, calling reactOnRailsPageLoaded',
);
reactOnRailsPageLoaded();
} else if (turbolinksVersion5()) {
debugTurbolinks(
'USING TURBOLINKS 5: document added event listeners ' +
' turbolinks:before-visit and turbolinks:load.');
document.addEventListener('turbolinks:before-visit', reactOnRailsPageUnloaded);
document.addEventListener('turbolinks:load', reactOnRailsPageLoaded);
} else {
debugTurbolinks(
'USING TURBOLINKS 2: document added event listeners page:before-unload and ' +
'page:change.');
document.addEventListener('page:before-unload', reactOnRailsPageUnloaded);
document.addEventListener('page:change', reactOnRailsPageLoaded);
}
});
}