react-rails 2.6.0 → 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: e9a12a6f724746ed2a189f4827268eb55fb538a80bb21edc2560809349a8f3aa
4
- data.tar.gz: aea725c7bb9606e7e98d47b51788860545b58efa50c70d24c1ba599de36c4751
3
+ metadata.gz: 96a680594edd90c4c4b7956ca981b98c39c0be650c2570bcac0640fe4641ba0f
4
+ data.tar.gz: 0c8153bde6bfaaddb6c86c8450729d9ac2aa336ea976dbc959fe94c0a66907a1
5
5
  SHA512:
6
- metadata.gz: df32314ab7e9e039861cd39907d1cf4de240b77188d251cc15cf9ae1eb57dd3180b3c9fdcbffebbe8c148e9f7a8a9aaffae38e6737e9a7635aa8d2511eb102c2
7
- data.tar.gz: 9089c5e64403d0040f2f183426f56fcf35542361e029838d3be1bfb01d098c4630515e24d083eefd4e72bbc6eb30752d9f9fcfb0e54cd765516d073e4799b7d8
6
+ metadata.gz: aac97afcf29aa71177ddbac2e11f117cb64fb524cd435701c3c6f70fb81775f870becfd1ba04f5167830b72808b8e8afbcf18c802477335c28d78ee5b0ec6d2e
7
+ data.tar.gz: 8988ff16c6619dc0ee8df11b060b49107e63524641b90ba497199d1cbbff96b696be61b3b8eb2237ab6b121e636352c07f5a7066426ff5c8c80608d85a7c32fb
data/CHANGELOG.md CHANGED
@@ -8,6 +8,39 @@
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
+
24
+ ## 2.6.1
25
+
26
+ #### Breaking Changes
27
+
28
+ #### New Features
29
+
30
+ - React 16.9.0
31
+ - Sprockets users get React_UJS 2.6.1
32
+
33
+ #### Deprecation
34
+
35
+ - Removed tests for Rails 3, 4, 5.0
36
+ - Removed tests for Sprockets 2
37
+ - Removed tests for Webpacker 1.1, 2
38
+
39
+ #### Bug Fixes
40
+
41
+ - React_UJS 2.6.1 still complies with ES5 #1027 #1026 #1016
42
+ - Support RubyGems pattern for Alpha releases when detecting sprockets version #1047
43
+
11
44
  ## 2.6.0
12
45
 
13
46
  #### Breaking Changes
@@ -15,6 +48,7 @@
15
48
  #### New Features
16
49
 
17
50
  - Typescript component generator #990
51
+ - Enhanced Turbolinks Support #978 #962
18
52
 
19
53
  #### Deprecation
20
54
 
@@ -91,6 +125,7 @@
91
125
  - Call ReactDOM.render() when react_component :prerender option is falsy, instead of ReactDOM.hydrate() #844, #842
92
126
 
93
127
  ## 2.4.2
128
+
94
129
  #### Bug Fixes
95
130
 
96
131
  - ReactDOM.hydrate() may not be defined for everyone, it will now use hydrate if it is defined or fallback to render #832
@@ -203,7 +238,6 @@
203
238
  // = require components
204
239
  ```
205
240
 
206
-
207
241
  #### New Features
208
242
 
209
243
  - Webpacker support:
@@ -450,14 +484,14 @@
450
484
 
451
485
  - Changed server rendering configuration names #253
452
486
 
453
- | Old | New |
454
- | ---- | ---- |
455
- | `config.react.timeout` | `config.react.server_renderer_timeout` |
456
- | `config.react.max_renderers` | `config.react.server_renderer_pool_size` |
457
- | `config.react.react_js` | `config.react.server_renderer_options[:files]` |
458
- | `config.react.component_filenames` | `config.react.server_renderer_options[:files]` |
459
- | `config.react.replay_console` | `config.react.server_renderer_options[:replay_console]` |
460
- | (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` |
461
495
 
462
496
  - JSX is transformed by Babel, not JSTransform #295
463
497
 
@@ -483,7 +517,6 @@
483
517
  - Add `tilt` dependency #248
484
518
  - Default prerender pool size to 1 #302
485
519
 
486
-
487
520
  ## 1.0.0 (April 7, 2015)
488
521
 
489
522
  #### New Features
data/README.md CHANGED
@@ -67,51 +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
+
78
+ ###### Rails 6.x and 5.x:
77
79
  ```
78
80
  $ bundle install
79
- $ rails webpacker:install # OR (on rails version < 5.0) rake webpacker:install
80
- $ rails webpacker:install:react # OR (on rails version < 5.0) rake 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
81
83
  $ rails generate react:install
82
84
  ```
85
+
83
86
  This gives you:
84
87
 
85
88
  - `app/javascript/components/` directory for your React components
86
89
  - [`ReactRailsUJS`](#ujs) setup in `app/javascript/packs/application.js`
87
90
  - `app/javascript/packs/server_rendering.js` for [server-side rendering](#server-side-rendering)
88
91
 
89
- ##### 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):
90
93
  ```erb
91
94
  <!-- application.html.erb in Head tag below turbolinks -->
92
95
  <%= javascript_pack_tag 'application' %>
93
96
  ```
94
97
 
95
- ##### 5) Generate your first component:
98
+ ##### 4) Generate your first component:
96
99
  ```
97
100
  $ rails g react:component HelloWorld greeting:string
98
101
  ```
99
102
 
100
- ##### 6) You can also generate your component in a subdirectory:
103
+ ##### 5) You can also generate your component in a subdirectory:
101
104
  ```
102
105
  $ rails g react:component my_subdirectory/HelloWorld greeting:string
103
106
  ```
104
107
  Note: Your component is added to `app/javascript/components/` by default.
105
108
 
109
+ Note: If your component is in a subdirectory you will append the directory path to your erb component call.
110
+
111
+ Example:
112
+ ```
113
+ <%= react_component("my_subdirectory/HelloWorld", { greeting: "Hello from react-rails." }) %>
114
+ ```
106
115
 
107
- ##### 7) [Render it in a Rails view](#view-helper):
116
+ ##### 6) [Render it in a Rails view](#view-helper):
108
117
 
109
118
  ```erb
110
119
  <!-- erb: paste this in view -->
111
120
  <%= react_component("HelloWorld", { greeting: "Hello from react-rails." }) %>
112
121
  ```
113
122
 
114
- ##### 8) Lets Start the app:
123
+ ##### 7) Lets Start the app:
115
124
  ```
116
125
  $ rails s
117
126
  ```
@@ -161,7 +170,10 @@ $ bundle exec rails webpacker:install:typescript
161
170
  $ yarn add @types/react @types/react-dom
162
171
  ```
163
172
 
164
- 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
+ ```
165
177
 
166
178
  ### Test component
167
179
 
@@ -658,7 +670,7 @@ yarn install
658
670
  ### Undefined Set
659
671
  ```
660
672
  ExecJS::ProgramError (identifier 'Set' undefined):
661
-
673
+
662
674
  (execjs):1
663
675
  ```
664
676
  If you see any variation of this issue, see [Using TheRubyRacer](#using-therubyracer)
@@ -670,18 +682,20 @@ TheRubyRacer [hasn't updated LibV8](https://github.com/cowboyd/therubyracer/blob
670
682
  LibV8 itself is already [beyond version 7](https://github.com/cowboyd/libv8/releases/tag/v7.3.492.27.1) therefore many serverside issues are caused by old JS engines and fixed by using an up to date one such as [MiniRacer](https://github.com/discourse/mini_racer) or [TheRubyRhino](https://github.com/cowboyd/therubyrhino) on JRuby.
671
683
 
672
684
  ### HMR
673
- HMR is possible with this gem as it does just pass through to Webpacker. Please open an issue to let us know tips and tricks for it to add to the wiki.
685
+ Hot Module Replacement is [possible with this gem](https://stackoverflow.com/a/54846330/193785) as it does just pass through to Webpacker. Please open an issue to let us know tips and tricks for it to add to the wiki.
686
+
687
+ Sample repo that shows HMR working with `react-rails`: [https://github.com/edelgado/react-rails-hmr](https://github.com/edelgado/react-rails-hmr)
674
688
 
675
- One example: [Stack Overflow answer with Babel and Webpacker config](https://stackoverflow.com/a/54846330/193785)
689
+ One caveat is that currently you [cannot Server-Side Render along with HMR](https://github.com/reactjs/react-rails/issues/925#issuecomment-415469572).
676
690
 
677
691
  ## Related Projects
678
692
 
679
693
  - [webpacker-react](https://github.com/renchap/webpacker-react): Integration of React with Rails utilizing Webpack with Hot Module Replacement (HMR).
680
- - [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`.
681
695
  - [react\_on\_rails](https://github.com/shakacode/react_on_rails): Integration of React with Rails utilizing Webpack, Redux, React-Router.
682
696
  - [react-rails-hot-loader](https://github.com/rmosolgo/react-rails-hot-loader) Simple live-reloader for `react-rails`.
683
697
  - [react-rails-benchmark_renderer](https://github.com/pboling/react-rails-benchmark_renderer) adds performance instrumentation to server rendering.
684
- - [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.
685
699
 
686
700
  ## Contributing
687
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
@@ -236,9 +274,16 @@ var ReactRailsUJS = {
236
274
  // This attribute holds which method to use between: ReactDOM.hydrate, ReactDOM.render
237
275
  RENDER_ATTR: 'data-hydrate',
238
276
 
277
+ // A unique identifier to identify a node
278
+ CACHE_ID_ATTR: "data-react-cache-id",
279
+
280
+ TURBOLINKS_PERMANENT_ATTR: "data-turbolinks-permanent",
281
+
239
282
  // If jQuery is detected, save a reference to it for event handlers
240
283
  jQuery: (typeof window !== 'undefined') && (typeof window.jQuery !== 'undefined') && window.jQuery,
241
284
 
285
+ components: {},
286
+
242
287
  // helper method for the mount and unmount methods to find the
243
288
  // `data-react-class` DOM elements
244
289
  findDOMNodes: function(searchSelector) {
@@ -304,6 +349,8 @@ var ReactRailsUJS = {
304
349
  var propsJson = node.getAttribute(ujs.PROPS_ATTR);
305
350
  var props = propsJson && JSON.parse(propsJson);
306
351
  var hydrate = node.getAttribute(ujs.RENDER_ATTR);
352
+ var cacheId = node.getAttribute(ujs.CACHE_ID_ATTR);
353
+ var turbolinksPermanent = node.hasAttribute(ujs.TURBOLINKS_PERMANENT_ATTR);
307
354
 
308
355
  if (!constructor) {
309
356
  var message = "Cannot find component: '" + className + "'"
@@ -312,10 +359,19 @@ var ReactRailsUJS = {
312
359
  }
313
360
  throw new Error(message + ". Make sure your component is available to render.")
314
361
  } else {
315
- if (hydrate && typeof ReactDOM.hydrate === "function") {
316
- ReactDOM.hydrate(React.createElement(constructor, props), node);
362
+ var component = this.components[cacheId];
363
+ if(component === undefined) {
364
+ component = React.createElement(constructor, props);
365
+ if(turbolinksPermanent) {
366
+ this.components[cacheId] = component;
367
+ }
368
+ }
369
+
370
+ if (hydrate && supportsHydration()) {
371
+ component = reactHydrate(node, component);
317
372
  } else {
318
- ReactDOM.render(React.createElement(constructor, props), node);
373
+ const root = createReactRootLike(node)
374
+ component = root.render(component);
319
375
  }
320
376
  }
321
377
  }
@@ -373,7 +429,7 @@ module.exports = ReactRailsUJS
373
429
 
374
430
 
375
431
  /***/ }),
376
- /* 7 */
432
+ /* 8 */
377
433
  /***/ (function(module, exports) {
378
434
 
379
435
  module.exports = {
@@ -396,7 +452,7 @@ module.exports = {
396
452
 
397
453
 
398
454
  /***/ }),
399
- /* 8 */
455
+ /* 9 */
400
456
  /***/ (function(module, exports) {
401
457
 
402
458
  module.exports = {
@@ -416,25 +472,23 @@ module.exports = {
416
472
 
417
473
 
418
474
  /***/ }),
419
- /* 9 */
475
+ /* 10 */
420
476
  /***/ (function(module, exports) {
421
477
 
422
478
  module.exports = {
423
479
  // Turbolinks 5+ got rid of named events (?!)
424
480
  setup: function(ujs) {
425
- ujs.handleEvent('turbolinks:load', ujs.handleMount)
426
- ujs.handleEvent('turbolinks:before-render', ujs.handleUnmount)
481
+ ujs.handleEvent('turbolinks:load', ujs.handleMount);
427
482
  },
428
483
 
429
484
  teardown: function(ujs) {
430
- ujs.removeEvent('turbolinks:load', ujs.handleMount)
431
- ujs.removeEvent('turbolinks:before-render', ujs.handleUnmount)
485
+ ujs.removeEvent('turbolinks:load', ujs.handleMount);
432
486
  },
433
487
  }
434
488
 
435
489
 
436
490
  /***/ }),
437
- /* 10 */
491
+ /* 11 */
438
492
  /***/ (function(module, exports) {
439
493
 
440
494
  module.exports = {
@@ -452,7 +506,7 @@ module.exports = {
452
506
 
453
507
 
454
508
  /***/ }),
455
- /* 11 */
509
+ /* 12 */
456
510
  /***/ (function(module, exports) {
457
511
 
458
512
  module.exports = {
@@ -473,7 +527,7 @@ module.exports = {
473
527
 
474
528
 
475
529
  /***/ }),
476
- /* 12 */
530
+ /* 13 */
477
531
  /***/ (function(module, exports) {
478
532
 
479
533
  // Load React components by requiring them from "components/", for example: