react-rails 2.6.1 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ca305d1d6e644b9a6626812de984d9f7df96d230c6d7544906228e5d266a008
4
- data.tar.gz: 0adaef4fa3452878dcb2d113f7e383333c297dd4fb245ce669fd0616c2bf4060
3
+ metadata.gz: 96a680594edd90c4c4b7956ca981b98c39c0be650c2570bcac0640fe4641ba0f
4
+ data.tar.gz: 0c8153bde6bfaaddb6c86c8450729d9ac2aa336ea976dbc959fe94c0a66907a1
5
5
  SHA512:
6
- metadata.gz: 9d0584ef2799b453aa22f965594dde71dc3f4895ca0747108bd96b99494df68c2603b27f7146a93aed9c8ef02f632142d408c457beb4eaf7932a714f2ee6ab75
7
- data.tar.gz: 400040ce79b9f881197e5bc9f60378427972d3e75804e8683f226eefe8e0af76e71737c236796daf27d977ebfa81d528047b7e5949744f5371e74b118c3c2977
6
+ metadata.gz: aac97afcf29aa71177ddbac2e11f117cb64fb524cd435701c3c6f70fb81775f870becfd1ba04f5167830b72808b8e8afbcf18c802477335c28d78ee5b0ec6d2e
7
+ data.tar.gz: 8988ff16c6619dc0ee8df11b060b49107e63524641b90ba497199d1cbbff96b696be61b3b8eb2237ab6b121e636352c07f5a7066426ff5c8c80608d85a7c32fb
data/CHANGELOG.md CHANGED
@@ -8,6 +8,19 @@
8
8
 
9
9
  #### Bug Fixes
10
10
 
11
+ ## 2.6.2
12
+
13
+ #### New Features
14
+
15
+ - React 16.14
16
+ - Support for ShakaPacker
17
+ - Preparation for React 18 #1151
18
+
19
+ #### Bug Fixes
20
+
21
+ - URI.open instead of open #1099
22
+ - No longer unmount components on Turbolinks navigation #1135
23
+
11
24
  ## 2.6.1
12
25
 
13
26
  #### Breaking Changes
@@ -112,6 +125,7 @@
112
125
  - Call ReactDOM.render() when react_component :prerender option is falsy, instead of ReactDOM.hydrate() #844, #842
113
126
 
114
127
  ## 2.4.2
128
+
115
129
  #### Bug Fixes
116
130
 
117
131
  - ReactDOM.hydrate() may not be defined for everyone, it will now use hydrate if it is defined or fallback to render #832
@@ -224,7 +238,6 @@
224
238
  // = require components
225
239
  ```
226
240
 
227
-
228
241
  #### New Features
229
242
 
230
243
  - Webpacker support:
@@ -471,14 +484,14 @@
471
484
 
472
485
  - Changed server rendering configuration names #253
473
486
 
474
- | Old | New |
475
- | ---- | ---- |
476
- | `config.react.timeout` | `config.react.server_renderer_timeout` |
477
- | `config.react.max_renderers` | `config.react.server_renderer_pool_size` |
478
- | `config.react.react_js` | `config.react.server_renderer_options[:files]` |
479
- | `config.react.component_filenames` | `config.react.server_renderer_options[:files]` |
480
- | `config.react.replay_console` | `config.react.server_renderer_options[:replay_console]` |
481
- | (none) | `config.react.server_renderer` |
487
+ | Old | New |
488
+ | ---------------------------------- | ------------------------------------------------------- |
489
+ | `config.react.timeout` | `config.react.server_renderer_timeout` |
490
+ | `config.react.max_renderers` | `config.react.server_renderer_pool_size` |
491
+ | `config.react.react_js` | `config.react.server_renderer_options[:files]` |
492
+ | `config.react.component_filenames` | `config.react.server_renderer_options[:files]` |
493
+ | `config.react.replay_console` | `config.react.server_renderer_options[:replay_console]` |
494
+ | (none) | `config.react.server_renderer` |
482
495
 
483
496
  - JSX is transformed by Babel, not JSTransform #295
484
497
 
@@ -504,7 +517,6 @@
504
517
  - Add `tilt` dependency #248
505
518
  - Default prerender pool size to 1 #302
506
519
 
507
-
508
520
  ## 1.0.0 (April 7, 2015)
509
521
 
510
522
  #### New Features
data/README.md CHANGED
@@ -67,62 +67,60 @@ $ rails new my-app
67
67
  $ cd my-app
68
68
  ```
69
69
 
70
- ##### 2) Add `webpacker` and `react-rails` to your gemfile:
70
+ ##### 2) Add `react-rails` to your Gemfile:
71
71
  ```ruby
72
- gem 'webpacker'
73
72
  gem 'react-rails'
74
73
  ```
74
+ Note: On rails versions < 6.0, You need to add `gem 'webpacker'` to your Gemfile in step 2 above.
75
75
 
76
76
  ##### 3) Now run the installers:
77
77
 
78
- ###### Rails 6.x:
78
+ ###### Rails 6.x and 5.x:
79
79
  ```
80
80
  $ bundle install
81
- $ rails webpacker:install
82
- $ rails webpacker:install:react
81
+ $ rails webpacker:install # OR (on rails version < 5.0) rake webpacker:install
82
+ $ rails webpacker:install:react # OR (on rails version < 5.0) rake webpacker:install:react
83
83
  $ rails generate react:install
84
84
  ```
85
- Note: For Rails 6, You don't need to add `javascript_pack_tag` as in Step 4. Since its already added by default.
86
85
 
87
- ###### Rails 5.x:
88
- ```
89
- $ bundle install
90
- $ rails webpacker:install # OR (on rails version < 5.0) rake webpacker:install
91
- $ rails webpacker:install:react # OR (on rails version < 5.0) rake webpacker:install:react
92
- $ rails generate react:install
93
- ```
94
86
  This gives you:
95
87
 
96
88
  - `app/javascript/components/` directory for your React components
97
89
  - [`ReactRailsUJS`](#ujs) setup in `app/javascript/packs/application.js`
98
90
  - `app/javascript/packs/server_rendering.js` for [server-side rendering](#server-side-rendering)
99
91
 
100
- ##### 4) Link the JavaScript pack in Rails view using `javascript_pack_tag` [helper](https://github.com/rails/webpacker#usage):
92
+ Note: On rails versions < 6.0, link the JavaScript pack in Rails view using `javascript_pack_tag` [helper](https://github.com/rails/webpacker#usage):
101
93
  ```erb
102
94
  <!-- application.html.erb in Head tag below turbolinks -->
103
95
  <%= javascript_pack_tag 'application' %>
104
96
  ```
105
97
 
106
- ##### 5) Generate your first component:
98
+ ##### 4) Generate your first component:
107
99
  ```
108
100
  $ rails g react:component HelloWorld greeting:string
109
101
  ```
110
102
 
111
- ##### 6) You can also generate your component in a subdirectory:
103
+ ##### 5) You can also generate your component in a subdirectory:
112
104
  ```
113
105
  $ rails g react:component my_subdirectory/HelloWorld greeting:string
114
106
  ```
115
107
  Note: Your component is added to `app/javascript/components/` by default.
116
108
 
109
+ Note: If your component is in a subdirectory you will append the directory path to your erb component call.
117
110
 
118
- ##### 7) [Render it in a Rails view](#view-helper):
111
+ Example:
112
+ ```
113
+ <%= react_component("my_subdirectory/HelloWorld", { greeting: "Hello from react-rails." }) %>
114
+ ```
115
+
116
+ ##### 6) [Render it in a Rails view](#view-helper):
119
117
 
120
118
  ```erb
121
119
  <!-- erb: paste this in view -->
122
120
  <%= react_component("HelloWorld", { greeting: "Hello from react-rails." }) %>
123
121
  ```
124
122
 
125
- ##### 8) Lets Start the app:
123
+ ##### 7) Lets Start the app:
126
124
  ```
127
125
  $ rails s
128
126
  ```
@@ -172,7 +170,10 @@ $ bundle exec rails webpacker:install:typescript
172
170
  $ yarn add @types/react @types/react-dom
173
171
  ```
174
172
 
175
- Doing this will allow React-Rails to support the .tsx extension.
173
+ Doing this will allow React-Rails to support the .tsx extension. Additionally, it is recommended to add `ts` and `tsx` to the `server_renderer_extensions` in your application configuration:
174
+ ```
175
+ config.react.server_renderer_extensions = ["jsx", "js", "tsx", "ts"]
176
+ ```
176
177
 
177
178
  ### Test component
178
179
 
@@ -690,11 +691,11 @@ One caveat is that currently you [cannot Server-Side Render along with HMR](http
690
691
  ## Related Projects
691
692
 
692
693
  - [webpacker-react](https://github.com/renchap/webpacker-react): Integration of React with Rails utilizing Webpack with Hot Module Replacement (HMR).
693
- - [The Free React on Rails Course](https://learnetto.com/users/hrishio/courses/the-free-react-on-rails-5-course) A free video course which teaches the basics of React and how to get started using it in Rails with `react-rails`.
694
+ - [The React on Rails Course](https://learnetto.com/users/hrishio/courses/the-free-react-on-rails-5-course) A video course which teaches the basics of React and how to get started using it in Rails with `react-rails`.
694
695
  - [react\_on\_rails](https://github.com/shakacode/react_on_rails): Integration of React with Rails utilizing Webpack, Redux, React-Router.
695
696
  - [react-rails-hot-loader](https://github.com/rmosolgo/react-rails-hot-loader) Simple live-reloader for `react-rails`.
696
697
  - [react-rails-benchmark_renderer](https://github.com/pboling/react-rails-benchmark_renderer) adds performance instrumentation to server rendering.
697
- - [Ruby Hyperloop](http://ruby-hyperloop.org/): Use Ruby to build reactive user interfaces with React.
698
+ - [Ruby Hyperstack](https://hyperstack.org/): Use Ruby to build reactive user interfaces with React.
698
699
 
699
700
  ## Contributing
700
701
 
@@ -1,13 +1,13 @@
1
1
  (function webpackUniversalModuleDefinition(root, factory) {
2
2
  if(typeof exports === 'object' && typeof module === 'object')
3
- module.exports = factory(require("react"), require("react-dom"), require("react-dom/server"));
3
+ module.exports = factory(require("react-dom"), require("react"), require("react-dom/server"));
4
4
  else if(typeof define === 'function' && define.amd)
5
- define(["react", "react-dom", "react-dom/server"], factory);
5
+ define(["react-dom", "react", "react-dom/server"], factory);
6
6
  else if(typeof exports === 'object')
7
- exports["ReactRailsUJS"] = factory(require("react"), require("react-dom"), require("react-dom/server"));
7
+ exports["ReactRailsUJS"] = factory(require("react-dom"), require("react"), require("react-dom/server"));
8
8
  else
9
- root["ReactRailsUJS"] = factory(root["React"], root["ReactDOM"], root["ReactDOMServer"]);
10
- })(this, function(__WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_4__, __WEBPACK_EXTERNAL_MODULE_5__) {
9
+ root["ReactRailsUJS"] = factory(root["ReactDOM"], root["React"], root["ReactDOMServer"]);
10
+ })(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_5__, __WEBPACK_EXTERNAL_MODULE_6__) {
11
11
  return /******/ (function(modules) { // webpackBootstrap
12
12
  /******/ // The module cache
13
13
  /******/ var installedModules = {};
@@ -73,7 +73,7 @@ return /******/ (function(modules) { // webpackBootstrap
73
73
  /******/ __webpack_require__.p = "";
74
74
  /******/
75
75
  /******/ // Load entry module and return exports
76
- /******/ return __webpack_require__(__webpack_require__.s = 6);
76
+ /******/ return __webpack_require__(__webpack_require__.s = 7);
77
77
  /******/ })
78
78
  /************************************************************************/
79
79
  /******/ ([
@@ -106,13 +106,19 @@ module.exports = function(className) {
106
106
 
107
107
  /***/ }),
108
108
  /* 1 */
109
+ /***/ (function(module, exports) {
110
+
111
+ module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
112
+
113
+ /***/ }),
114
+ /* 2 */
109
115
  /***/ (function(module, exports, __webpack_require__) {
110
116
 
111
- var nativeEvents = __webpack_require__(7)
112
- var pjaxEvents = __webpack_require__(8)
113
- var turbolinksEvents = __webpack_require__(9)
114
- var turbolinksClassicDeprecatedEvents = __webpack_require__(11)
115
- var turbolinksClassicEvents = __webpack_require__(10)
117
+ var nativeEvents = __webpack_require__(8)
118
+ var pjaxEvents = __webpack_require__(9)
119
+ var turbolinksEvents = __webpack_require__(10)
120
+ var turbolinksClassicDeprecatedEvents = __webpack_require__(12)
121
+ var turbolinksClassicEvents = __webpack_require__(11)
116
122
 
117
123
  // see what things are globally available
118
124
  // and setup event handlers to those things
@@ -164,14 +170,14 @@ module.exports = function(ujs) {
164
170
 
165
171
 
166
172
  /***/ }),
167
- /* 2 */
173
+ /* 3 */
168
174
  /***/ (function(module, exports, __webpack_require__) {
169
175
 
170
176
  // Make a function which:
171
177
  // - First tries to require the name
172
178
  // - Then falls back to global lookup
173
179
  var fromGlobal = __webpack_require__(0)
174
- var fromRequireContext = __webpack_require__(12)
180
+ var fromRequireContext = __webpack_require__(13)
175
181
 
176
182
  module.exports = function(reqctx) {
177
183
  var fromCtx = fromRequireContext(reqctx)
@@ -195,16 +201,41 @@ module.exports = function(reqctx) {
195
201
 
196
202
 
197
203
  /***/ }),
198
- /* 3 */
199
- /***/ (function(module, exports) {
204
+ /* 4 */
205
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
200
206
 
201
- module.exports = __WEBPACK_EXTERNAL_MODULE_3__;
207
+ "use strict";
208
+ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
209
+ /* harmony export (immutable) */ __webpack_exports__["supportsHydration"] = supportsHydration;
210
+ /* harmony export (immutable) */ __webpack_exports__["reactHydrate"] = reactHydrate;
211
+ /* harmony export (immutable) */ __webpack_exports__["createReactRootLike"] = createReactRootLike;
212
+ const ReactDOM = __webpack_require__(1)
202
213
 
203
- /***/ }),
204
- /* 4 */
205
- /***/ (function(module, exports) {
214
+ function supportsHydration() {
215
+ return typeof ReactDOM.hydrate === "function" || typeof ReactDOM.hydrateRoot === "function"
216
+ }
217
+
218
+ function reactHydrate(node, component) {
219
+ if (typeof ReactDOM.hydrateRoot === "function") {
220
+ return ReactDOM.hydrateRoot(node, component)
221
+ } else {
222
+ return ReactDOM.hydrate(component, node)
223
+ }
224
+ }
225
+
226
+ function createReactRootLike(node) {
227
+ return ReactDOM.createRoot ? ReactDOM.createRoot(node) : legacyReactRootLike(node)
228
+ }
229
+
230
+ function legacyReactRootLike(node) {
231
+ const root = {
232
+ render(component) {
233
+ return ReactDOM.render(component, node)
234
+ }
235
+ }
236
+ return root
237
+ }
206
238
 
207
- module.exports = __WEBPACK_EXTERNAL_MODULE_4__;
208
239
 
209
240
  /***/ }),
210
241
  /* 5 */
@@ -214,15 +245,22 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_5__;
214
245
 
215
246
  /***/ }),
216
247
  /* 6 */
248
+ /***/ (function(module, exports) {
249
+
250
+ module.exports = __WEBPACK_EXTERNAL_MODULE_6__;
251
+
252
+ /***/ }),
253
+ /* 7 */
217
254
  /***/ (function(module, exports, __webpack_require__) {
218
255
 
219
- var React = __webpack_require__(3)
220
- var ReactDOM = __webpack_require__(4)
221
- var ReactDOMServer = __webpack_require__(5)
256
+ var React = __webpack_require__(5)
257
+ var ReactDOM = __webpack_require__(1)
258
+ var ReactDOMServer = __webpack_require__(6)
222
259
 
223
- var detectEvents = __webpack_require__(1)
260
+ var detectEvents = __webpack_require__(2)
224
261
  var constructorFromGlobal = __webpack_require__(0)
225
- var constructorFromRequireContextWithGlobalFallback = __webpack_require__(2)
262
+ var constructorFromRequireContextWithGlobalFallback = __webpack_require__(3)
263
+ const { supportsHydration, reactHydrate, createReactRootLike } = __webpack_require__(4)
226
264
 
227
265
  var ReactRailsUJS = {
228
266
  // This attribute holds the name of component which should be mounted
@@ -329,13 +367,14 @@ var ReactRailsUJS = {
329
367
  }
330
368
  }
331
369
 
332
- if (hydrate && typeof ReactDOM.hydrate === "function") {
333
- component = ReactDOM.hydrate(component, node);
370
+ if (hydrate && supportsHydration()) {
371
+ component = reactHydrate(node, component);
334
372
  } else {
335
- component = ReactDOM.render(component, node);
373
+ const root = createReactRootLike(node)
374
+ component = root.render(component);
336
375
  }
337
376
  }
338
- }
377
+ }
339
378
  },
340
379
 
341
380
  // Within `searchSelector`, find nodes which have React components
@@ -390,7 +429,7 @@ module.exports = ReactRailsUJS
390
429
 
391
430
 
392
431
  /***/ }),
393
- /* 7 */
432
+ /* 8 */
394
433
  /***/ (function(module, exports) {
395
434
 
396
435
  module.exports = {
@@ -413,7 +452,7 @@ module.exports = {
413
452
 
414
453
 
415
454
  /***/ }),
416
- /* 8 */
455
+ /* 9 */
417
456
  /***/ (function(module, exports) {
418
457
 
419
458
  module.exports = {
@@ -433,25 +472,23 @@ module.exports = {
433
472
 
434
473
 
435
474
  /***/ }),
436
- /* 9 */
475
+ /* 10 */
437
476
  /***/ (function(module, exports) {
438
477
 
439
478
  module.exports = {
440
479
  // Turbolinks 5+ got rid of named events (?!)
441
480
  setup: function(ujs) {
442
481
  ujs.handleEvent('turbolinks:load', ujs.handleMount);
443
- ujs.handleEvent('turbolinks:before-render', ujs.handleUnmount);
444
482
  },
445
483
 
446
484
  teardown: function(ujs) {
447
485
  ujs.removeEvent('turbolinks:load', ujs.handleMount);
448
- ujs.removeEvent('turbolinks:before-render', ujs.handleUnmount);
449
486
  },
450
487
  }
451
488
 
452
489
 
453
490
  /***/ }),
454
- /* 10 */
491
+ /* 11 */
455
492
  /***/ (function(module, exports) {
456
493
 
457
494
  module.exports = {
@@ -469,7 +506,7 @@ module.exports = {
469
506
 
470
507
 
471
508
  /***/ }),
472
- /* 11 */
509
+ /* 12 */
473
510
  /***/ (function(module, exports) {
474
511
 
475
512
  module.exports = {
@@ -490,7 +527,7 @@ module.exports = {
490
527
 
491
528
 
492
529
  /***/ }),
493
- /* 12 */
530
+ /* 13 */
494
531
  /***/ (function(module, exports) {
495
532
 
496
533
  // Load React components by requiring them from "components/", for example: