react_on_rails 11.2.1 → 12.0.0.pre.beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +320 -0
  3. data/.eslintignore +2 -1
  4. data/.eslintrc +23 -1
  5. data/.github/FUNDING.yml +1 -0
  6. data/.gitignore +3 -1
  7. data/.prettierignore +10 -1
  8. data/.prettierrc +3 -0
  9. data/.rubocop.yml +37 -11
  10. data/.travis.yml +10 -20
  11. data/CHANGELOG.md +85 -9
  12. data/CONTRIBUTING.md +60 -71
  13. data/Gemfile +3 -4
  14. data/{COMM-LICENSE → REACT-ON-RAILS-PRO-LICENSE} +6 -9
  15. data/README.md +121 -71
  16. data/Rakefile +0 -7
  17. data/SUMMARY.md +9 -12
  18. data/book.json +5 -5
  19. data/docs/additional-reading/asset-pipeline.md +8 -16
  20. data/docs/additional-reading/react-helmet.md +30 -10
  21. data/docs/additional-reading/react-router.md +52 -75
  22. data/docs/additional-reading/server-rendering-tips.md +12 -7
  23. data/docs/api/javascript-api.md +3 -3
  24. data/docs/api/redux-store-api.md +4 -2
  25. data/docs/api/view-helpers-api.md +8 -9
  26. data/docs/basics/configuration.md +68 -59
  27. data/docs/basics/deployment.md +1 -2
  28. data/docs/basics/hmr-and-hot-reloading-with-the-webpack-dev-server.md +49 -0
  29. data/docs/basics/i18n.md +44 -22
  30. data/docs/basics/installation-into-an-existing-rails-app.md +2 -2
  31. data/docs/basics/minitest-configuration.md +31 -0
  32. data/docs/basics/react-server-rendering.md +1 -1
  33. data/docs/basics/{generator-functions-and-railscontext.md → render-functions-and-railscontext.md} +59 -21
  34. data/docs/basics/rspec-configuration.md +29 -17
  35. data/docs/basics/upgrading-react-on-rails.md +67 -3
  36. data/docs/basics/webpack-configuration.md +15 -1
  37. data/docs/contributor-info/errors-with-hooks.md +45 -0
  38. data/docs/contributor-info/pull-requests.md +44 -0
  39. data/docs/misc/doctrine.md +1 -1
  40. data/docs/{misc-pending → outdated}/code-splitting.md +12 -8
  41. data/docs/{additional-reading → outdated}/heroku-deployment.md +0 -6
  42. data/docs/{basics → outdated}/how-react-on-rails-works.md +3 -3
  43. data/docs/{misc-pending → outdated}/manual-installation-overview.md +5 -5
  44. data/docs/{additional-reading → outdated}/rails-assets-relative-paths.md +3 -3
  45. data/docs/{misc-pending → outdated}/rails-assets.md +4 -7
  46. data/docs/{misc → outdated}/rails3.md +0 -0
  47. data/docs/testimonials/resortpass.md +13 -0
  48. data/docs/testimonials/testimonials.md +11 -1
  49. data/docs/tutorial.md +96 -70
  50. data/jest.config.js +4 -0
  51. data/lib/generators/react_on_rails/base_generator.rb +2 -2
  52. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  53. data/lib/generators/react_on_rails/generator_helper.rb +4 -6
  54. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev +3 -1
  55. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr +26 -0
  56. data/lib/generators/react_on_rails/templates/base/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +20 -40
  57. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +2 -1
  58. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/components/HelloWorld.jsx +4 -8
  59. data/lib/generators/react_on_rails/templates/redux/base/app/javascript/bundles/HelloWorld/store/helloWorldStore.js +1 -3
  60. data/lib/react_on_rails.rb +3 -1
  61. data/lib/react_on_rails/configuration.rb +13 -22
  62. data/lib/react_on_rails/error.rb +2 -0
  63. data/lib/react_on_rails/helper.rb +100 -143
  64. data/lib/react_on_rails/json_parse_error.rb +2 -0
  65. data/lib/react_on_rails/locales/base.rb +150 -0
  66. data/lib/react_on_rails/locales/to_js.rb +37 -0
  67. data/lib/react_on_rails/locales/to_json.rb +27 -0
  68. data/lib/react_on_rails/prerender_error.rb +11 -15
  69. data/lib/react_on_rails/react_component/render_options.rb +4 -0
  70. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +41 -46
  71. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +7 -8
  72. data/lib/react_on_rails/utils.rb +14 -19
  73. data/lib/react_on_rails/version.rb +1 -1
  74. data/lib/react_on_rails/version_checker.rb +1 -0
  75. data/lib/react_on_rails/webpacker_utils.rb +13 -2
  76. data/lib/tasks/assets.rake +19 -44
  77. data/lib/tasks/locale.rake +4 -2
  78. data/package-scripts.yml +11 -8
  79. data/package.json +29 -28
  80. data/rakelib/dummy_apps.rake +1 -9
  81. data/rakelib/example_type.rb +3 -1
  82. data/rakelib/examples.rake +3 -0
  83. data/rakelib/lint.rake +2 -7
  84. data/rakelib/node_package.rake +2 -2
  85. data/rakelib/release.rake +0 -6
  86. data/rakelib/run_rspec.rake +5 -18
  87. data/react_on_rails.gemspec +3 -5
  88. data/tsconfig.json +14 -0
  89. data/webpackConfigLoader.js +3 -2
  90. data/yarn.lock +4170 -2197
  91. metadata +34 -57
  92. data/Gemfile.rails32 +0 -73
  93. data/docs/additional-reading/babel.md +0 -5
  94. data/docs/additional-reading/hot-reloading-rails-development-asset-pipeline.md +0 -47
  95. data/docs/api/ruby-api-hot-reload-view-helpers.md +0 -44
  96. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-server +0 -12
  97. data/lib/react_on_rails/assets_precompile.rb +0 -153
  98. data/lib/react_on_rails/locales_to_js.rb +0 -138
@@ -1,39 +1,28 @@
1
+ _This article needs updating for the latest version of React Router_
2
+
1
3
  # Using React Router
2
4
 
3
- React on Rails supports the use of React Router. Client-side code doesn't need any special configuration for the React on Rails gem. Implement React Router how you normally would. Note, you might want to avoid using Turbolinks as both Turbolinks and React-Router will be trying to handle the back and forward buttons. If you get this figured out, please do share with the community! Otherwise, you might have to tweak the basic settings for Turbolinks, and this may or may not be worth the effort.
4
5
 
5
- When attempting to use server-rendering, it is necessary to take steps that prevent rendering when there is a router error or redirect. In these cases, the client code should return an object containing the `error` and a `redirectLocation` instead of the React component. The `react_component` helper method in your Rails view will automatically detect that there was an error/redirect and handle it accordingly.
6
+ React on Rails supports the use of React Router. Client-side code doesn't need any special configuration for the React on Rails gem. Implement React Router how you normally would. Note, you might want to avoid using Turbolinks as both Turbolinks and React-Router will be trying to handle the back and forward buttons. If you get this figured out, please do share with the community! Otherwise, you might have to tweak the basic settings for Turbolinks, and this may or may not be worth the effort.
6
7
 
7
8
  If you are working with the HelloWorldApp created by the react_on_rails generator, then the code below corresponds to the module in `client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx`.
8
9
 
9
10
  ```js
11
+
12
+ import { BrowserRouter, Switch } from 'react-router-dom'
13
+ import routes from './routes.jsx'
14
+
10
15
  const RouterApp = (props, railsContext) => {
11
- let error;
12
- let redirectLocation;
13
- let routeProps;
14
- const { location } = railsContext;
15
-
16
16
  // create your hydrated store
17
17
  const store = createStore(props);
18
-
19
- // See https://github.com/reactjs/react-router/blob/master/docs/guides/ServerRendering.md
20
- match({ routes, location }, (_error, _redirectLocation, _routeProps) => {
21
- error = _error;
22
- redirectLocation = _redirectLocation;
23
- routeProps = _routeProps;
24
- });
25
-
26
- // This tell react_on_rails to skip server rendering any HTML. Note, client rendering
27
- // will handle the redirect. What's key is that we don't try to render.
28
- // Critical to return the Object properties to match this { error, redirectLocation }
29
- if (error || redirectLocation) {
30
- return { error, redirectLocation };
31
- }
32
-
33
- // Important that you don't do this if you are redirecting or have an error.
18
+
34
19
  return (
35
20
  <Provider store={store}>
36
- <RouterContext {...routeProps} />
21
+ <BrowserRouter>
22
+ <Switch>
23
+ {routes}
24
+ </Switch>
25
+ </BrowserRouter>
37
26
  </Provider>
38
27
  );
39
28
  };
@@ -50,64 +39,52 @@ For a fleshed out integration of react_on_rails with react-router, check out [Re
50
39
 
51
40
  # Server Rendering Using React Router V4
52
41
 
53
- Your generator function may not return an object with the property `renderedHtml`. Thus, you call
42
+ Your render function may not return an object with the property `renderedHtml`. Thus, you call
54
43
  renderToString() and return an object with this property.
55
44
 
56
45
  This example **only applies to server rendering** and should be only used in the server side bundle.
57
46
 
58
- From the [original example in the ReactRouter docs](https://react-router.now.sh/ServerRouter)
47
+ From the [original example in the ReactRouter docs](https://github.com/ReactTraining/react-router/blob/v4.3.1/packages/react-router-dom/docs/guides/server-rendering.md)
59
48
 
60
49
  ```javascript
61
50
  import React from 'react'
62
51
  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
- }
52
+ import { StaticRouter } from 'react-router'
53
+ import { Provider } from 'react-redux'
54
+ import ReactOnRails from 'react-on-rails'
55
+
56
+ // App.jsx from src/client/App.jsx
57
+ import App from '../App'
58
+
59
+ const ReactServerRenderer = (props, railsContext) => {
60
+ const context = {}
61
+
62
+ // commentStore from src/server/store/commentStore
63
+ const store = ReactOnRails.getStore('../store/commentStore')
64
+
65
+ // Route Store generated from react-on-rails
66
+
67
+ const { location } = railsContext
68
+
69
+ const html = ReactDOMServer.renderToString(
70
+ <Provider store={store}>
71
+ <StaticRouter
72
+ location={location}
73
+ context={context}
74
+ props={props}
75
+ >
76
+ <App />
77
+ </StaticRouter>
78
+ </ Provider>
79
+ )
80
+
81
+ if (context.url) {
82
+ // Somewhere a `<Redirect>` was rendered
83
+ redirect(301, context.url)
84
+ } else {
85
+ // we're good, send the response
86
+ return { renderedHtml: html };
87
+ }
88
+ }
112
89
  }
113
90
  ```
@@ -1,14 +1,19 @@
1
1
  # Server Rendering Tips
2
2
 
3
- Be sure to use mini_racer. See [issues/428](https://github.com/shakacode/react_on_rails/issues/428)
3
+ For the best performance with Server Rendering, consider using [React on Rails Pro]
4
+
5
+ Be sure to use mini_racer. See [issues/428](https://github.com/shakacode/react_on_rails/issues/428).
6
+
7
+
4
8
 
5
9
  ## General Tips
6
- - Your code can't reference `document`. Server side JS execution does not have access to `document`, so jQuery and some
7
- other libs won't work in this environment. You can debug this by putting in `console.log`
8
- statements in your code.
9
- - You can conditionally avoid running code that references document by passing in a boolean prop to your top level react
10
- component. Since the passed in props Hash from the view helper applies to client and server side code, the best way to
11
- do this is to use a generator function.
10
+ - Your code can't reference `document`. Server side JS execution does not have access to `document`,
11
+ so jQuery and some other libs won't work in this environment. You can debug this by putting in
12
+ `console.log` statements in your code.
13
+ - You can conditionally avoid running code that references document by either checking if `window`
14
+ is defined or using the "railsContext"
15
+ your top level react component. Since the passed in props Hash from the view helper applies to
16
+ client and server side code, the best way to do this is to use a render function.
12
17
  - 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. 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
18
  - You can enable Node.js server rendering via [React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
14
19
 
@@ -25,10 +25,10 @@ The best source of docs is the main [ReactOnRails.js](https://github.com/shakaco
25
25
  /**
26
26
  * Main entry point to using the react-on-rails npm package. This is how Rails will be able to
27
27
  * find you components for rendering. Components get called with props, or you may use a
28
- * "generator function" to return a React component or an object with the following shape:
28
+ * "render function" to return a React component or an object with the following shape:
29
29
  * { renderedHtml, redirectLocation, error }.
30
- * For server rendering, if you wish to return multiple HTML strings from a generator function,
31
- * you may return an Object from your generator function with a single top level property of
30
+ * For server rendering, if you wish to return multiple HTML strings from a render function,
31
+ * you may return an Object from your render function with a single top level property of
32
32
  * renderedHtml. Inside this Object, place a key called componentHtml, along with any other
33
33
  * needed keys. This is useful when you using side effects libraries like react helmet.
34
34
  * Your Ruby code with get this Object as a Hash containing keys componentHtml and any other
@@ -1,8 +1,10 @@
1
1
  # Redux Store
2
2
 
3
- First things first. You don't need to use the `redux_store` api to use redux. This api was setup to support multiple calls to `react_component` on one page that all talk to the same redux store.
3
+ _This redux API is no longer recommended as it prevents dynamic code splitting for performance. Instead, you should use the standard react_component view helper passing in a "render function."_
4
4
 
5
- If you are only rendering one react component on a page, as is typical to do a "Single Page App" in React, then you should _probably_ pass the props to your React component in a "generator function."
5
+ You don't need to use the `redux_store` api to use redux. This api was setup to support multiple calls to `react_component` on one page that all talk to the same redux store.
6
+
7
+ If you are only rendering one react component on a page, as is typical to do a "Single Page App" in React, then you should _probably_ pass the props to your React component in a "render function."
6
8
 
7
9
  Consider using the `redux_store` helper for the two following use cases:
8
10
 
@@ -22,13 +22,13 @@ Uncommonly used options:
22
22
  id: nil,
23
23
  ```
24
24
 
25
- - **component_name:** Can be a React component, created using an ES6 class or 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).
25
+ - **component_name:** Can be a React component, created using an ES6 class or a render 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).
26
26
  All options except `props, id, html_options` will inherit from your `react_on_rails.rb` initializer, as described [here](../basics/configuration.md).
27
27
  - **general options:**
28
28
  - **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.
29
29
  - **prerender:** enable server-side rendering of a component. Set to false when debugging!
30
30
  - **id:** Id for the div, will be used to attach the React component. This will get assigned automatically if you do not provide an id. Must be unique.
31
- - **html_options:** Any other HTML options get placed on the added div for the component. For example, you can set a class (or inline style) on the outer div so that it behaves like a span, with the styling of `display:inline-block`.
31
+ - **html_options:** Any other HTML options get placed on the added div for the component. For example, you can set a class (or inline style) on the outer div so that it behaves like a span, with the styling of `display:inline-block`. You may also use an option of `tag: "span"` to replace the use of the default DIV tag to be a SPAN tag.
32
32
  - **trace:** set to true to print additional debugging information in the browser. Defaults to true for development, off otherwise. Only on the **client side** will you will see the `railsContext` and your props.
33
33
  - **random_dom_id:** True to automatically generate random dom ids when using multiple instances of the same React component on one Rails view.
34
34
  - **options if prerender (server rendering) is true:**
@@ -45,7 +45,7 @@ adding meta-tags to a page. It is exactly like react_component except for the fo
45
45
 
46
46
  1. `prerender: true` is automatically added to options, as this method doesn't make sense for
47
47
  client only rendering.
48
- 2. Your JavaScript generator function for server rendering must return an Object rather than a React Component.
48
+ 2. Your JavaScript render function for server rendering must return an Object rather than a React Component.
49
49
  3. Your view code must expect an object and not a string.
50
50
 
51
51
  Here is an example of ERB view code:
@@ -73,7 +73,6 @@ export default (props, _railsContext) => {
73
73
  };
74
74
  return { renderedHtml };
75
75
  };
76
-
77
76
  ```
78
77
 
79
78
  ------------
@@ -93,17 +92,17 @@ end %>
93
92
 
94
93
  ### rails_context
95
94
 
96
- You can call `rails_context(server_side: true | false)` from your controller or view to see what values are are in the Rails Context. Pass true or false depending on whether you want to see the server side or the client side rails_context.
95
+ You can call `rails_context` or `rails_context(server_side: true|false)` from your controller or view to see what values are are in the Rails Context. Pass true or false depending on whether you want to see the server side or the client side rails_context. Typically, for computing cache keys, you should leave server_side as the default true. When calling this from a controller method, use `helpers.rails_context`.
97
96
 
98
97
  ------------
99
98
 
100
99
  ### Renderer Functions (function that will call ReactDOM.render or ReactDOM.hydrate)
101
100
 
102
- A "renderer function" is a generator function that accepts three arguments (rather than 2): `(props, railsContext, domNodeId) => { ... }`. Instead of returning a React component, a renderer is responsible for installing a callback that will call `ReactDOM.render` (in React 16+, `ReactDOM.hydrate`) to render a React component into the DOM. The "renderer function" is called at the same time the document ready event would instantate the React components into the DOM.
101
+ A "renderer function" is a render function that accepts three arguments (rather than 2): `(props, railsContext, domNodeId) => { ... }`. Instead of returning a React component, a renderer is responsible for installing a callback that will call `ReactDOM.render` (in React 16+, `ReactDOM.hydrate`) to render a React component into the DOM. The "renderer function" is called at the same time the document ready event would instantate the React components into the DOM.
103
102
 
104
- Why would you want to call `ReactDOM.hydrate` yourself? One possible use case is [code splitting](../misc-pending/code-splitting.md). In a nutshell, you don't want to load the React component on the DOM node yet. So you want to install some handler that will call `ReactDOM.hydrate` at a later time. In the case of code splitting with server rendering, the server rendered code has any async code loaded and used to server render. Thus, the client code must also fully load any asynch code before server rendering. Otherwise, the client code would first render partially, not matching the server rendering, and then a second later, the full code would render, resulting in an unpleasant flashing on the screen.
103
+ Why would you want to call `ReactDOM.hydrate` yourself? One possible use case is [code splitting](docs/outdated/code-splitting.md). In a nutshell, you don't want to load the React component on the DOM node yet. So you want to install some handler that will call `ReactDOM.hydrate` at a later time. In the case of code splitting with server rendering, the server rendered code has any async code loaded and used to server render. Thus, the client code must also fully load any asynch code before server rendering. Otherwise, the client code would first render partially, not matching the server rendering, and then a second later, the full code would render, resulting in an unpleasant flashing on the screen.
105
104
 
106
- Renderer functions are not meant to be used on the server since there's no DOM on the server. Instead, use a generator function. Attempting to server render with a renderer function will throw an error.
105
+ Renderer functions are not meant to be used on the server since there's no DOM on the server. Instead, use a render function. Attempting to server render with a renderer function will throw an error.
107
106
 
108
107
  ------------
109
108
 
@@ -113,7 +112,7 @@ Renderer functions are not meant to be used on the server since there's no DOM o
113
112
 
114
113
  1. [React on Rails docs for react-router](../additional-reading/react-router.md)
115
114
  2. 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).
116
- 3. [Code Splitting docs](../misc-pending/code-splitting.md) for information about how to set up code splitting for server rendered routes.
115
+ 3. [Code Splitting docs](docs/outdated/code-splitting.md) for information about how to set up code splitting for server rendered routes.
117
116
 
118
117
  ------------
119
118
 
@@ -59,58 +59,15 @@ ReactOnRails.configure do |config|
59
59
 
60
60
  # defaults to "" (top level)
61
61
  #
62
- config.node_modules_location = "client" # Recommended!
62
+ config.node_modules_location = "client" # If using webpacker you should use "".
63
63
 
64
- # This configures the script to run to build the production assets by webpack. Set this to nil
64
+ # This configures the script to run to build the production assets by webpack . Set this to nil
65
65
  # if you don't want react_on_rails building this file for you.
66
+ # Note, if you want to use this command then you should remove the file
67
+ # config/webpack/production.js
68
+ # If that file exists, React on Rails thinks that you'll use the rails/webpacker bin/webpack compiler.
66
69
  config.build_production_command = "RAILS_ENV=production bin/webpack"
67
70
 
68
- ################################################################################
69
- ################################################################################
70
- # TEST CONFIGURATION OPTIONS
71
- # Below options are used with the use of this test helper:
72
- # ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
73
- ################################################################################
74
-
75
- # If you are using this in your spec_helper.rb (or rails_helper.rb):
76
- #
77
- # ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
78
- #
79
- # with rspec then this controls what yarn command is run
80
- # to automatically refresh your webpack assets on every test run.
81
- #
82
- config.build_test_command = "RAILS_ENV=test bin/webpack"
83
-
84
- # Directory where your generated assets go. All generated assets must go to the same directory.
85
- # If you are using webpacker, this value will come from your config/webpacker.yml file.
86
- # This is the default in webpacker.yml:
87
- # public_output_path: packs-test
88
- # which means files in /public/packs-test
89
- #
90
- # Alternately, you may configure this if you are NOT using webpacker. It is relative to your Rails
91
- # root directory. A custom, non-webpacker, config might use something like:
92
- #
93
- # config.generated_assets_dir = File.join(%w[public webpack], Rails.env)
94
- # This setting should not be used if using webpacker.
95
-
96
- # CONFIGURE YOUR SOURCE FILES
97
- # The test helper needs to know where your JavaScript files exist. The default is configured
98
- # by your config/webpacker.yml soure_path:
99
- # source_path: client/app/javascript # if using recommended /client directory
100
- #
101
- # If you are not using webpacker, the `node_modules_location` is assumed to be the location of your source
102
- # files.
103
-
104
- # Define the files we need to check for webpack compilation when running tests.
105
- # The default is `%w( manifest.json )` as will be sufficient for most webpacker builds.
106
- # However, if you are generated a server bundle that is NOT hashed (present in manifest.json),
107
- # then include the file in this list like this:
108
- #
109
- config.webpack_generated_files = %w( server-bundle.js manifest.json )
110
-
111
- # You can optionally add values to your rails_context. See example below for RenderingExtension
112
- # config.rendering_extension = RenderingExtension
113
-
114
71
  ################################################################################
115
72
  ################################################################################
116
73
  # SERVER RENDERING OPTIONS
@@ -127,27 +84,37 @@ ReactOnRails.configure do |config|
127
84
  # you should include a name that matches your bundle name in your webpack config.
128
85
  config.server_bundle_js_file = "server-bundle.js"
129
86
 
87
+ # THE BELOW OPTIONS FOR SERVER-SIDE RENDERING RARELY NEED CHANGING
88
+ #
89
+ # This value only affects server-side rendering when using the webpack-dev-server
90
+ # If you are hashing the server bundle and you want to use the same bundle for client and server,
91
+ # you'd set this to `true` so that React on Rails reads the server bundle from the webpack-dev-server.
92
+ # Normally, you have different bundles for client and server, thus, the default is false.
93
+ # Furthermore, if you are not hashing the server bundle (not in the manifest.json), then React on Rails
94
+ # will only look for the server bundle to be created in the typical file location, typically by
95
+ # a `webpack --watch` process.
96
+ # If true, ensure that in config/webpacker.yml that you have both dev_server.hmr and
97
+ # dev_server.inline set to false.
98
+ config.same_bundle_for_client_and_server = false
99
+
130
100
  # If set to true, this forces Rails to reload the server bundle if it is modified
131
101
  # Default value is Rails.env.development?
132
- #
102
+ # You probably will never change this.
133
103
  config.development_mode = Rails.env.development?
134
104
 
135
- # For server rendering so that it replays in the browser console.
105
+ # For server rendering so that the server-side console replays in the browser console.
136
106
  # This can be set to false so that server side messages are not displayed in the browser.
137
- # Default is true. Be cautious about turning this off.
107
+ # Default is true. Be cautious about turning this off, as it can make debugging difficult.
138
108
  # Default value is true
139
- #
140
109
  config.replay_console = true
141
110
 
142
111
  # Default is true. Logs server rendering messages to Rails.logger.info. If false, you'll only
143
112
  # see the server rendering messages in the browser console.
144
- #
145
113
  config.logging_on_server = true
146
114
 
147
115
  # Default is true only for development? to raise exception on server if the JS code throws for
148
116
  # server rendering. The reason is that the server logs will show the error and force you to fix
149
117
  # any server rendering issues immediately during development.
150
- #
151
118
  config.raise_on_prerender_error = Rails.env.development?
152
119
 
153
120
  ################################################################################
@@ -172,6 +139,7 @@ ReactOnRails.configure do |config|
172
139
  # Replace the following line to the location where you keep translation.js & default.js for use
173
140
  # by the npm packages react-intl. Be sure this directory exists!
174
141
  # config.i18n_dir = Rails.root.join("client", "app", "libs", "i18n")
142
+ #
175
143
  # If not using the i18n feature, then leave this section commented out or set the value
176
144
  # of config.i18n_dir to nil.
177
145
  #
@@ -179,8 +147,12 @@ ReactOnRails.configure do |config|
179
147
  # that will source for automatic generation on translations.js & default.js
180
148
  # By default(without this option) all yaml files from Rails.root.join("config", "locales")
181
149
  # and installed gems are loaded
182
- config.i18n_yml_dir = Rails.root.join("config", "locales", "client")
150
+ config.i18n_yml_dir = Rails.root.join("config", "locales")
183
151
 
152
+ # Possible output formats are js and json
153
+ # The default format is json
154
+ config.i18n_output_format = 'json'
155
+
184
156
  ################################################################################
185
157
  ################################################################################
186
158
  # CLIENT RENDERING OPTIONS
@@ -189,8 +161,47 @@ ReactOnRails.configure do |config|
189
161
  ################################################################################
190
162
  # default is false
191
163
  config.prerender = false
192
- end
193
164
 
165
+ # You can optionally add values to your rails_context. This object is passed
166
+ # every time a component renders.
167
+ # See example below for an example definition of RenderingExtension
168
+ #
169
+ # config.rendering_extension = RenderingExtension
170
+
171
+ ################################################################################
172
+ ################################################################################
173
+ # TEST CONFIGURATION OPTIONS
174
+ # Below options are used with the use of this test helper:
175
+ # ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
176
+ #
177
+ # NOTE:
178
+ # Instead of using this test helper, you may ensure fresh test files using rails/webpacker via:
179
+ # 1. Have `config/webpacker/test.js` exporting an array of objects to configure both client and server bundles.
180
+ # 2. Set the compile option to true in config/webpacker.yml for env test
181
+ ################################################################################
182
+
183
+ # If you are using this in your spec_helper.rb (or rails_helper.rb):
184
+ #
185
+ # ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
186
+ #
187
+ # with rspec then this controls what yarn command is run
188
+ # to automatically refresh your webpack assets on every test run.
189
+ #
190
+ config.build_test_command = "RAILS_ENV=test bin/webpack"
191
+
192
+ # CONFIGURE YOUR SOURCE FILES
193
+ # The test helper needs to know where your JavaScript files exist. The value is configured
194
+ # by your config/webpacker.yml source_path:
195
+ # source_path: client/app # if using recommended /client directory
196
+ #
197
+ # Define the files we need to check for webpack compilation when running tests.
198
+ # The default is `%w( manifest.json )` as will be sufficient for most webpacker builds.
199
+ # However, if you are generated a server bundle that is NOT hashed (present in manifest.json),
200
+ # then include the file in this list like this:
201
+ config.webpack_generated_files = %w( server-bundle.js manifest.json )
202
+ # Note, be sure NOT to include your server-bundle.js if it is hashed, or else React on Rails will
203
+ # think the server-bundle.js is missing every time for test runs.
204
+ end
194
205
  ```
195
206
 
196
207
  Example of a RenderingExtension for custom values in the `rails_context`:
@@ -199,7 +210,7 @@ Example of a RenderingExtension for custom values in the `rails_context`:
199
210
  module RenderingExtension
200
211
 
201
212
  # Return a Hash that contains custom values from the view context that will get merged with
202
- # the standard rails_context values and passed to all calls to generator functions used by the
213
+ # the standard rails_context values and passed to all calls to render functions used by the
203
214
  # react_component and redux_store view helpers
204
215
  def self.custom_context(view_context)
205
216
  {
@@ -208,5 +219,3 @@ module RenderingExtension
208
219
  end
209
220
  end
210
221
  ```
211
-
212
-