Skip to content

Commit 81f6480

Browse files
authored
Merge pull request #802 from BookOfGreg/fix-743
Fix Turbolinks Detection
2 parents 09a77c4 + 4238043 commit 81f6480

File tree

12 files changed

+53
-20
lines changed

12 files changed

+53
-20
lines changed

lib/assets/javascripts/react_ujs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ var turbolinksClassicEvents = __webpack_require__(10)
119119
module.exports = function(ujs) {
120120
if (ujs.handleEvent) {
121121
// We're calling this a second time -- remove previous handlers
122-
if (typeof Turbolinks.EVENTS !== "undefined") {
122+
if (typeof Turbolinks !== "undefined" && typeof Turbolinks.EVENTS !== "undefined") {
123123
turbolinksClassicEvents.teardown(ujs);
124124
}
125125
turbolinksEvents.teardown(ujs);

react_ujs/dist/react_ujs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ var turbolinksClassicEvents = __webpack_require__(10)
119119
module.exports = function(ujs) {
120120
if (ujs.handleEvent) {
121121
// We're calling this a second time -- remove previous handlers
122-
if (typeof Turbolinks.EVENTS !== "undefined") {
122+
if (typeof Turbolinks !== "undefined" && typeof Turbolinks.EVENTS !== "undefined") {
123123
turbolinksClassicEvents.teardown(ujs);
124124
}
125125
turbolinksEvents.teardown(ujs);

react_ujs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react_ujs",
3-
"version": "2.2.1",
3+
"version": "2.3.1",
44
"description": "Rails UJS for the react-rails gem",
55
"main": "index.js",
66
"repository": "reactjs/react-rails",

react_ujs/src/events/detect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var turbolinksClassicEvents = require("./turbolinksClassic")
99
module.exports = function(ujs) {
1010
if (ujs.handleEvent) {
1111
// We're calling this a second time -- remove previous handlers
12-
if (typeof Turbolinks.EVENTS !== "undefined") {
12+
if (typeof Turbolinks !== "undefined" && typeof Turbolinks.EVENTS !== "undefined") {
1313
turbolinksClassicEvents.teardown(ujs);
1414
}
1515
turbolinksEvents.teardown(ujs);

react_ujs/yarn.lock

+20-16
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,14 @@ emojis-list@^2.0.0:
468468
version "2.1.0"
469469
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"
470470

471-
enhanced-resolve@^3.0.0:
472-
version "3.1.0"
473-
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.1.0.tgz#9f4b626f577245edcf4b2ad83d86e17f4f421dec"
471+
enhanced-resolve@^3.3.0:
472+
version "3.4.1"
473+
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.4.1.tgz#0421e339fd71419b3da13d129b3979040230476e"
474474
dependencies:
475475
graceful-fs "^4.1.2"
476476
memory-fs "^0.4.0"
477477
object-assign "^4.0.1"
478-
tapable "^0.2.5"
478+
tapable "^0.2.7"
479479

480480
errno@^0.1.3:
481481
version "0.1.4"
@@ -1428,9 +1428,9 @@ [email protected]:
14281428
dependencies:
14291429
hoek "2.x.x"
14301430

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

14351435
source-map@^0.5.3, source-map@~0.5.1, source-map@~0.5.3:
14361436
version "0.5.6"
@@ -1525,7 +1525,11 @@ supports-color@^3.1.0:
15251525
dependencies:
15261526
has-flag "^1.0.0"
15271527

1528-
tapable@^0.2.5, tapable@~0.2.5:
1528+
tapable@^0.2.7:
1529+
version "0.2.8"
1530+
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.8.tgz#99372a5c999bf2df160afc0d74bed4f47948cd22"
1531+
1532+
tapable@~0.2.5:
15291533
version "0.2.6"
15301534
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.6.tgz#206be8e188860b514425375e6f1ae89bfb01fd8d"
15311535

@@ -1645,23 +1649,23 @@ watchpack@^1.3.1:
16451649
chokidar "^1.4.3"
16461650
graceful-fs "^4.1.2"
16471651

1648-
webpack-sources@^0.2.3:
1649-
version "0.2.3"
1650-
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-0.2.3.tgz#17c62bfaf13c707f9d02c479e0dcdde8380697fb"
1652+
webpack-sources@^1.0.1:
1653+
version "1.0.1"
1654+
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.1.tgz#c7356436a4d13123be2e2426a05d1dad9cbe65cf"
16511655
dependencies:
1652-
source-list-map "^1.1.1"
1656+
source-list-map "^2.0.0"
16531657
source-map "~0.5.3"
16541658

16551659
webpack@^2.3.3:
1656-
version "2.6.1"
1657-
resolved "https://registry.yarnpkg.com/webpack/-/webpack-2.6.1.tgz#2e0457f0abb1ac5df3ab106c69c672f236785f07"
1660+
version "2.7.0"
1661+
resolved "https://registry.yarnpkg.com/webpack/-/webpack-2.7.0.tgz#b2a1226804373ffd3d03ea9c6bd525067034f6b1"
16581662
dependencies:
16591663
acorn "^5.0.0"
16601664
acorn-dynamic-import "^2.0.0"
16611665
ajv "^4.7.0"
16621666
ajv-keywords "^1.1.1"
16631667
async "^2.1.2"
1664-
enhanced-resolve "^3.0.0"
1668+
enhanced-resolve "^3.3.0"
16651669
interpret "^1.0.0"
16661670
json-loader "^0.5.4"
16671671
json5 "^0.5.1"
@@ -1675,7 +1679,7 @@ webpack@^2.3.3:
16751679
tapable "~0.2.5"
16761680
uglify-js "^2.8.27"
16771681
watchpack "^1.3.1"
1678-
webpack-sources "^0.2.3"
1682+
webpack-sources "^1.0.1"
16791683
yargs "^6.0.0"
16801684

16811685
which-module@^1.0.0:

test/dummy_sprockets/app/assets/config/manifest.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
//= link application.js
44
//= link turbolinks_only.js
55
//= link application.css
6+
//= link app_no_turbolinks.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//= require react
2+
//= require react_ujs
3+
//= require_tree ./components

test/dummy_sprockets/app/controllers/pages_controller.rb

+5
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ def show
1818
js_context.exec("global.ctx = undefined;")
1919
end
2020
end
21+
22+
def no_turbolinks
23+
@prerender = false
24+
render :show, layout: 'app_no_turbolinks'
25+
end
2126
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Dummy</title>
5+
<%= javascript_include_tag "app_no_turbolinks" %>
6+
<%= csrf_meta_tags %>
7+
</head>
8+
<body>
9+
10+
<%= yield %>
11+
12+
</body>
13+
</html>

test/dummy_sprockets/config/application.rb

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Application < Rails::Application
3636
}
3737

3838
if SprocketsHelpers.available?
39+
config.assets.precompile += %w( app_no_turbolinks.js )
3940
config.assets.enabled = true
4041
end
4142
end

test/dummy_sprockets/config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Dummy::Application.routes.draw do
2+
get 'no-turbolinks', to: 'pages#no_turbolinks'
23
resources :pages, only: [:show]
34
resources :server, only: [:show] do
45
collection do

test/react/rails/react_rails_ujs_test.rb

+5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ def refute_greeting(page, greeting)
101101
assert_greeting(page, 'Hello Bob')
102102
end
103103

104+
test 'react_ujs works without Turbolinks' do # Fixes #743
105+
visit '/no-turbolinks'
106+
assert_nil page.execute_script('ReactRailsUJS.detectEvents()')
107+
end
108+
104109
test 'react_ujs can unmount/mount using a selector reference for a component parent' do
105110
visit '/pages/1'
106111
assert_greeting(page, 'Hello Bob')

0 commit comments

Comments
 (0)