Skip to content

Commit

Permalink
Disable Turbolinks support when not supported
Browse files Browse the repository at this point in the history
By checking with Turbolinks.supported API, fallback unsupported browser to non Turbolinks mode.
  • Loading branch information
ka2n committed Dec 20, 2016
1 parent 93fb10b commit 5ba3494
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ All notable changes to this project's source code will be documented in this fil
Contributors: please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version.

## [Unreleased]
*Please add entries here for your pull requests.*
##### Fixed
- Disable Turbolinks support when not supported.

## [6.3.2] - 2016-12-5
##### Fixed
Expand Down
34 changes: 20 additions & 14 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;
}

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

Expand Down Expand Up @@ -175,24 +179,26 @@ 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-cache and ' +
'turbolinks:load.',
);
document.addEventListener('turbolinks:before-cache', 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-cache and ' +
'turbolinks:load.',
);
document.addEventListener('turbolinks:before-cache', 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);
}
});
}

0 comments on commit 5ba3494

Please sign in to comment.