react_on_rails 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.md +21 -5
- data/README.md +11 -12
- data/docs/additional-reading/server-rendering-tips.md +39 -1
- data/lib/generators/react_on_rails/base_generator.rb +43 -9
- data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx.tt +1 -1
- data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +43 -35
- data/lib/generators/react_on_rails/templates/base/base/{package.json → package.json.tt} +14 -2
- data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +4 -0
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +20 -26
- data/lib/react_on_rails/server_rendering_pool.rb +40 -9
- data/lib/react_on_rails/version.rb +1 -1
- data/package.json +24 -26
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00b4b6cdd792eae2f8a892620e99371ae33eb716
|
4
|
+
data.tar.gz: 2c8831e6abb2b480cfa3802d2f6abf5d9357c706
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 939994ec889500aeff448c4a8b6d6c22464879e751fabf17c7b2d710922eaf4c440197c1c03938f6e5e70e80d5ead3e8c4e5f0dbc21313d8e432f8c8eefce594
|
7
|
+
data.tar.gz: 488947af98af5ec1c274fa332fbd2a301562a1db35ee79f2e9d4a1073c6129d3314c3f2076c320325e7aa4d43e827a8aef6ef364bf0d918ba793db9e73439e81
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -22,7 +22,7 @@ before_install:
|
|
22
22
|
- sudo apt-get install -y xvfb
|
23
23
|
|
24
24
|
install:
|
25
|
-
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install 5.
|
25
|
+
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install 5.10.0
|
26
26
|
- npm install -g npm
|
27
27
|
- npm install -g poltergeist
|
28
28
|
- gem install bundler
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,22 @@ All notable changes to this project will be documented in this file. Items under
|
|
4
4
|
Contributors: please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version.
|
5
5
|
## [Unreleased]
|
6
6
|
|
7
|
-
## [5.
|
7
|
+
## [5.1.0] - 2016-04-03
|
8
|
+
##### Added
|
9
|
+
All 5.1.0 changes can be found in [#362](https://github.com/shakacode/react_on_rails/pull/362) by [justin808](https://github.com/justin808).
|
10
|
+
- Generator enhancements
|
11
|
+
- Generator adds line to spec/rails_helper.rb so that running specs will ensure assets are compiled.
|
12
|
+
- Other small changes to the generator including adding necessary npm scripts to allow React on Rails to build assets.
|
13
|
+
- Npm modules updated for generator.
|
14
|
+
- Added babel-runtime in to the client/package.json created.
|
15
|
+
- Server rendering
|
16
|
+
- Added more diagnostics for server rendering.
|
17
|
+
- Calls to setTimeout and setInterval are not logged for server rendering unless env TRACE_REACT_ON_RAILS is set to YES.
|
18
|
+
- Updated all project npm dependencies to latest.
|
19
|
+
- Update to node 5.10.0 for CI.
|
20
|
+
- Added babel-runtime as a peer dependency for the npm module.
|
21
|
+
|
22
|
+
## [5.0.0] - 2016-04-01
|
8
23
|
|
9
24
|
##### Added
|
10
25
|
- Added `railsContext`, an object which gets passed always as the second parameter to both react component and redux store generator functions, both for server and client rendering. This provides data like the current locale, the pathname, etc. The data values are customizable by a new configuration called `rendering_extension` where you can create a module with a method called `rendering_extension`. This allows you to add additional values to the Rails Context. Implement one static method called `custom_context(view_context)` and return a Hash. See [#345](https://github.com/shakacode/react_on_rails/pull/345) by [justin808](https://github.com/justin808)
|
@@ -96,12 +111,12 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
|
|
96
111
|
- Support for Turbolinks 5! [#270](https://github.com/shakacode/react_on_rails/pull/270).
|
97
112
|
- Added better error messages for `ReactOnRails.register()`. [#273](https://github.com/shakacode/react_on_rails/pull/273).
|
98
113
|
|
99
|
-
##### Breaking Change
|
114
|
+
##### Breaking Change
|
100
115
|
- Calls to `react_component` should use a named argument of props. For example, change this:
|
101
116
|
```ruby
|
102
117
|
<%= react_component("ReduxSharedStoreApp", {}, prerender: false, trace: true) %>
|
103
118
|
```
|
104
|
-
|
119
|
+
|
105
120
|
to
|
106
121
|
```ruby
|
107
122
|
<%= react_component("ReduxSharedStoreApp", props: {}, prerender: false, trace: true) %>
|
@@ -109,7 +124,7 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
|
|
109
124
|
You'll get a deprecation message to change this.
|
110
125
|
- Renamed `ReactOnRails.configure_rspec_to_compile_assets` to `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`. The code has also been optimized to check for whether or not the compiled webpack bundles are up to date or not and will not run if not necessary. If you are using non-standard directories for your generated webpack assets (`app/assets/javascripts/generated` and `app/assets/stylesheets/generated`) or have additional directories you wish the helper to check, you need to update your ReactOnRails configuration accordingly. See [documentation](https://github.com/shakacode/react_on_rails/blob/master/docs/additional-reading/rspec_configuration.md) for how to do this. [#253](https://github.com/shakacode/react_on_rails/pull/253).
|
111
126
|
- You have to call `ReactOnRails.register` to register react components. This was deprecated in v2. [#273](https://github.com/shakacode/react_on_rails/pull/273).
|
112
|
-
|
127
|
+
|
113
128
|
##### Migration Steps v2 to v3
|
114
129
|
- [spec/dummy/spec/rails_helper.rb](https://github.com/shakacode/react_on_rails/blob/master/spec%2Fdummy%2Fspec%2Frails_helper.rb#L36..38) for an example. Add this line to your `rails_helper.rb`:
|
115
130
|
```ruby
|
@@ -247,7 +262,8 @@ Best done with Object destructing:
|
|
247
262
|
|
248
263
|
##### Fixed
|
249
264
|
- Fix several generator related issues.
|
250
|
-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/5.
|
265
|
+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/5.1.0...master
|
266
|
+
[5.1.0]: https://github.com/shakacode/react_on_rails/compare/5.0.0...5.1.0
|
251
267
|
[5.0.0]: https://github.com/shakacode/react_on_rails/compare/4.0.3...5.0.0
|
252
268
|
[4.0.3]: https://github.com/shakacode/react_on_rails/compare/4.0.2...4.0.3
|
253
269
|
[4.0.2]: https://github.com/shakacode/react_on_rails/compare/4.0.1...4.0.2
|
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/shakacode/react_on_rails.svg?branch=master)](https://travis-ci.org/shakacode/react_on_rails) [![Dependency Status](https://gemnasium.com/shakacode/react_on_rails.svg)](https://gemnasium.com/shakacode/react_on_rails) [![Gem Version](https://badge.fury.io/rb/react_on_rails.svg)](https://badge.fury.io/rb/react_on_rails) [![npm version](https://badge.fury.io/js/react-on-rails.svg)](https://badge.fury.io/js/react-on-rails) [![Code Climate](https://codeclimate.com/github/shakacode/react_on_rails/badges/gpa.svg)](https://codeclimate.com/github/shakacode/react_on_rails) [![Coverage Status](https://coveralls.io/repos/shakacode/react_on_rails/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react_on_rails?branch=master)
|
2
2
|
|
3
3
|
# NEWS
|
4
|
-
* 5.
|
5
|
-
* Please see the [CHANGELOG.md](./CHANGELOG.md) for details on the latest release and any breaking changes.
|
4
|
+
* 5.1.0 has shipped!Please see the [CHANGELOG.md](./CHANGELOG.md) for details on the latest release and any breaking changes.
|
6
5
|
* [New slides on React on Rails](http://www.slideshare.net/justingordon/react-on-rails-v4032).
|
7
|
-
* 2016-02-28: We added a [Projects page](PROJECTS.md). Please edit the page your project or [email us](mailto:contact@shakacode.com) and we'll add you. We also love stars as it helps us attract new users and contributors.
|
6
|
+
* 2016-02-28: We added a [Projects page](./PROJECTS.md) and a [Kudos page](./KUDOS.md). Please edit the page your project or [email us](mailto:contact@shakacode.com) and we'll add you. We also love stars as it helps us attract new users and contributors.
|
8
7
|
* *See [NEWS.md](NEWS.md) for the full news history.*
|
9
8
|
|
10
9
|
# NOTES
|
@@ -67,7 +66,7 @@ Please see [Getting Started](#getting-started) for how to set up your Rails proj
|
|
67
66
|
+ [Why Webpack?](#why-webpack)
|
68
67
|
+ [Getting Started](#getting-started)
|
69
68
|
- [Installation Summary](#installation-summary)
|
70
|
-
- [Initializer Configuration: config/initializers/react_on_rails.rb](#initializer-configuration)
|
69
|
+
- [Initializer Configuration: config/initializers/react_on_rails.rb](#initializer-configuration)
|
71
70
|
+ [How it Works](#how-it-works)
|
72
71
|
- [Client-Side Rendering vs. Server-Side Rendering](#client-side-rendering-vs-server-side-rendering)
|
73
72
|
- [Building the Bundles](#building-the-bundles)
|
@@ -261,7 +260,7 @@ Set the config value for the `rendering_extension`:
|
|
261
260
|
config.rendering_extension = RenderingExtension
|
262
261
|
```
|
263
262
|
|
264
|
-
Implement it like this above in the same file. Create a class method on the module called `custom_context` that takes the `view_context` for a param.
|
263
|
+
Implement it like this above in the same file. Create a class method on the module called `custom_context` that takes the `view_context` for a param.
|
265
264
|
|
266
265
|
See [spec/dummy/config/initializers/react_on_rails.rb](spec/dummy/config/initializers/react_on_rails.rb) for a detailed example.
|
267
266
|
|
@@ -387,11 +386,11 @@ The best source of docs is the main [ReactOnRails.js](node_package/src/ReactOnRa
|
|
387
386
|
registerStore(stores)
|
388
387
|
|
389
388
|
/**
|
390
|
-
* Allows retrieval of the store by name. This store will be hydrated by any Rails form props.
|
389
|
+
* Allows retrieval of the store by name. This store will be hydrated by any Rails form props.
|
391
390
|
* Pass optional param throwIfMissing = false if you want to use this call to get back null if the
|
392
391
|
* store with name is not registered.
|
393
392
|
* @param name
|
394
|
-
* @param throwIfMissing Defaults to true. Set to false to have this call return undefined if
|
393
|
+
* @param throwIfMissing Defaults to true. Set to false to have this call return undefined if
|
395
394
|
* there is no store with the given name.
|
396
395
|
* @returns Redux Store, possibly hydrated
|
397
396
|
*/
|
@@ -428,7 +427,7 @@ static vs. hot is picked based on whether `ENV["REACT_ON_RAILS_ENV"] == "HOT"`
|
|
428
427
|
hot: 'application_non_webpack',
|
429
428
|
'data-turbolinks-track' => true) %>
|
430
429
|
```
|
431
|
-
|
430
|
+
|
432
431
|
See application.html.erb for usage example and [application.html.erb](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/app%2Fviews%2Flayouts%2Fapplication.html.erb)
|
433
432
|
|
434
433
|
**env_javascript_include_tag(args = {})**
|
@@ -564,7 +563,7 @@ You will need to make a function that can create the store you will be using for
|
|
564
563
|
|
565
564
|
```
|
566
565
|
function appStore(props, railsContext) {
|
567
|
-
// Create a hydrated redux store, using props and the railsContext (object with
|
566
|
+
// Create a hydrated redux store, using props and the railsContext (object with
|
568
567
|
// Rails contextual information).
|
569
568
|
return myAppStore;
|
570
569
|
}
|
@@ -613,9 +612,9 @@ Components are created as [stateless function(al) components](https://facebook.g
|
|
613
612
|
|
614
613
|
## React Router
|
615
614
|
[React Router](https://github.com/reactjs/react-router) is supported, including server side rendering! See:
|
616
|
-
|
615
|
+
|
617
616
|
1. [React on Rails docs for react-router](docs/additional-reading/react-router.md)
|
618
|
-
1. Examples in [spec/dummy/app/views/react_router](spec/dummy/app/views/react_router) and follow to the JavaScript code in the [spec/dummy/client/app/startup/ServerRouterApp.jsx](spec/dummy/client/app/startup/ServerRouterApp.jsx).
|
617
|
+
1. Examples in [spec/dummy/app/views/react_router](spec/dummy/app/views/react_router) and follow to the JavaScript code in the [spec/dummy/client/app/startup/ServerRouterApp.jsx](spec/dummy/client/app/startup/ServerRouterApp.jsx).
|
619
618
|
|
620
619
|
## Developing with the Webpack Dev Server
|
621
620
|
One of the benefits of using webpack is access to [webpack's dev server](https://webpack.github.io/docs/webpack-dev-server.html) and its [hot module replacement](https://webpack.github.io/docs/hot-module-replacement-with-webpack.html) functionality.
|
@@ -653,7 +652,7 @@ Note: If you have components from react-rails you want to use, then you will nee
|
|
653
652
|
## Additional Reading
|
654
653
|
+ [React on Rails, Slides](http://www.slideshare.net/justingordon/react-on-rails-v4032)
|
655
654
|
+ [The React on Rails Doctrine](https://medium.com/@railsonmaui/the-react-on-rails-doctrine-3c59a778c724)
|
656
|
-
+ [Installation Overview](docs/additional-reading/installation-overview.md)
|
655
|
+
+ [Installation Overview](docs/additional-reading/installation-overview.md)
|
657
656
|
+ [Babel](docs/additional-reading/babel.md)
|
658
657
|
+ [Heroku Deployment](docs/additional-reading/heroku-deployment.md)
|
659
658
|
+ [Manual Installation](docs/additional-reading/manual-installation.md)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# Server Rendering Tips
|
2
2
|
|
3
|
+
## General Tips
|
3
4
|
- Your code can't reference `document`. Server side JS execution does not have access to `document`, so jQuery and some
|
4
5
|
other libs won't work in this environment. You can debug this by putting in `console.log`
|
5
6
|
statements in your code.
|
@@ -8,4 +9,41 @@
|
|
8
9
|
do this is to use a generator function.
|
9
10
|
- If you're serious about server rendering, it's worth the effort to have different entry points for client and server rendering. It's worth the extra complexity.
|
10
11
|
|
11
|
-
The point is that you have separate files for top level client or server side, and you pass some extra option indicating that rendering is happening server
|
12
|
+
The point is that you have separate files for top level client or server side, and you pass some extra option indicating that rendering is happening server side.
|
13
|
+
|
14
|
+
## Troubleshooting Server Rendering
|
15
|
+
|
16
|
+
1. First be sure your code works with server rendering disabled (`prerender: false`)
|
17
|
+
2. `export TRACE_REACT_ON_RAILS=YES` Turn this on to get both the invocation code for you component, as well as the whole file used to setup the JavaScript context.
|
18
|
+
|
19
|
+
## setTimeout and setInterval
|
20
|
+
|
21
|
+
These methods are polyfilled for server rendering to be no-ops. We don't log calls to these by default as some libraries, namely babel-polyfill, will call setTimout. If you wish to log calls to setTimeout and setInterval, set the ENV value: `export TRACE_REACT_ON_RAILS=YES`.
|
22
|
+
|
23
|
+
Here's an example of this which shows the line numbers that end up calling setTimeout:
|
24
|
+
```
|
25
|
+
➜ ~/shakacode/react_on_rails/gen-examples/examples/basic-server-rendering (add-rails-helper-to-generator u=) ✗ export TRACE_REACT_ON_RAILS=YES
|
26
|
+
➜ ~/shakacode/react_on_rails/gen-examples/examples/basic-server-rendering (add-rails-helper-to-generator u=) ✗ rspec
|
27
|
+
Hello World
|
28
|
+
Building Webpack client-rendering assets...
|
29
|
+
Completed building Webpack client-rendering assets.
|
30
|
+
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
|
31
|
+
react_renderer.rb: 92
|
32
|
+
wrote file tmp/server-generated.js
|
33
|
+
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
|
34
|
+
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
|
35
|
+
react_renderer.rb: 92
|
36
|
+
wrote file tmp/base_js_code.js
|
37
|
+
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
|
38
|
+
[SERVER] setTimeout is not defined for execJS. See https://github.com/sstephenson/execjs#faq. Note babel-polyfill will call this.
|
39
|
+
[SERVER] at setTimeout (<eval>:31:17)
|
40
|
+
at defer (<eval>:4422:8)
|
41
|
+
at setImmediate (<eval>:4387:6)
|
42
|
+
at notify (<eval>:4481:16)
|
43
|
+
at module.exports (<eval>:4490:6)
|
44
|
+
at notify (<eval>:4081:4)
|
45
|
+
at Promise.$resolve (<eval>:4189:8)
|
46
|
+
at <eval>:793:18
|
47
|
+
at Function.resolve (<eval>:4265:6)
|
48
|
+
the hello world example works
|
49
|
+
```
|
@@ -110,15 +110,15 @@ module ReactOnRails
|
|
110
110
|
|
111
111
|
def copy_base_files
|
112
112
|
base_path = "base/base/"
|
113
|
-
%w(app/controllers/hello_world_controller.rb
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
113
|
+
base_files = %w(app/controllers/hello_world_controller.rb
|
114
|
+
client/.babelrc
|
115
|
+
client/index.jade
|
116
|
+
client/server.js
|
117
|
+
client/webpack.client.base.config.js
|
118
|
+
client/webpack.client.rails.config.js
|
119
|
+
REACT_ON_RAILS.md
|
120
|
+
client/REACT_ON_RAILS_CLIENT_README.md)
|
121
|
+
base_files.each { |file| copy_file(base_path + file, file) }
|
122
122
|
end
|
123
123
|
|
124
124
|
def template_base_files
|
@@ -127,6 +127,7 @@ module ReactOnRails
|
|
127
127
|
Procfile.dev
|
128
128
|
Procfile.dev-hot
|
129
129
|
app/views/hello_world/index.html.erb
|
130
|
+
package.json
|
130
131
|
client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx
|
131
132
|
client/webpack.client.hot.config.js
|
132
133
|
client/package.json).each { |file| template(base_path + file + ".tt", file) }
|
@@ -184,6 +185,32 @@ Rails.application.config.assets.paths << Rails.root.join("app", "assets", "webpa
|
|
184
185
|
end
|
185
186
|
end
|
186
187
|
|
188
|
+
def append_to_spec_rails_helper
|
189
|
+
rails_helper = File.join(destination_root, "spec/rails_helper.rb")
|
190
|
+
if File.exist?(rails_helper)
|
191
|
+
add_configure_rspec_to_compile_assets(rails_helper)
|
192
|
+
else
|
193
|
+
spec_helper = File.join(destination_root, "spec/spec_helper.rb")
|
194
|
+
if File.exist?(spec_helper)
|
195
|
+
add_configure_rspec_to_compile_assets(spec_helper)
|
196
|
+
else
|
197
|
+
GeneratorMessages.add_info(
|
198
|
+
<<-MSG.strip_heredoc
|
199
|
+
Did not find spec/rails_helper.rb or spec/spec_helper.rb to add line
|
200
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
201
|
+
MSG
|
202
|
+
)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
CONFIGURE_RSPEC_TO_COMPILE_ASSETS = <<-STR.strip_heredoc
|
208
|
+
RSpec.configure do |config|
|
209
|
+
# Ensure that if we are running js tests, we are using latest webpack assets
|
210
|
+
# This will use the defaults of :js and :server_rendering meta tags
|
211
|
+
ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
212
|
+
STR
|
213
|
+
|
187
214
|
# rename to application.scss from application.css or application.css.scss
|
188
215
|
def force_application_scss_naming_if_necessary
|
189
216
|
base_path = "app/assets/stylesheets/"
|
@@ -220,6 +247,13 @@ Rails.application.config.assets.paths << Rails.root.join("app", "assets", "webpa
|
|
220
247
|
MSG
|
221
248
|
GeneratorMessages.add_info(message)
|
222
249
|
end
|
250
|
+
|
251
|
+
private
|
252
|
+
|
253
|
+
def add_configure_rspec_to_compile_assets(helper_file)
|
254
|
+
search_str = "RSpec.configure do |config|"
|
255
|
+
gsub_file(helper_file, search_str, CONFIGURE_RSPEC_TO_COMPILE_ASSETS)
|
256
|
+
end
|
223
257
|
end
|
224
258
|
end
|
225
259
|
end
|
@@ -25,82 +25,90 @@
|
|
25
25
|
},
|
26
26
|
"homepage": "https://github.com/shakacode/react-webpack-rails-tutorial",
|
27
27
|
"scripts": {
|
28
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
29
28
|
"start": "node server.js",
|
30
29
|
"build:client": "NODE_ENV=production webpack --config webpack.client.rails.config.js",
|
30
|
+
<%- if options.server_rendering? -%>
|
31
31
|
"build:server": "NODE_ENV=production webpack --config webpack.server.rails.config.js",
|
32
|
+
<%- end -%>
|
32
33
|
"build:dev:client": "webpack -w --config webpack.client.rails.config.js",
|
33
|
-
|
34
|
+
<%- if options.server_rendering? -%>
|
35
|
+
"build:dev:server": "webpack -w --config webpack.server.rails.config.js",
|
36
|
+
<%- end -%>
|
37
|
+
"build:production:client": "NODE_ENV=production webpack --config webpack.client.rails.build.config.js",
|
38
|
+
<%- if options.server_rendering? -%>
|
39
|
+
"build:production:server": "NODE_ENV=production webpack --config webpack.server.rails.build.config.js",
|
40
|
+
<%- end -%>
|
41
|
+
<%- unless options.skip_js_linters? -%>
|
34
42
|
"lint": "npm run eslint && npm run jscs",
|
35
43
|
"eslint": "eslint --ext .js,.jsx .",
|
36
|
-
"jscs": "jscs --verbose ."
|
44
|
+
"jscs": "jscs --verbose .",
|
37
45
|
<%- end -%>
|
46
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
38
47
|
},
|
39
48
|
"dependencies": {
|
40
|
-
"autoprefixer": "^6.3.
|
49
|
+
"autoprefixer": "^6.3.5",
|
41
50
|
"axios": "^0.9.1",
|
42
|
-
"babel": "^6.5.
|
43
|
-
"babel-cli": "^6.5
|
44
|
-
"babel-core": "^6.
|
45
|
-
"babel-loader": "^6.2.
|
46
|
-
"babel-
|
47
|
-
"babel-
|
51
|
+
"babel": "^6.5.2",
|
52
|
+
"babel-cli": "^6.6.5",
|
53
|
+
"babel-core": "^6.7.4",
|
54
|
+
"babel-loader": "^6.2.4",
|
55
|
+
"babel-runtime": "^6.6.1",
|
56
|
+
"babel-polyfill": "^6.7.4",
|
57
|
+
"babel-preset-es2015": "^6.6.0",
|
48
58
|
"babel-preset-react": "^6.5.0",
|
49
59
|
"babel-preset-stage-0": "^6.5.0",
|
50
60
|
"css-loader": "^0.23.1",
|
51
|
-
"es5-shim": "^4.5.
|
61
|
+
"es5-shim": "^4.5.7",
|
52
62
|
"expose-loader": "^0.7.1",
|
53
63
|
<%- if options.redux? -%>
|
54
64
|
"immutable": "^3.7.6",
|
55
65
|
<%- end -%>
|
56
66
|
"imports-loader": "^0.6.5",
|
57
|
-
"jquery": "^2.2.
|
58
|
-
"jquery-ujs": "^1.2.
|
59
|
-
"loader-utils": "^0.2.
|
60
|
-
"lodash": "^4.
|
67
|
+
"jquery": "^2.2.2",
|
68
|
+
"jquery-ujs": "^1.2.1",
|
69
|
+
"loader-utils": "^0.2.13",
|
70
|
+
"lodash": "^4.7.0",
|
61
71
|
<%- if options.redux? -%>
|
62
|
-
"mirror-creator": "1.
|
72
|
+
"mirror-creator": "1.1.0",
|
63
73
|
<%- end -%>
|
64
|
-
"react": "^0.14.
|
74
|
+
"react": "^0.14.8",
|
65
75
|
<%- unless options.skip_bootstrap? -%>
|
66
|
-
"react-bootstrap": "^0.28.
|
76
|
+
"react-bootstrap": "^0.28.5",
|
67
77
|
<%- end -%>
|
68
|
-
"react-dom": "^0.14.
|
78
|
+
"react-dom": "^0.14.8",
|
69
79
|
"react-on-rails": "<%= VersionSyntaxConverter.new.rubygem_to_npm %>",
|
70
80
|
<%- if options.redux? -%>
|
71
|
-
"react-redux": "^4.4.
|
81
|
+
"react-redux": "^4.4.1",
|
72
82
|
"redux": "^3.3.1",
|
73
|
-
"redux-promise": "^0.5.
|
74
|
-
"redux-thunk": "^
|
83
|
+
"redux-promise": "^0.5.3",
|
84
|
+
"redux-thunk": "^2.0.1",
|
75
85
|
<%- end -%>
|
76
|
-
"webpack": "^1.12.
|
86
|
+
"webpack": "^1.12.14"
|
77
87
|
},
|
78
88
|
"devDependencies": {
|
79
|
-
|
80
|
-
"babel-eslint": "^5.0.0-beta8",
|
81
|
-
<%- end -%>
|
82
|
-
"babel-plugin-react-transform": "^2.0.0",
|
89
|
+
"babel-plugin-react-transform": "^2.0.2",
|
83
90
|
<%- unless options.skip_bootstrap? -%>
|
84
91
|
"bootstrap-sass": "^3.3.6",
|
85
92
|
"bootstrap-sass-loader": "^1.0.10",
|
86
93
|
<%- end -%>
|
87
94
|
"css-loader": "^0.23.1",
|
88
95
|
<%- unless options.skip_js_linters? -%>
|
89
|
-
"eslint": "^
|
90
|
-
|
91
|
-
"eslint-config-shakacode": "^
|
92
|
-
|
96
|
+
"eslint": "^2.6.0",
|
97
|
+
<%- unless options.skip_js_linters? -%>
|
98
|
+
"eslint-config-shakacode": "^4.0.0",
|
99
|
+
<%- end -%>
|
100
|
+
"eslint-plugin-react": "^4.2.3",
|
93
101
|
<%- end -%>
|
94
102
|
"express": "^4.13.4",
|
95
103
|
"file-loader": "^0.8.5",
|
96
104
|
"jade": "^1.11.0",
|
97
105
|
<%- unless options.skip_js_linters? -%>
|
98
|
-
"jscs": "^2.
|
106
|
+
"jscs": "^2.11.0",
|
99
107
|
<%- end -%>
|
100
108
|
"node-sass": "^3.4.2",
|
101
|
-
"react-transform-hmr": "^1.0.
|
102
|
-
"sass-loader": "^3.
|
103
|
-
"style-loader": "^0.13.
|
109
|
+
"react-transform-hmr": "^1.0.4",
|
110
|
+
"sass-loader": "^3.2.0",
|
111
|
+
"style-loader": "^0.13.1",
|
104
112
|
"url-loader": "^0.5.7",
|
105
113
|
"webpack-dev-server": "^1.14.1"
|
106
114
|
}
|
@@ -9,9 +9,21 @@
|
|
9
9
|
},
|
10
10
|
"scripts": {
|
11
11
|
"postinstall": "cd client && npm install",
|
12
|
-
"test": "rspec && (cd client && npm run lint)",
|
13
12
|
"express-server": "echo 'visit http://localhost:4000' && cd client && npm start",
|
14
|
-
"rails-server": "echo 'visit http://localhost:3000/hello_world' && foreman start -f Procfile.dev"
|
13
|
+
"rails-server": "echo 'visit http://localhost:3000/hello_world' && foreman start -f Procfile.dev",
|
14
|
+
"build:production:client": "(cd client && npm run build:production:client --silent)",
|
15
|
+
<%- if options.server_rendering? -%>
|
16
|
+
"build:production:server": "(cd client && npm run build:production:server --silent)",
|
17
|
+
<%- end -%>
|
18
|
+
"build:client": "(cd client && npm run build:client --silent",
|
19
|
+
<%- if options.server_rendering? -%>
|
20
|
+
"build:server": "(cd client && npm run build:server --silent)",
|
21
|
+
<%- end -%>
|
22
|
+
"build:dev:client": "(cd client && npm run build:dev:client --silent)",
|
23
|
+
<%- if options.server_rendering? -%>
|
24
|
+
"build:dev:server": "(cd client && npm run build:dev:server --silent)",
|
25
|
+
<%- end -%>
|
26
|
+
"test": "rspec && (cd client && npm run lint)"
|
15
27
|
},
|
16
28
|
"repository": {
|
17
29
|
"type": "git",
|
@@ -34,6 +34,10 @@ Capybara.javascript_driver = :poltergeist
|
|
34
34
|
# ActiveRecord::Migration.maintain_test_schema!
|
35
35
|
|
36
36
|
RSpec.configure do |config|
|
37
|
+
# Ensure that if we are running js tests, we are using latest webpack assets
|
38
|
+
# This will use the defaults of :js and :server_rendering meta tags
|
39
|
+
ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
|
40
|
+
|
37
41
|
# Remove this line if you"re not using ActiveRecord or ActiveRecord fixtures
|
38
42
|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
39
43
|
|
@@ -12,35 +12,29 @@ function select(state) {
|
|
12
12
|
}
|
13
13
|
|
14
14
|
// Simple example of a React "smart" component
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
const HelloWorld = (props) => {
|
16
|
+
const { dispatch, $$helloWorldStore } = props;
|
17
|
+
const actions = bindActionCreators(helloWorldActionCreators, dispatch);
|
18
|
+
const { updateName } = actions;
|
19
|
+
const name = $$helloWorldStore.get('name');
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
// This uses the ES2015 spread operator to pass properties as it is more DRY
|
22
|
+
// This is equivalent to:
|
23
|
+
// <HelloWorldWidget $$helloWorldStore={$$helloWorldStore} actions={actions} />
|
24
|
+
return (
|
25
|
+
<HelloWorldWidget {...{ updateName, name }} />
|
26
|
+
);
|
27
|
+
};
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
}
|
29
|
+
HelloWorld.propTypes = {
|
30
|
+
dispatch: PropTypes.func.isRequired,
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
// This uses the ES2015 spread operator to pass properties as it is more DRY
|
37
|
-
// This is equivalent to:
|
38
|
-
// <HelloWorldWidget $$helloWorldStore={$$helloWorldStore} actions={actions} />
|
39
|
-
return (
|
40
|
-
<HelloWorldWidget {...{ updateName, name }} />
|
41
|
-
);
|
42
|
-
}
|
43
|
-
}
|
32
|
+
// This corresponds to the value used in function select above.
|
33
|
+
// We prefix all property and variable names pointing to Immutable.js objects with '$$'.
|
34
|
+
// This allows us to immediately know we don't call $$helloWorldStore['someProperty'], but
|
35
|
+
// instead use the Immutable.js `get` API for Immutable.Map
|
36
|
+
$$helloWorldStore: PropTypes.instanceOf(Immutable.Map).isRequired,
|
37
|
+
};
|
44
38
|
|
45
39
|
// Don't forget to actually use connect!
|
46
40
|
// Note that we don't export HelloWorld, but the redux "connected" version of it.
|
@@ -29,7 +29,11 @@ module ReactOnRails
|
|
29
29
|
# js_code MUST RETURN json stringify Object
|
30
30
|
# Calling code will probably call 'html_safe' on return value before rendering to the view.
|
31
31
|
def self.server_render_js_with_console_logging(js_code)
|
32
|
-
|
32
|
+
if trace_react_on_rails?
|
33
|
+
@file_index ||= 1
|
34
|
+
trace_messsage(js_code, "tmp/server-generated-#{@file_index % 10}.js")
|
35
|
+
@file_index += 1
|
36
|
+
end
|
33
37
|
json_string = eval_js(js_code)
|
34
38
|
result = JSON.parse(json_string)
|
35
39
|
|
@@ -51,8 +55,8 @@ module ReactOnRails
|
|
51
55
|
class << self
|
52
56
|
private
|
53
57
|
|
54
|
-
def trace_messsage(js_code, file_name = "tmp/server-generated.js")
|
55
|
-
return unless
|
58
|
+
def trace_messsage(js_code, file_name = "tmp/server-generated.js", force = false)
|
59
|
+
return unless trace_react_on_rails? || force
|
56
60
|
# Set to anything to print generated code.
|
57
61
|
puts "Z" * 80
|
58
62
|
puts "react_renderer.rb: 92"
|
@@ -61,6 +65,10 @@ module ReactOnRails
|
|
61
65
|
puts "Z" * 80
|
62
66
|
end
|
63
67
|
|
68
|
+
def trace_react_on_rails?
|
69
|
+
ENV["TRACE_REACT_ON_RAILS"].present?
|
70
|
+
end
|
71
|
+
|
64
72
|
def eval_js(js_code)
|
65
73
|
@js_context_pool.with do |js_context|
|
66
74
|
result = js_context.eval(js_code)
|
@@ -78,17 +86,18 @@ module ReactOnRails
|
|
78
86
|
#{execjs_timer_polyfills}
|
79
87
|
#{bundle_js_code};
|
80
88
|
JS
|
89
|
+
file_name = "tmp/base_js_code.js"
|
81
90
|
begin
|
91
|
+
trace_messsage(base_js_code, file_name)
|
82
92
|
ExecJS.compile(base_js_code)
|
83
93
|
rescue => e
|
84
|
-
|
85
|
-
|
86
|
-
"ERROR when compiling base_js_code! See #{file_name} to "\
|
94
|
+
msg = "ERROR when compiling base_js_code! "\
|
95
|
+
"See file #{file_name} to "\
|
87
96
|
"correlate line numbers of error. Error is\n\n#{e.message}"\
|
88
97
|
"\n\n#{e.backtrace.join("\n")}"
|
89
98
|
puts msg
|
90
99
|
Rails.logger.error(msg)
|
91
|
-
trace_messsage(base_js_code, file_name)
|
100
|
+
trace_messsage(base_js_code, file_name, true)
|
92
101
|
raise e
|
93
102
|
end
|
94
103
|
else
|
@@ -105,16 +114,38 @@ module ReactOnRails
|
|
105
114
|
|
106
115
|
def execjs_timer_polyfills
|
107
116
|
<<-JS
|
117
|
+
function getStackTrace () {
|
118
|
+
var stack;
|
119
|
+
try {
|
120
|
+
throw new Error('');
|
121
|
+
}
|
122
|
+
catch (error) {
|
123
|
+
stack = error.stack || '';
|
124
|
+
}
|
125
|
+
stack = stack.split('\\n').map(function (line) { return line.trim(); });
|
126
|
+
return stack.splice(stack[0] == 'Error' ? 2 : 1);
|
127
|
+
}
|
128
|
+
|
108
129
|
function setInterval() {
|
109
|
-
|
130
|
+
#{undefined_for_exec_js_logging('setInterval')}
|
110
131
|
}
|
111
132
|
|
112
133
|
function setTimeout() {
|
113
|
-
|
134
|
+
#{undefined_for_exec_js_logging('setTimeout')}
|
114
135
|
}
|
115
136
|
JS
|
116
137
|
end
|
117
138
|
|
139
|
+
def undefined_for_exec_js_logging(function_name)
|
140
|
+
if trace_react_on_rails?
|
141
|
+
"console.error('#{function_name} is not defined for execJS. See "\
|
142
|
+
"https://github.com/sstephenson/execjs#faq. Note babel-polyfill may call this.');\n"\
|
143
|
+
" console.error(getStackTrace().join('\\n'));"
|
144
|
+
else
|
145
|
+
""
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
118
149
|
# Reimplement console methods for replaying on the client
|
119
150
|
def console_polyfill
|
120
151
|
<<-JS
|
data/package.json
CHANGED
@@ -1,44 +1,42 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-on-rails",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.1.0",
|
4
4
|
"description": "react-on-rails JavaScript for react_on_rails Ruby gem",
|
5
5
|
"main": "node_package/lib/ReactOnRails.js",
|
6
6
|
"directories": {
|
7
7
|
"doc": "docs"
|
8
8
|
},
|
9
9
|
"devDependencies": {
|
10
|
-
"babel-cli": "^6.
|
11
|
-
"babel-core": "^6.4
|
12
|
-
"babel-
|
13
|
-
"babel-
|
14
|
-
"babel-plugin-transform-runtime": "^6.
|
15
|
-
"babel-preset-es2015": "^6.
|
16
|
-
"babel-preset-react": "^6.
|
17
|
-
"babel-preset-stage-0": "^6.
|
18
|
-
"babel-
|
19
|
-
"babel-
|
20
|
-
"babel-types": "^6.4.5",
|
10
|
+
"babel-cli": "^6.6.5",
|
11
|
+
"babel-core": "^6.7.4",
|
12
|
+
"babel-loader": "^6.2.4",
|
13
|
+
"babel-plugin-react-transform": "^2.0.2",
|
14
|
+
"babel-plugin-transform-runtime": "^6.6.0",
|
15
|
+
"babel-preset-es2015": "^6.6.0",
|
16
|
+
"babel-preset-react": "^6.5.0",
|
17
|
+
"babel-preset-stage-0": "^6.5.0",
|
18
|
+
"babel-tape-runner": "^2.0.1",
|
19
|
+
"babel-types": "^6.7.2",
|
21
20
|
"babelify": "^7.2.0",
|
22
|
-
"blue-tape": "^0.
|
23
|
-
"eslint": "^
|
24
|
-
"eslint-config-
|
25
|
-
"eslint-
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"
|
29
|
-
"
|
30
|
-
"react": "^0.
|
31
|
-
"react-dom": "^0.14.7",
|
32
|
-
"react-transform-hmr": "^1.0.1",
|
21
|
+
"blue-tape": "^0.2.0",
|
22
|
+
"eslint": "^2.6.0",
|
23
|
+
"eslint-config-shakacode": "4.0.0",
|
24
|
+
"eslint-plugin-react": "^4.2.3",
|
25
|
+
"jscs": "^2.11.0",
|
26
|
+
"jsdom": "^8.2.0",
|
27
|
+
"react": "^0.14.8",
|
28
|
+
"react-dom": "^0.14.8",
|
29
|
+
"react-transform-hmr": "^1.0.4",
|
33
30
|
"redux": "^3.3.1",
|
34
31
|
"release-it": "^2.3.1",
|
35
32
|
"tap-spec": "^4.1.1",
|
36
|
-
"tape": "^4.
|
37
|
-
"webpack": "^1.12.
|
33
|
+
"tape": "^4.5.1",
|
34
|
+
"webpack": "^1.12.14"
|
38
35
|
},
|
39
36
|
"peerDependencies": {
|
40
37
|
"react": ">= 0.14",
|
41
|
-
"react-dom": ">= 0.14"
|
38
|
+
"react-dom": ">= 0.14",
|
39
|
+
"babel-runtime": ">= 6"
|
42
40
|
},
|
43
41
|
"files": [
|
44
42
|
"node_package/lib"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: react_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|
@@ -373,7 +373,7 @@ files:
|
|
373
373
|
- lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt
|
374
374
|
- lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt
|
375
375
|
- lib/generators/react_on_rails/templates/base/base/lib/tasks/linters.rake.tt
|
376
|
-
- lib/generators/react_on_rails/templates/base/base/package.json
|
376
|
+
- lib/generators/react_on_rails/templates/base/base/package.json.tt
|
377
377
|
- lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverRegistration.jsx
|
378
378
|
- lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js
|
379
379
|
- lib/generators/react_on_rails/templates/bootstrap/app/assets/stylesheets/_bootstrap-custom.scss
|