react_on_rails 6.4.0 → 6.4.1

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
  SHA1:
3
- metadata.gz: 6a4f8bdac2245e1f3a17da6fd63341e9ce892b36
4
- data.tar.gz: 18f926d01a9634607fa41e217c0981b751ed6dbd
3
+ metadata.gz: 94e59e11d5830cb4add6aa9d4c4dfff86075eda1
4
+ data.tar.gz: 0aed8a351e8ad6701c91e6b802a9b63d3aa04e3f
5
5
  SHA512:
6
- metadata.gz: 3c38887fd29781c9342661fc2f3a88cd50fa494610d1aed43342e0b0522d84762ebc1a0aa3b176a75fbec61a149ab6ee7f9c700ba4f109d2ee0d66091f8fa494
7
- data.tar.gz: d5cdcc84850799bea50d3d346a45dbbdb6627cb409138e6c0ec4ebbca2f8720018fa35cfac24fccbf5053b8822635d2d4e0a2580f266e68d61bf17b14f5df75e
6
+ metadata.gz: a50c9626b05fbbb4c10b10941dbff6e3168979fb4d9ef6843552557f041260e95d11ae9e3fd0d7a8983ad37bde8c779b408fc87e506a633d28ab24a7a25fd0e1
7
+ data.tar.gz: b8226192b451b6701d4f788fcfbf01a6eb9516302112d9156ef046f9a7563f7ae291c84140e921bb4b10fd8f9d0a0e5295caa836164b38b5e85aee17df6ffc3e
data/CHANGELOG.md CHANGED
@@ -8,6 +8,9 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
8
8
 
9
9
  ## [6.4.0] - 2017-1-12
10
10
 
11
+ ### Possible Breaking Change
12
+ - Since foreman is no longer a dependency of the React on Rails gem, please run `gem install foreman`. If you are using rvm, you may wish to run `rvm @global do gem install foreman` to install foreman for all your gemsets.
13
+
11
14
  ### Fixed
12
15
  - Removed foreman as a dependency. [#678](https://github.com/shakacode/react_on_rails/pull/678) by [x2es](https://github.com/x2es).
13
16
 
data/CONTRIBUTING.md CHANGED
@@ -176,6 +176,13 @@ npm test
176
176
 
177
177
  ```sh
178
178
  cd spec/dummy
179
+ rspec
180
+ ```
181
+
182
+ Eventually, we may have JS tests:
183
+
184
+ ```sh
185
+ cd spec/dummy/client
179
186
  npm run test
180
187
  ```
181
188
 
data/README.md CHANGED
@@ -119,9 +119,9 @@ We're definitely not doing that. With react_on_rails, webpack is mainly generati
119
119
  bundle && npm install
120
120
  ```
121
121
 
122
- 6. Start your Rails server:
122
+ 6. Ensure that you have `foreman` installed: `gem install foreman`.
123
123
 
124
- with foreman installed (`gem install foreman`)
124
+ 7. Start your Rails server:
125
125
 
126
126
  ```bash
127
127
  foreman start -f Procfile.dev
@@ -217,7 +217,7 @@ On production deployments that use asset precompilation, such as Heroku deployme
217
217
  If you have used the provided generator, these bundles will automatically be added to your `.gitignore` to prevent extraneous noise from re-generated code in your pull requests. You will want to do this manually if you do not use the provided generator.
218
218
 
219
219
  ### Rails Context
220
- When you use a "generator function" to create react components or you used shared redux stores, you get 2 params passed to your function:
220
+ When you use a "generator function" to create react components (or renderedHtml on the server) or you used shared redux stores, you get 2 params passed to your function:
221
221
 
222
222
  1. Props that you pass in the view helper of either `react_component` or `redux_store`
223
223
  2. Rails contextual information, such as the current pathname. You can customize this in your config file.
@@ -318,6 +318,8 @@ If you do want different code to run, you'd setup a separate webpack compilation
318
318
  #### Generator Functions
319
319
  Why would you create a function that returns a React component? For example, you may want the ability to use the passed-in props to initialize a redux store or setup react-router. Or you may want to return different components depending on what's in the props. ReactOnRails will automatically detect a registered generator function.
320
320
 
321
+ Another reason to user a generator function is that sometimes in server rendering, specifically with React Router, you need to return the result of calling ReactDOMServer.renderToString(element). You can do this by returning an object with the following shape: { renderedHtml, redirectLocation, error }.
322
+
321
323
  #### Renderer Functions
322
324
  A renderer function is a generator function that accepts three arguments: `(props, railsContext, domNodeId) => { ... }`. Instead of returning a React component, a renderer is responsible for calling `ReactDOM.render` to manually render a React component into the dom. Why would you want to call `ReactDOM.render` yourself? One possible use case is [code splitting](docs/additional-reading/code-splitting.md).
323
325
 
@@ -340,7 +342,7 @@ react_component(component_name,
340
342
  html_options: {})
341
343
  ```
342
344
 
343
- + **component_name:** Can be a React component, created using a ES6 class, or `React.createClass`, a generator function that returns a React component, or a renderer function that manually renders a React component to the dom (client side only).
345
+ + **component_name:** Can be a React component, created using a ES6 class, or `React.createClass`, a generator function that returns a React component (or only on the server side, an object with shape { redirectLocation, error, renderedHtml }), or a renderer function that manually renders a React component to the dom (client side only).
344
346
  + **options:**
345
347
  + **props:** Ruby Hash which contains the properties to pass to the react object, or a JSON string. If you pass a string, we'll escape it for you.
346
348
  + **prerender:** enable server-side rendering of component. Set to false when debugging!
@@ -5,6 +5,9 @@ The generator has created the necessary files and gems for deployment to Heroku.
5
5
  + `12factor` gem: required by Heroku if using a version before Rails 5 (see their [README](https://github.com/heroku/rails_12factor#rails-5) for more information if upgrading from a lower version)
6
6
  + `'puma'` gem: recommended Heroku webserver
7
7
  + `config/puma.rb`: Puma webserver config file
8
+ + `/package.json`: Top level package.json which must contain `"scripts": { "postinstall": "cd client && npm install" }`
9
+
10
+ If you want to see an updated example deployed to Heroku, please visit the [github.com/shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial).
8
11
 
9
12
  ## More details on precompilation using webpack to create JavaScript assets
10
13
  This is how the rake task gets modified. You should be able to call `clear_prerequisites` and setup your own custom precompile if needed.
@@ -46,3 +46,68 @@ For a fleshed out integration of react_on_rails with react-router, check out [Re
46
46
  * [react-webpack-rails-tutorial/client/app/bundles/comments/startup/ClientRouterApp.jsx](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/app/bundles/comments/startup/ClientRouterApp.jsx)
47
47
 
48
48
  * [react-webpack-rails-tutorial/client/app/bundles/comments/startup/ServerRouterApp.jsx](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/app/bundles/comments/startup/ServerRouterApp.jsx)
49
+
50
+
51
+ # Server Rendering Using React Router V4
52
+
53
+ Your generator function may not return an object with the property `renderedHtml`. Thus, you call
54
+ renderToString() and return an object with this property.
55
+
56
+ This example **only applies to server rendering** and should be only used in the server side bundle.
57
+
58
+ From the [original example in the ReactRouter docs](https://react-router.now.sh/ServerRouter)
59
+
60
+ ```javascript
61
+ import React from 'react'
62
+ import { renderToString } from 'react-dom/server'
63
+ import { ServerRouter, createServerRenderContext } from 'react-router'
64
+
65
+ const ReactRouterComponent = (props, railsContext) => {
66
+
67
+ // first create a context for <ServerRouter>, it's where we keep the
68
+ // results of rendering for the second pass if necessary
69
+ const context = createServerRenderContext()
70
+ const { location } = railsContext;
71
+
72
+ // render the first time
73
+ let markup = renderToString(
74
+ <ServerRouter
75
+ location={location}
76
+ context={context}
77
+ >
78
+ <App/>
79
+ </ServerRouter>
80
+ )
81
+
82
+ // get the result
83
+ const result = context.getResult()
84
+
85
+ // the result will tell you if it redirected, if so, we ignore
86
+ // the markup and send a proper redirect.
87
+ if (result.redirect) {
88
+ return {
89
+ redirectLocation: result.redirect.pathname
90
+ };
91
+ } else {
92
+
93
+ // the result will tell you if there were any misses, if so
94
+ // we can send a 404 and then do a second render pass with
95
+ // the context to clue the <Miss> components into rendering
96
+ // this time (on the client they know from componentDidMount)
97
+ if (result.missed) {
98
+ // React on Rails does not support the 404 status code for the browser.
99
+ // res.writeHead(404)
100
+
101
+ markup = renderToString(
102
+ <ServerRouter
103
+ location={location}
104
+ context={context}
105
+ >
106
+ <App/>
107
+ </ServerRouter>
108
+ )
109
+ }
110
+ return { renderedHtml: markup };
111
+ }
112
+ }
113
+ ```
@@ -4,7 +4,9 @@ The best source of docs is the main [ReactOnRails.js](../../node_package/src/Rea
4
4
  ```js
5
5
  /**
6
6
  * Main entry point to using the react-on-rails npm package. This is how Rails will be able to
7
- * find you components for rendering.
7
+ * find you components for rendering. Components get called with props, or you may use a
8
+ * "generator function" to return a React component or an object with the following shape:
9
+ * { renderedHtml, redirectLocation, error }.
8
10
  * @param components (key is component name, value is component)
9
11
  */
10
12
  register(components)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ReactOnRails
3
- VERSION = "6.4.0".freeze
3
+ VERSION = "6.4.1".freeze
4
4
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "6.4.0",
3
+ "version": "6.4.1",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
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: 6.4.0
4
+ version: 6.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-13 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool