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

Fix Turbolinks Detection #802

Merged
merged 3 commits into from
Oct 10, 2017
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
2 changes: 1 addition & 1 deletion lib/assets/javascripts/react_ujs.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var turbolinksClassicEvents = __webpack_require__(10)
module.exports = function(ujs) {
if (ujs.handleEvent) {
// We're calling this a second time -- remove previous handlers
if (typeof Turbolinks.EVENTS !== "undefined") {
if (typeof Turbolinks !== "undefined" && typeof Turbolinks.EVENTS !== "undefined") {
turbolinksClassicEvents.teardown(ujs);
}
turbolinksEvents.teardown(ujs);
Expand Down
2 changes: 1 addition & 1 deletion react_ujs/dist/react_ujs.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var turbolinksClassicEvents = __webpack_require__(10)
module.exports = function(ujs) {
if (ujs.handleEvent) {
// We're calling this a second time -- remove previous handlers
if (typeof Turbolinks.EVENTS !== "undefined") {
if (typeof Turbolinks !== "undefined" && typeof Turbolinks.EVENTS !== "undefined") {
turbolinksClassicEvents.teardown(ujs);
}
turbolinksEvents.teardown(ujs);
Expand Down
2 changes: 1 addition & 1 deletion react_ujs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react_ujs",
"version": "2.2.1",
"version": "2.3.1",
"description": "Rails UJS for the react-rails gem",
"main": "index.js",
"repository": "reactjs/react-rails",
Expand Down
2 changes: 1 addition & 1 deletion react_ujs/src/events/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var turbolinksClassicEvents = require("./turbolinksClassic")
module.exports = function(ujs) {
if (ujs.handleEvent) {
// We're calling this a second time -- remove previous handlers
if (typeof Turbolinks.EVENTS !== "undefined") {
if (typeof Turbolinks !== "undefined" && typeof Turbolinks.EVENTS !== "undefined") {
turbolinksClassicEvents.teardown(ujs);
}
turbolinksEvents.teardown(ujs);
Expand Down
36 changes: 20 additions & 16 deletions react_ujs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,14 @@ emojis-list@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"

enhanced-resolve@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.1.0.tgz#9f4b626f577245edcf4b2ad83d86e17f4f421dec"
enhanced-resolve@^3.3.0:
version "3.4.1"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.4.1.tgz#0421e339fd71419b3da13d129b3979040230476e"
dependencies:
graceful-fs "^4.1.2"
memory-fs "^0.4.0"
object-assign "^4.0.1"
tapable "^0.2.5"
tapable "^0.2.7"

errno@^0.1.3:
version "0.1.4"
Expand Down Expand Up @@ -1428,9 +1428,9 @@ sntp@1.x.x:
dependencies:
hoek "2.x.x"

source-list-map@^1.1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-1.1.2.tgz#9889019d1024cce55cdc069498337ef6186a11a1"
source-list-map@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.0.tgz#aaa47403f7b245a92fbc97ea08f250d6087ed085"

source-map@^0.5.3, source-map@~0.5.1, source-map@~0.5.3:
version "0.5.6"
Expand Down Expand Up @@ -1525,7 +1525,11 @@ supports-color@^3.1.0:
dependencies:
has-flag "^1.0.0"

tapable@^0.2.5, tapable@~0.2.5:
tapable@^0.2.7:
version "0.2.8"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.8.tgz#99372a5c999bf2df160afc0d74bed4f47948cd22"

tapable@~0.2.5:
version "0.2.6"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.6.tgz#206be8e188860b514425375e6f1ae89bfb01fd8d"

Expand Down Expand Up @@ -1645,23 +1649,23 @@ watchpack@^1.3.1:
chokidar "^1.4.3"
graceful-fs "^4.1.2"

webpack-sources@^0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-0.2.3.tgz#17c62bfaf13c707f9d02c479e0dcdde8380697fb"
webpack-sources@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.1.tgz#c7356436a4d13123be2e2426a05d1dad9cbe65cf"
dependencies:
source-list-map "^1.1.1"
source-list-map "^2.0.0"
source-map "~0.5.3"

webpack@^2.3.3:
version "2.6.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-2.6.1.tgz#2e0457f0abb1ac5df3ab106c69c672f236785f07"
version "2.7.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-2.7.0.tgz#b2a1226804373ffd3d03ea9c6bd525067034f6b1"
dependencies:
acorn "^5.0.0"
acorn-dynamic-import "^2.0.0"
ajv "^4.7.0"
ajv-keywords "^1.1.1"
async "^2.1.2"
enhanced-resolve "^3.0.0"
enhanced-resolve "^3.3.0"
interpret "^1.0.0"
json-loader "^0.5.4"
json5 "^0.5.1"
Expand All @@ -1675,7 +1679,7 @@ webpack@^2.3.3:
tapable "~0.2.5"
uglify-js "^2.8.27"
watchpack "^1.3.1"
webpack-sources "^0.2.3"
webpack-sources "^1.0.1"
yargs "^6.0.0"

which-module@^1.0.0:
Expand Down
1 change: 1 addition & 0 deletions test/dummy_sprockets/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
//= link application.js
//= link turbolinks_only.js
//= link application.css
//= link app_no_turbolinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= require react
//= require react_ujs
//= require_tree ./components
5 changes: 5 additions & 0 deletions test/dummy_sprockets/app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ def show
js_context.exec("global.ctx = undefined;")
end
end

def no_turbolinks
@prerender = false
render :show, layout: 'app_no_turbolinks'
end
end
13 changes: 13 additions & 0 deletions test/dummy_sprockets/app/views/layouts/app_no_turbolinks.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy</title>
<%= javascript_include_tag "app_no_turbolinks" %>
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>
1 change: 1 addition & 0 deletions test/dummy_sprockets/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Application < Rails::Application
}

if SprocketsHelpers.available?
config.assets.precompile += %w( app_no_turbolinks.js )
config.assets.enabled = true
end
end
Expand Down
1 change: 1 addition & 0 deletions test/dummy_sprockets/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Dummy::Application.routes.draw do
get 'no-turbolinks', to: 'pages#no_turbolinks'
resources :pages, only: [:show]
resources :server, only: [:show] do
collection do
Expand Down
5 changes: 5 additions & 0 deletions test/react/rails/react_rails_ujs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def refute_greeting(page, greeting)
assert_greeting(page, 'Hello Bob')
end

test 'react_ujs works without Turbolinks' do # Fixes #743
visit '/no-turbolinks'
assert_nil page.execute_script('ReactRailsUJS.detectEvents()')
end

test 'react_ujs can unmount/mount using a selector reference for a component parent' do
visit '/pages/1'
assert_greeting(page, 'Hello Bob')
Expand Down