react_on_rails 6.4.2 → 6.5.0.beta.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: cc9ce8dfafb075ba679a34c960037df7c61746ff
4
- data.tar.gz: 35d775a65518d91e1b46733758cdf9883c52b6ac
3
+ metadata.gz: 66dd313d68c7587349dba811710050bd0b68c065
4
+ data.tar.gz: 8593a20efabecdc8b53ab2ab868a7a5a22e2c5e5
5
5
  SHA512:
6
- metadata.gz: 8e6c98e563102e792da954e116ef75e7774c13698c970be417869d667364e0bfa604b4e815eb9e22f9e87540e897da7988bd3823ec98836c98846e763195081e
7
- data.tar.gz: d675c0ad865f9edd283ba64344e2912cceac4ec50720c6f00c676a8e1d458ad5363cefa86f1f7adcac9847613215fae47701bb7e090b786cbf4bfa31710b7c97
6
+ metadata.gz: f70c7504fc02efd692bef39cd628bb7bff67ad69c56d18d6e2b1da6e5abdfff5d41ab678754626f11ebb3be2bc18a7e6d6d7ad39ed0c7aec3a87788134722392
7
+ data.tar.gz: 1f986e7e885762669dbdb3ef802d246989daafb3b0bbdcaef59cae15846e7a08aa17d73f7a673dc71f769fe04f9881ca9ada7700d27095a9b2a03006dce4acaa
data/CHANGELOG.md CHANGED
@@ -6,17 +6,10 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
6
6
  ## [Unreleased]
7
7
  *Please add entries here for your pull requests.*
8
8
 
9
- ## [6.4.2] - 2017-1-17
10
- ### Fixed
11
- - Added OS detection for install generator, system call for Windows and unit-tests for it. [#666](https://github.com/shakacode/react_on_rails/pull/666) by [GeorgeGorbanev](https://github.com/GeorgeGorbanev).
12
-
13
- ## [6.4.1] - 2017-1-17
14
- No changes.
15
-
16
9
  ## [6.4.0] - 2017-1-12
17
10
 
18
11
  ### Possible Breaking Change
19
- - 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.
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.
20
13
 
21
14
  ### Fixed
22
15
  - Removed foreman as a dependency. [#678](https://github.com/shakacode/react_on_rails/pull/678) by [x2es](https://github.com/x2es).
@@ -435,9 +428,7 @@ Best done with Object destructing:
435
428
  ##### Fixed
436
429
  - Fix several generator related issues.
437
430
 
438
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.4.2...master
439
- [6.4.2]: https://github.com/shakacode/react_on_rails/compare/6.4.1...6.4.2
440
- [6.4.1]: https://github.com/shakacode/react_on_rails/compare/6.4.0...6.4.1
431
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.4.0...master
441
432
  [6.4.0]: https://github.com/shakacode/react_on_rails/compare/6.3.5...6.4.0
442
433
  [6.3.5]: https://github.com/shakacode/react_on_rails/compare/6.3.4...6.3.5
443
434
  [6.3.4]: https://github.com/shakacode/react_on_rails/compare/6.3.3...6.3.4
data/README.md CHANGED
@@ -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!
@@ -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)
@@ -64,7 +64,7 @@ module ReactOnRails
64
64
  end
65
65
 
66
66
  def missing_npm?
67
- return false unless ReactOnRails::Utils.running_on_windows? ? `where npm`.blank? : `which npm`.blank?
67
+ return false unless `which npm`.blank?
68
68
  error = "npm is required. Please install it before continuing. "
69
69
  error << "https://www.npmjs.com/"
70
70
  GeneratorMessages.add_error(error)
@@ -72,7 +72,7 @@ module ReactOnRails
72
72
  end
73
73
 
74
74
  def missing_node?
75
- return false unless ReactOnRails::Utils.running_on_windows? ? `where node`.blank? : `which node`.blank?
75
+ return false unless `which node`.blank?
76
76
  error = "** nodejs is required. Please install it before continuing. "
77
77
  error << "https://nodejs.org/en/"
78
78
  GeneratorMessages.add_error(error)
@@ -20,10 +20,6 @@ module ReactOnRails
20
20
  ReactOnRails.configuration.server_bundle_js_file)
21
21
  end
22
22
 
23
- def self.running_on_windows?
24
- (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
25
- end
26
-
27
23
  module Required
28
24
  def required(arg_name)
29
25
  raise ArgumentError, "#{arg_name} is required"
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ReactOnRails
3
- VERSION = "6.4.2".freeze
3
+ VERSION = "6.5.0.beta.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.2",
3
+ "version": "6.5.0-beta.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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.4.2
4
+ version: 6.5.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
@@ -445,9 +445,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
445
445
  version: 2.0.0
446
446
  required_rubygems_version: !ruby/object:Gem::Requirement
447
447
  requirements:
448
- - - ">="
448
+ - - ">"
449
449
  - !ruby/object:Gem::Version
450
- version: '0'
450
+ version: 1.3.1
451
451
  requirements: []
452
452
  rubyforge_project:
453
453
  rubygems_version: 2.6.8