react-rails 2.4.0 โ 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -1
- data/README.md +100 -60
- data/lib/assets/javascripts/react_ujs.js +1 -1
- data/lib/generators/react/component_generator.rb +3 -4
- data/lib/react/rails/version.rb +1 -1
- data/lib/react/server_rendering/webpacker_manifest_container.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42eec1443d0268c4dfcc8e691b06d505dd1e7c3a
|
4
|
+
data.tar.gz: 8611400bfabb5185e1a6c508ee665549fbf71f98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43f5b84c1c7deb4a6fa20d29b206d9001232037b0c753577e46d8ccd7d82311bb11af44ae827740cb973130bd4187493a591da1c088733aed8043ab3ec6d10d6
|
7
|
+
data.tar.gz: bdd331ed7aa76e90267621d1fa89532ccd143ab351953953825941fab5857b8288d33db6af249289dd9ac837cbe24aa5c94b0fd790886226d80c609d219499a3
|
data/CHANGELOG.md
CHANGED
@@ -8,12 +8,26 @@
|
|
8
8
|
|
9
9
|
#### Bug Fixes
|
10
10
|
|
11
|
+
## 2.4.1
|
12
|
+
|
13
|
+
#### Breaking Changes
|
14
|
+
|
15
|
+
#### New Features
|
16
|
+
- Webpacker gets ES6 components by default #822
|
17
|
+
- ReactDOM.hydrate() #828
|
18
|
+
- Documentation updates #830
|
19
|
+
|
20
|
+
#### Deprecation
|
21
|
+
|
22
|
+
#### Bug Fixes
|
23
|
+
- Webpacker local manifest sometimes had double asset_hosts if the dev server was running #834 thanks @joeyparis
|
24
|
+
|
11
25
|
## 2.4.0
|
12
26
|
|
13
27
|
#### Breaking Changes
|
14
28
|
|
15
29
|
- (Sprockets) Prebundled React upgraded to 16 #792
|
16
|
-
- (Sprockets) Addons removed #
|
30
|
+
- (Sprockets) Addons removed #792
|
17
31
|
|
18
32
|
#### New Features
|
19
33
|
|
data/README.md
CHANGED
@@ -1,51 +1,66 @@
|
|
1
|
-
#
|
1
|
+
# React-Rails
|
2
2
|
|
3
3
|
[](http://rubygems.org/gems/react-rails)
|
4
|
+
[](https://www.npmjs.com/package/react_ujs)
|
4
5
|
[](https://travis-ci.org/reactjs/react-rails)
|
5
6
|
[](https://gemnasium.com/reactjs/react-rails)
|
6
7
|
[](https://codeclimate.com/github/reactjs/react-rails)
|
7
|
-
[](https://codeclimate.com/github/reactjs/react-rails/coverage)
|
8
8
|
|
9
|
-
Gem version 2.4.x onwards and master will no longer have React Addons.
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
- [
|
24
|
-
-
|
10
|
+
React-Rails is a flexible tool to use [React](http://facebook.github.io/react/) with Rails. It:
|
11
|
+
* Automatically renders React server-side and client-side
|
12
|
+
* Supports Webpacker 3.x, 2.x, 1.1+
|
13
|
+
* Supports Sprockets 4.x, 3.x, 2.x
|
14
|
+
* Lets you use [JSX](http://facebook.github.io/react/docs/jsx-in-depth.html), [ES6](http://es6-features.org/), [Coffeescript](http://coffeescript.org/)
|
15
|
+
|
16
|
+
Example app code available here: https://github.com/BookOfGreg/react-rails-example-app
|
17
|
+
|
18
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
19
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
20
|
+
## Contents
|
21
|
+
|
22
|
+
- [Get started with Webpacker](#get-started-with-webpacker)
|
23
|
+
- [File naming](#file-naming)
|
24
|
+
- [Use with Asset Pipeline](#use-with-asset-pipeline)
|
25
|
+
- [Custom JSX Transformer](#custom-jsx-transformer)
|
26
|
+
- [React.js versions](#reactjs-versions)
|
27
|
+
- [View Helper](#view-helper)
|
28
|
+
- [Custom View Helper](#custom-view-helper)
|
29
|
+
- [UJS](#ujs)
|
30
|
+
- [Mounting & Unmounting](#mounting--unmounting)
|
31
|
+
- [Event Handling](#event-handling)
|
32
|
+
- [`getConstructor`](#getconstructor)
|
33
|
+
- [Server-Side Rendering](#server-side-rendering)
|
34
|
+
- [Configuration](#configuration)
|
35
|
+
- [JavaScript State](#javascript-state)
|
36
|
+
- [Custom Server Renderer](#custom-server-renderer)
|
37
|
+
- [Controller Actions](#controller-actions)
|
38
|
+
- [Component Generator](#component-generator)
|
39
|
+
- [Use with JBuilder](#use-with-jbuilder)
|
40
|
+
- [Camelize Props](#camelize-props)
|
41
|
+
- [Upgrading](#upgrading)
|
42
|
+
- [2.3 to 2.4](#23-to-24)
|
25
43
|
- [Related Projects](#related-projects)
|
26
|
-
- [
|
44
|
+
- [Contributing](#contributing)
|
27
45
|
|
28
|
-
|
46
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
29
47
|
|
30
|
-
Install from Rubygems as `react-rails`.
|
31
48
|
|
32
|
-
|
33
|
-
gem "react-rails"
|
34
|
-
```
|
49
|
+
The React-Rails Wiki has lots of additional information about React-Rails including many "how-to" articles and answers to the most frequently asked questions. Please browse the Wiki after finishing this README:
|
35
50
|
|
36
|
-
|
51
|
+
https://github.com/reactjs/React-Rails/wiki
|
37
52
|
|
38
|
-
```
|
39
|
-
$ rails g react:install
|
40
|
-
```
|
41
53
|
|
42
|
-
##
|
54
|
+
## Get started with Webpacker
|
43
55
|
|
44
|
-
[
|
56
|
+
[or Get started with Sprockets](#use-with-asset-pipeline)
|
45
57
|
|
46
|
-
|
58
|
+
[Webpacker](https://github.com/rails/webpacker) integrates modern JS tooling with Rails.
|
59
|
+
|
60
|
+
Add `webpacker` and `react-rails` to your gemfile and run the installers:
|
47
61
|
|
48
62
|
```
|
63
|
+
$ bundle install
|
49
64
|
$ rails webpacker:install
|
50
65
|
$ rails webpacker:install:react
|
51
66
|
$ rails generate react:install
|
@@ -57,7 +72,15 @@ This gives you:
|
|
57
72
|
- [`ReactRailsUJS`](#ujs) setup in `app/javascript/packs/application.js`
|
58
73
|
- `app/javascript/packs/server_rendering.js` for [server-side rendering](#server-side-rendering)
|
59
74
|
|
60
|
-
|
75
|
+
Generate your first component:
|
76
|
+
|
77
|
+
```
|
78
|
+
$ rails g react:component HelloWorld greeting:string
|
79
|
+
```
|
80
|
+
|
81
|
+
Your component is added to `app/javascript/components/` by default.
|
82
|
+
|
83
|
+
[Render it in a Rails view](#view-helper):
|
61
84
|
|
62
85
|
```erb
|
63
86
|
<%= react_component("HelloWorld", { greeting: "Hello" }) %>
|
@@ -74,8 +97,6 @@ The component name tells `react-rails` where to load the component. For example:
|
|
74
97
|
|
75
98
|
This way, you can access top-level, default, or named exports.
|
76
99
|
|
77
|
-
If `require` fails, `react-rails` falls back to the global namespace approach described in [Use with Asset Pipeline](#use-with-asset-pipeline).
|
78
|
-
|
79
100
|
The `require.context` inserted into `packs/application.js` is used to load components. If you want to load components from a different directory, override it by calling `ReactRailsUJS.useContext`:
|
80
101
|
|
81
102
|
```js
|
@@ -85,7 +106,12 @@ var ReactRailsUJS = require("react_ujs")
|
|
85
106
|
ReactRailsUJS.useContext(myCustomContext)
|
86
107
|
```
|
87
108
|
|
88
|
-
|
109
|
+
If `require` fails to find your component, [`ReactRailsUJS`](#ujs) falls back to the global namespace, described in [Use with Asset Pipeline](#use-with-asset-pipeline).
|
110
|
+
|
111
|
+
### File naming
|
112
|
+
|
113
|
+
React-Rails supports plenty of file extensions such as: .js, .jsx.js, .js.jsx, .es6.js, .coffee, etcetera!
|
114
|
+
Sometimes this will cause a stumble when searching for filenames.
|
89
115
|
|
90
116
|
Component File Name | `react_component` call
|
91
117
|
-----|-----
|
@@ -97,7 +123,7 @@ Component File Name | `react_component` call
|
|
97
123
|
|
98
124
|
## Use with Asset Pipeline
|
99
125
|
|
100
|
-
`react-rails` provides React.js & a UJS driver to the Rails asset pipeline. Get started by installing:
|
126
|
+
`react-rails` provides a pre-bundled React.js & a UJS driver to the Rails asset pipeline. Get started by installing:
|
101
127
|
|
102
128
|
```
|
103
129
|
$ rails g react:install
|
@@ -113,7 +139,7 @@ This will:
|
|
113
139
|
|
114
140
|
Now, you can create React components in `.jsx` files:
|
115
141
|
|
116
|
-
```
|
142
|
+
```JSX
|
117
143
|
// app/assets/javascripts/components/post.jsx
|
118
144
|
|
119
145
|
window.Post = createReactClass({
|
@@ -171,7 +197,7 @@ MyApp::Application.configure do
|
|
171
197
|
end
|
172
198
|
```
|
173
199
|
|
174
|
-
Be sure to restart your Rails server after changing these files. See [VERSIONS.md](https://github.com/reactjs/react-rails/blob/master/VERSIONS.md) to learn which version of React.js is included with your `react-rails` version.
|
200
|
+
Be sure to restart your Rails server after changing these files. See [VERSIONS.md](https://github.com/reactjs/react-rails/blob/master/VERSIONS.md) to learn which version of React.js is included with your `react-rails` version. In some edge cases you may need to bust the sprockets cache with `rake tmp:clear`
|
175
201
|
|
176
202
|
|
177
203
|
## View Helper
|
@@ -402,7 +428,7 @@ rails g react:component Post title:string published:bool published_by:instanceOf
|
|
402
428
|
|
403
429
|
would generate:
|
404
430
|
|
405
|
-
```
|
431
|
+
```JSX
|
406
432
|
var Post = createReactClass({
|
407
433
|
propTypes: {
|
408
434
|
title: PropTypes.string,
|
@@ -480,29 +506,43 @@ You can also specify this option in `react_component`:
|
|
480
506
|
<%= react_component('HelloMessage', {name: 'John'}, {camelize_props: true}) %>
|
481
507
|
```
|
482
508
|
|
509
|
+
## Upgrading
|
510
|
+
|
511
|
+
### 2.3 to 2.4
|
512
|
+
|
513
|
+
Keep your `react_ujs` up to date, `yarn upgrade`
|
514
|
+
|
515
|
+
React-Rails 2.4.x uses React 16+ which no longer has React Addons. Therefore the pre-bundled version of react no longer has an addons version, if you need addons still, there is the 2.3.1+ version of the gem that still has addons.
|
516
|
+
|
517
|
+
If you need to make changes in your components for the prebundled react, see the migration docs here:
|
518
|
+
|
519
|
+
- https://reactjs.org/blog/2016/11/16/react-v15.4.0.html
|
520
|
+
- https://reactjs.org/blog/2017/04/07/react-v15.5.0.html
|
521
|
+
- https://reactjs.org/blog/2017/06/13/react-v15.6.0.html
|
522
|
+
|
523
|
+
|
524
|
+
For the vast majority of cases this will get you most of the migration:
|
525
|
+
- global find+replace `React.Prop` -> `Prop`
|
526
|
+
- add `import PropTypes from 'prop-types'` (Webpacker only)
|
527
|
+
- re-run `bundle exec rails webpacker:install:react` to update npm packages (Webpacker only)
|
528
|
+
|
483
529
|
## Related Projects
|
484
530
|
|
485
|
-
- [react
|
486
|
-
- [Ruby Hyperloop](http://ruby-hyperloop.org/): Use Ruby to build reactive user interfaces with React.
|
487
|
-
- [react-rails-hot-loader](https://github.com/rmosolgo/react-rails-hot-loader) is a simple live-reloader for `react-rails`.
|
488
|
-
- [react-rails-benchmark_renderer](https://github.com/pboling/react-rails-benchmark_renderer) adds performance instrumentation to server rendering.
|
531
|
+
- [webpacker-react](https://github.com/renchap/webpacker-react): Integration of React with Rails utilizing Webpack with Hot Module Replacement (HMR).
|
489
532
|
- [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`.
|
533
|
+
- [react\_on\_rails](https://github.com/shakacode/react_on_rails): Integration of React with Rails utilizing Webpack, Redux, React-Router.
|
534
|
+
- [react-rails-hot-loader](https://github.com/rmosolgo/react-rails-hot-loader) Simple live-reloader for `react-rails`.
|
535
|
+
- [react-rails-benchmark_renderer](https://github.com/pboling/react-rails-benchmark_renderer) adds performance instrumentation to server rendering.
|
536
|
+
- [Ruby Hyperloop](http://ruby-hyperloop.org/): Use Ruby to build reactive user interfaces with React.
|
537
|
+
|
538
|
+
## Contributing
|
539
|
+
|
540
|
+
๐ Thanks for taking the time to contribute! ๐
|
541
|
+
|
542
|
+
With 2 Million+ downloads of the react-rails Gem and another 100k+ downloads of react_ujs on NPM, you're helping the biggest React + Rails community!
|
543
|
+
|
544
|
+
By contributing to React-Rails, you agree to abide by the [code of conduct](https://github.com/reactjs/react-rails/blob/master/CODE_OF_CONDUCT.md).
|
545
|
+
|
546
|
+
You can always help by submitting patches or triaging issues, even offering reproduction steps to issues is incredibly helpful!
|
490
547
|
|
491
|
-
|
492
|
-
|
493
|
-
- Run tests with `rake test` or `appraisal rake test`
|
494
|
-
- Integration tests run in Headless Chrome which is included in Chrome (59+ linux,OSX | 60+ Windows)
|
495
|
-
- ChromeDriver is included with `chromedriver-helper` gem so no need to manually install that ๐
|
496
|
-
- Update React assets with `rake react:update`
|
497
|
-
- Update the UJS with `rake ujs:update`
|
498
|
-
- Releases:
|
499
|
-
- To release a new RubyGems version:
|
500
|
-
- Increment the version in `lib/react/rails/version.rb`
|
501
|
-
- Add an entry to `VERSIONS.md`
|
502
|
-
- Update the changelog (find recent changes on GitHub by listing commits or showing closed PRs)
|
503
|
-
- Commit changes & push to master
|
504
|
-
- `bundle exec rake release`: pushes a tag to GitHub, builds a `.gem`, and pushes to RubyGems
|
505
|
-
- To release a new NPM version:
|
506
|
-
- Update the version in `react_ujs/package.json`
|
507
|
-
- Commit & push to master
|
508
|
-
- `bundle exec rake ujs:publish` (runs `npm publish`)
|
548
|
+
Please see our [Contribution guide](https://github.com/reactjs/react-rails/blob/master/CONTRIBUTING.md) for more info.
|
@@ -315,7 +315,7 @@ var ReactRailsUJS = {
|
|
315
315
|
}
|
316
316
|
throw new Error(message + ". Make sure your component is available to render.")
|
317
317
|
} else {
|
318
|
-
ReactDOM.
|
318
|
+
ReactDOM.hydrate(React.createElement(constructor, props), node);
|
319
319
|
}
|
320
320
|
}
|
321
321
|
},
|
@@ -90,11 +90,10 @@ module React
|
|
90
90
|
}
|
91
91
|
|
92
92
|
def create_component_file
|
93
|
-
template_extension =
|
94
|
-
when options[:es6]
|
95
|
-
'es6.jsx'
|
96
|
-
when options[:coffee]
|
93
|
+
template_extension = if options[:coffee]
|
97
94
|
'js.jsx.coffee'
|
95
|
+
elsif options[:es6] || webpacker?
|
96
|
+
'es6.jsx'
|
98
97
|
else
|
99
98
|
'js.jsx'
|
100
99
|
end
|
data/lib/react/rails/version.rb
CHANGED
@@ -42,6 +42,8 @@ module React
|
|
42
42
|
asset_path = Webpacker.manifest.lookup(logical_path).to_s
|
43
43
|
if Webpacker.dev_server.running?
|
44
44
|
ds = Webpacker.dev_server
|
45
|
+
# Remove the protocol and host from the asset path. Sometimes webpacker includes this, sometimes it does not
|
46
|
+
asset_path.slice!("#{ds.protocol}://#{ds.host_with_port}")
|
45
47
|
dev_server_asset = open("#{ds.protocol}://#{ds.host_with_port}#{asset_path}").read
|
46
48
|
dev_server_asset.sub!(CLIENT_REQUIRE, '//\0')
|
47
49
|
dev_server_asset
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: react-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul OโShannessy
|
8
8
|
- Robert Mosolgo
|
9
|
+
- Gregory Myers
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2017-
|
13
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: appraisal
|
@@ -282,6 +283,7 @@ description: Render components in views or controller actions. Server-side rende
|
|
282
283
|
email:
|
283
284
|
- paul@oshannessy.com
|
284
285
|
- rmosolgo@gmail.com
|
286
|
+
- neonmd@hotmail.co.uk
|
285
287
|
executables: []
|
286
288
|
extensions: []
|
287
289
|
extra_rdoc_files: []
|