react_on_rails 12.3.0 → 12.4.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +12 -10
  3. data/CHANGELOG.md +21 -15
  4. data/NEWS.md +9 -3
  5. data/README.md +12 -308
  6. data/SUMMARY.md +12 -12
  7. data/docs/additional-details/generator-details.md +1 -1
  8. data/docs/additional-details/manual-installation-overview.md +2 -2
  9. data/docs/api/view-helpers-api.md +4 -4
  10. data/docs/contributor-info/linters.md +1 -1
  11. data/docs/contributor-info/pull-requests.md +1 -1
  12. data/docs/{basics → guides}/client-vs-server-rendering.md +1 -1
  13. data/docs/{basics → guides}/configuration.md +0 -0
  14. data/docs/{basics → guides}/deployment.md +1 -1
  15. data/docs/guides/getting-started.md +183 -0
  16. data/docs/{basics → guides}/hmr-and-hot-reloading-with-the-webpack-dev-server.md +0 -0
  17. data/docs/{basics → guides}/how-react-on-rails-works.md +3 -1
  18. data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +39 -0
  19. data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +98 -0
  20. data/docs/{basics → guides}/i18n.md +0 -0
  21. data/docs/{basics → guides}/installation-into-an-existing-rails-app.md +3 -3
  22. data/docs/{basics → guides}/minitest-configuration.md +0 -0
  23. data/docs/{rails-webpacker-react-integration-options.md → guides/rails-webpacker-react-integration-options.md} +1 -1
  24. data/docs/guides/react-on-rails-overview.md +30 -0
  25. data/docs/{basics → guides}/react-server-rendering.md +2 -2
  26. data/docs/{basics → guides}/render-functions-and-railscontext.md +0 -0
  27. data/docs/{basics → guides}/rspec-configuration.md +2 -2
  28. data/docs/{basics → guides}/tutorial.md +2 -4
  29. data/docs/{basics → guides}/upgrading-react-on-rails.md +1 -1
  30. data/docs/{basics → guides}/webpack-configuration.md +1 -1
  31. data/docs/home.md +19 -378
  32. data/docs/javascript/code-splitting.md +2 -2
  33. data/docs/misc/articles.md +1 -1
  34. data/docs/misc/doctrine.md +3 -3
  35. data/docs/outdated/rails-assets-relative-paths.md +2 -2
  36. data/docs/outdated/rails-assets.md +1 -1
  37. data/docs/rails/convert-rails-5-api-only-app.md +1 -1
  38. data/docs/rails/rails-engine-integration.md +3 -12
  39. data/docs/react-on-rails-pro/react-on-rails-pro.md +43 -0
  40. data/docs/testimonials/testimonials.md +4 -4
  41. data/lib/react_on_rails/helper.rb +6 -0
  42. data/lib/react_on_rails/locales/base.rb +7 -12
  43. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +9 -0
  44. data/lib/react_on_rails/version.rb +1 -1
  45. data/lib/tasks/assets.rake +3 -1
  46. data/package.json +1 -1
  47. metadata +24 -19
data/README.md CHANGED
@@ -13,47 +13,21 @@
13
13
 
14
14
  *These are the docs for React on Rails 12. To see the version 11 docs, [click here](https://github.com/shakacode/react_on_rails/tree/11.3.0).*
15
15
 
16
- #### News
17
- **October 14, 2020**: [RUBY ROGUES
18
- RR 474: React on Rails V12 – Don’t Shave That Yak! with Justin Gordon](https://devchat.tv/ruby-rogues/rr-474-react-on-rails-v12-dont-shave-that-yak-with-justin-gordon/).
19
-
20
- **October 1, 2020**: See the [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy) example repo for a simple configuration of webpack via the rails/webpacker gem
21
- that supports SSR.
22
-
23
- **August 2, 2020**: See the example repo of [React on Rails Tutorial With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh) for a new way to setup the creation of your SSR bundle with `rails/webpacker`.
24
-
25
- **July 8, 2020**: Release v12 of React on Rails.
26
-
27
- **Major Improvements**
28
-
29
- 1. **React Hooks Support** for top level components
30
- 2. **Typescript bindings**
31
- 3. **rails/webpacker** "just works" with React on Rails by default.
32
- 4. i18n support for generating a JSON file rather than a JS file.
33
-
34
- Be sure to see the [CHANGELOG.md](https://github.com/shakacode/react_on_rails/tree/master/CHANGELOG.md) and read the upgrade instructions:
35
- [docs/basics/upgrading-react-on-rails](https://www.shakacode.com/react-on-rails/docs/basics/upgrading-react-on-rails#upgrading-to-v12).
36
-
37
- * See Justin's RailsConf talk: [Webpacker, It-Just-Works, But How?](http://railsconf.com/2020/video/justin-gordon-webpacker-it-just-works-but-how).
38
- * Are you interested in support for React on Rails? Do you want to use Node.js to do your server-side rendering so libraries like Emotion and Loadable Components just work, as compared to rendering via Ruby embedded JS? If so check out [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
39
- * HMR is working with [Loadable Components](https://loadable-components.com) for a both amazing hot-reloading developer experience and great runtime performance. Please [email me](mailto:justin@shakacode.com) if you'd like to use [Loadable Components Code Splitting](https://loadable-components.com/docs/code-splitting/) to speed up your app by reducing your bundle sizes and lazily loading the code that's needed.
40
- ---
41
-
42
16
  #### About
43
17
  React on Rails integrates Rails with (server rendering of) Facebook's [React](https://github.com/facebook/react) front-end framework.
44
18
 
45
- This project is maintained by the software consulting firm [ShakaCode](https://www.shakacode.com). We focus on Ruby on Rails applications with React front-ends, often using TypeScript or ReasonML. We also build Gatsby sites. See [our recent work](https://www.shakacode.com/recent-work) for examples of what we do.
19
+ This project is maintained by the software consulting firm [ShakaCode](https://www.shakacode.com). We focus on Ruby on Rails applications with React front-ends, often using TypeScript or ReScript (ReasonML). We also build React Native apps and Gatsby sites. See [our recent work](https://www.shakacode.com/recent-work) for examples of what we do. ShakaCode.com (HiChee.com) is [hiring developers that like working on open-source](https://www.shakacode.com/career/).
46
20
 
47
21
  Interested in optimizing your webpack setup for React on Rails including code
48
- splitting with [react-router](https://github.com/ReactTraining/react-router#readme),
49
- and [loadable-components](https://loadable-components.com/) with server-side rendering?
50
- We just did this for Popmenu, [lowering Heroku costs 20-25% while getting a 73% decrease in average response times](https://www.shakacode.com/recent-work/popmenu/).
22
+ splitting with [react-router](https://github.com/ReactTraining/react-router#readme) and
23
+ and [loadable-components](https://loadable-components.com/) with server-side rendering for SEO and hot-reloading for developers?
24
+ We did this for Popmenu, [lowering Heroku costs 20-25% while getting a 73% decrease in average response times](https://www.shakacode.com/recent-work/popmenu/). Check out [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/).
51
25
 
52
26
  Feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com), maintainer of React on Rails, for more information.
53
27
 
54
- [Click to join **React + Rails Slack**](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
28
+ # Documentation
55
29
 
56
- # Intro
30
+ See the documentation at [shakacode.com/react-on-rails/docs](https://www.shakacode.com/react-on-rails/docs/).
57
31
 
58
32
  ## Project Objective
59
33
 
@@ -67,11 +41,11 @@ Given that `rails/webpacker` gem already provides basic React integration, why w
67
41
  1. Tight integration with [rails/webpacker](https://github.com/rails/webpacker).
68
42
  1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance, is not offered by `rails/webpacker`.
69
43
  1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/ReactTraining/react-router#readme) integration with server-side-rendering.
70
- 1. [Internationalization (I18n) and (localization)](https://www.shakacode.com/react-on-rails/docs/basics/i18n)
44
+ 1. [Internationalization (I18n) and (localization)](https://www.shakacode.com/react-on-rails/docs/guides/i18n)
71
45
  1. A supportive community. This [web search shows how live public sites are using React on Rails](https://publicwww.com/websites/%22react-on-rails%22++-undeveloped.com+depth%3Aall/).
72
46
  1. [Reason ML Support](https://github.com/shakacode/reason-react-on-rails-example).
73
47
 
74
- See [Rails/Webpacker React Integration Options](./docs/rails-webpacker-react-integration-options.md) for comparisons to other gems.
48
+ See [Rails/Webpacker React Integration Options](https://www.shakacode.com/react-on-rails/docs/guides/rails-webpacker-react-integration-options) for comparisons to other gems.
75
49
 
76
50
  See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
77
51
 
@@ -81,228 +55,18 @@ _Requires creating a free account._
81
55
  * [How to use different versions of a file for client and server rendering](https://forum.shakacode.com/t/how-to-use-different-versions-of-a-file-for-client-and-server-rendering/1352)
82
56
  * [How to conditionally render server side based on the device type](https://forum.shakacode.com/t/how-to-conditionally-render-server-side-based-on-the-device-type/1473)
83
57
 
84
- ----
85
-
86
- # Docs
87
-
88
- **Consider browsing this on our [website](https://www.shakacode.com/react-on-rails/docs/).**
89
58
 
90
59
  ## Prerequisites
91
60
 
92
61
  Ruby on Rails >=5 and rails/webpacker 4.2+.
93
62
 
94
- ## Getting Started
95
-
96
- Note, the best way to understand how to use ReactOnRails is to study a few simple examples. You can do a quick demo setup, either on your existing app or on a new Rails app.
97
-
98
- 1. Do the quick [tutorial](https://www.shakacode.com/react-on-rails/docs/basics/tutorial).
99
- 2. Add React on Rails to an existing Rails app per [the instructions](https://www.shakacode.com/react-on-rails/docs/basics/installation-into-an-existing-rails-app).
100
- 3. Look at [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy), a simple, no DB example.
101
- 3. Look at [github.com/shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial); it's a full-featured example live at [www.reactrails.com](http://www.reactrails.com).
102
-
103
- ## Basic Installation
104
-
105
- *See also [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/basics/installation-into-an-existing-rails-app).*
106
-
107
- 2. Add the `react_on_rails` gem to Gemfile:
108
-
109
- ```bash
110
- bundle add react_on_rails --strict
111
- ```
112
-
113
- 4. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
114
-
115
- 5. Run the generator:
116
-
117
- ```bash
118
- rails generate react_on_rails:install
119
- ```
120
-
121
- 6. Start the app:
122
-
123
- ```bash
124
- rails s
125
- ```
126
-
127
- 7. Visit http://localhost:3000/hello_world.
128
-
129
-
130
- ### Turning on server rendering
131
-
132
- With the code from running the React on Rails generator above:
133
-
134
- 1. Edit `app/views/hello_world/index.html.erb` and set `prerender` to `true`.
135
- 2. Refresh the page.
136
-
137
- Below is the line where you turn server rendering on by setting `prerender` to true:
138
-
139
- ```erb
140
- <%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %>
141
- ```
142
-
143
- Note, if you got an error in your console regarding "ReferenceError: window is not defined",
144
- then you need to edit `config/webpacker.yml` and set `hmr: false` and `inline: false`.
145
- See [rails/webpacker PR 2644](https://github.com/rails/webpacker/pull/2644) for a fix for this
146
- issue.
147
-
148
- ## Basic Usage
149
-
150
- ### Configuration
151
-
152
- * Configure `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [docs/basics/configuration.md](https://www.shakacode.com/react-on-rails/docs/basics/configuration) for documentation of all configuration options.
153
- * Configure `config/webpacker.yml`. If you used the generator and the default webpacker setup, you don't need to touch this file. If you are customizing your setup, then consult the [spec/dummy/config/webpacker.yml](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/webpacker.yml) example or the official default [webpacker.yml](https://github.com/rails/webpacker/blob/master/lib/install/config/webpacker.yml).
154
- * Tip: set `compile: false` for development if you know that you'll always be compiling with a watch process. Otherwise, every request will check if compilation is needed.
155
- * Your `public_output_path` must match your custom Webpack configuration for `output` of your bundles.
156
- * Only set `cache_manifest` to `true` in your production env.
157
-
158
- ## Including your React Component on your Rails Views
159
-
160
- - React component are rendered via your Rails Views. Here's an ERB sample:
161
-
162
- ```erb
163
- <%= react_component("HelloWorld", props: @some_props) %>
164
- ```
165
-
166
- - **Server-Side Rendering**: Your react component is first rendered into HTML on the server. Use the **prerender** option:
167
-
168
- ```erb
169
- <%= react_component("HelloWorld", props: @some_props, prerender: true) %>
170
- ```
171
-
172
- - The `component_name` parameter is a string matching the name you used to expose your React component globally. So, in the above examples, if you had a React component named "HelloWorld", you would register it with the following lines:
173
-
174
- ```js
175
- import ReactOnRails from 'react-on-rails';
176
- import HelloWorld from './HelloWorld';
177
- ReactOnRails.register({ HelloWorld });
178
- ```
179
-
180
- Exposing your component in this way is how React on Rails is able to reference your component from a Rails view. You can expose as many components as you like, as long as their names do not collide. See below for the details of how you expose your components via the react_on_rails webpack configuration. You may call `ReactOnRails.register` many times.
181
-
182
- - `@some_props` can be either a hash or JSON string. This is an optional argument assuming you do not need to pass any options (if you want to pass options, such as `prerender: true`, but you do not want to pass any properties, simply pass an empty hash `{}`). This will make the data available in your component:
183
-
184
- ```ruby
185
- # Rails View
186
- <%= react_component("HelloWorld", props: { name: "Stranger" }) %>
187
- ```
188
-
189
- - This is what your HelloWorld.js file might contain. The railsContext is always available for any parameters that you _always_ want available for your React components. It has _nothing_ to do with the concept of the [React Context](https://reactjs.org/docs/context.html). See [Render-Functions and the RailsContext](https://www.shakacode.com/react-on-rails/docs/basics/render-functions-and-railscontext) for more details on this topic.
190
-
191
- ```js
192
- import React from 'react';
193
-
194
- export default (props, railsContext) => {
195
- // Note wrap in a function to make this a React function component
196
- return () => (
197
- <div>
198
- Your locale is {railsContext.i18nLocale}.<br/>
199
- Hello, {props.name}!
200
- </div>
201
- );
202
- };
203
- ```
204
-
205
- See the [View Helpers API](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api) for more details on `react_component` and its sibling function `react_component_hash`.
206
-
207
- ## Globally Exposing Your React Components
208
-
209
- For the React on Rails view helper `react_component` to use your React components, you will have to **register** them in your JavaScript code.
210
-
211
- Use modules just as you would when using Webpack and React without Rails. The difference is that instead of mounting React components directly to an element using `React.render`, you **register your components to ReactOnRails and then mount them with helpers inside of your Rails views**.
212
-
213
- This is how to expose a component to the `react_component` view helper.
214
-
215
- ```javascript
216
- // app/javascript/packs/hello-world-bundle.js
217
- import HelloWorld from '../components/HelloWorld';
218
- import ReactOnRails from 'react-on-rails';
219
- ReactOnRails.register({ HelloWorld });
220
- ```
221
-
222
- #### Different Server-Side Rendering Code (and a Server-Specific Bundle)
223
-
224
- You may want different code for your server-rendered components running server side versus client side. For example, if you have an animation that runs when a component is displayed, you might need to turn that off when server rendering. One way to handle this is conditional code like `if (window) { doClientOnlyCode() }`.
225
-
226
- Another way is to use a separate webpack configuration file that can use a different server side entry file, like 'serverRegistration.js' as opposed to 'clientRegistration.js.' That would set up different code for server rendering.
227
-
228
- For details on techniques to use different code for client and server rendering, see: [How to use different versions of a file for client and server rendering](https://forum.shakacode.com/t/how-to-use-different-versions-of-a-file-for-client-and-server-rendering/1352). (_Requires creating a free account._)
229
-
230
- ## Specifying Your React Components: Register directly or use render-functions
231
-
232
- You have two ways to specify your React components. You can either register the React component (either function or class component) directly, or you can create a function that returns a React component, which we using the name of a "render-function". Creating a render-function allows:
233
-
234
- 1. You to have access to the `railsContext`. See [documentation for the railsContext](https://www.shakacode.com/react-on-rails/docs/basics/render-functions-and-railscontext) in terms of why you might need it. You **need** a Render-Function to access the `railsContext`.
235
- 2. You can use the passed-in props to initialize a redux store or set up react-router.
236
- 3. You can return different components depending on what's in the props.
237
-
238
- Note, the return value of a **Render-Function** should be either a React Function or Class Component, or an object representing server rendering results.
239
-
240
- Do not return a React Element (JSX).
241
-
242
- ReactOnRails will automatically detect a registered Render-Function by the fact that the function takes
243
- more than 1 parameter. In other words, if you want the ability to provide a function that returns the
244
- React component, then you need to specify at least a second parameter. This is the `railsContext`.
245
- If you're not using this parameter, declare your function with the unused param:
246
-
247
- ```js
248
- const MyComponentGenerator = (props, _railsContext) => {
249
- if (props.print) {
250
- // This is a React FunctionComponent because it is wrapped in a function.
251
- return () => <H1>{JSON.stringify(props)}</H1>;
252
- }
253
- }
254
- ```
255
-
256
- Thus, there is no difference between registering a React Function Component or class Component versus a "Render-Function." Just call `ReactOnRails.register`.
257
-
258
- ## react_component_hash for Render-Functions
259
-
260
- Another reason to use a Render-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 }. Make sure you use this function with `react_component_hash`.
261
-
262
- For server rendering, if you wish to return multiple HTML strings from a Render-Function, you may return an Object from your Render-Function with a single top-level property of `renderedHtml`. Inside this Object, place a key called `componentHtml`, along with any other needed keys. An example scenario of this is when you are using side effects libraries like [React Helmet](https://github.com/nfl/react-helmet). Your Ruby code will get this Object as a Hash containing keys componentHtml and any other custom keys that you added:
263
-
264
- ```js
265
- { renderedHtml: { componentHtml, customKey1, customKey2} }
266
- ```
267
-
268
- For details on using react_component_hash with react-helmet, see [our react-helmet documentation](https://www.shakacode.com/react-on-rails/docs/additional-reading/react-helmet).
269
-
270
- ## Error Handling
271
-
272
- * All errors from ReactOnRails will be of type ReactOnRails::Error.
273
- * Prerendering (server rendering) errors get context information for HoneyBadger and Sentry for easier debugging.
274
-
275
- ## I18n
276
-
277
- React on Rails provides an option for automatic conversions of Rails `*.yml` locale files into `*.json` or `*.js*.
278
- See the [How to add I18n](https://www.shakacode.com/react-on-rails/docs/basics/i18n) for a summary of adding I18n.
279
-
280
- ## More Details
281
-
282
- Browse the links in the [Summary Table of Contents](https://github.com/shakacode/react_on_rails/tree/master/SUMMARY.md)
283
-
284
- Here are some highly recommended next articles to read:
285
-
286
- 1. [How React on Rails Works](https://www.shakacode.com/react-on-rails/docs/basics/how-react-on-rails-works)
287
- 1. [Webpack Configuration](https://www.shakacode.com/react-on-rails/docs/basics/webpack-configuration)
288
- 1. [View Helpers API](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api)
289
- 1. [Caching and Performance: React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
290
- 1. [Deployment](https://www.shakacode.com/react-on-rails/docs/basics/deployment).
291
-
292
63
  # Support
293
64
 
294
- [Click to join **React + Rails Slack**](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
295
-
296
- ## Community Resources
297
-
298
- Please [**click to subscribe**](https://app.mailerlite.com/webforms/landing/l1d9x5) to keep in touch with Justin Gordon and [ShakaCode](http://www.shakacode.com/). I intend to send announcements of new releases of React on Rails and of our latest [blog articles](https://blog.shakacode.com) and tutorials.
299
-
300
- [![2017-01-31_14-16-56](https://cloud.githubusercontent.com/assets/1118459/22490211/f7a70418-e7bf-11e6-9bef-b3ccd715dbf8.png)](https://app.mailerlite.com/webforms/landing/l1d9x5)
301
-
302
- - **Slack Room**: [Contact us](mailto:contact@shakacode.com) for an invite to the ShakaCode Slack room! Let us know if you want to contribute.
65
+ * [Click to join **React + Rails Slack**](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
66
+ - [**Subscribe**](https://app.mailerlite.com/webforms/landing/l1d9x5) for announcements of new releases of React on Rails and of our latest [blog articles](https://blog.shakacode.com) and tutorials.
303
67
  - **[forum.shakacode.com](https://forum.shakacode.com)**: Post your questions
304
68
  - **[@railsonmaui on Twitter](https://twitter.com/railsonmaui)**
305
- - For a live, [open source](https://github.com/shakacode/react-webpack-rails-tutorial), example of this gem, see [www.reactrails.com](http://www.reactrails.com).
69
+ - *See [NEWS.md](https://github.com/shakacode/react_on_rails/tree/master/NEWS.md) for more notes over time.*
306
70
  - See [Projects](https://github.com/shakacode/react_on_rails/tree/master/PROJECTS.md) using and [KUDOS](https://github.com/shakacode/react_on_rails/tree/master/KUDOS.md) for React on Rails. Please submit yours! Please edit either page or [email us](mailto:contact@shakacode.com) and we'll add your info. We also **love stars** as it helps us attract new users and contributors.
307
71
  - *See [NEWS.md](https://github.com/shakacode/react_on_rails/tree/master/NEWS.md) for more notes over time.*
308
72
 
@@ -310,66 +74,6 @@ Please [**click to subscribe**](https://app.mailerlite.com/webforms/landing/l1d9
310
74
 
311
75
  Bug reports and pull requests are welcome. See [Contributing](https://github.com/shakacode/react_on_rails/tree/master/CONTRIBUTING.md) to get started, and the [list of help wanted issues](https://github.com/shakacode/react_on_rails/labels/contributions%3A%20up%20for%20grabs%21).
312
76
 
313
- ## React on Rails Pro
314
-
315
- Support React on Rails Pro development [by becoming a Github sponsor](https://github.com/sponsors/shakacode) and get these benefits.
316
-
317
- React on Rails Pro includes Node server rendering, fragment caching, code-splitting, and other performance enhancements for React on Rails. For a case study, see the article [HVMN’s 90% Reduction in Server Response Time from React on Rails Pro](https://www.shakacode.com/blog/hvmns-90-reduction-in-server-response-time-from-react-on-rails-pro/). The [Wiki](https://github.com/shakacode/react_on_rails/wiki) contains more details.
318
-
319
- [![2018-09-11_10-31-11](https://user-images.githubusercontent.com/1118459/45467845-5bcc7400-b6bd-11e8-91e1-e0cf806d4ea4.png)](https://blog.shakacode.com/hvmns-90-reduction-in-server-response-time-from-react-on-rails-pro-eb08226687db)
320
-
321
- The [React on Rails Pro Support Plan](https://www.shakacode.com/react-on-rails-pro) can help!
322
-
323
- * Optimizing your webpack setup to the latest Webpack for React on Rails including code splitting with loadable-components.
324
- * Upgrading your app to use the current `rails/webpacker` setup that skips the Sprockets asset pipeline.
325
- * Better performance client and server side.
326
- * Best practices based on over 6 years of React on Rails experience on many production projects.
327
- * Using [Reason](https://reasonml.github.io/) with (or without) React on Rails.
328
-
329
- ShakaCode can also help you with your custom software development needs. We specialize in marketplace and e-commerce applications that utilize both Rails and React. Because we own [HiChee.com](https://hichee.com), we can leverage that code for your app!
330
-
331
- Please email Justin Gordon [justin@shakacode.com](mailto:justin@shakacode.com), the maintainer of React on Rails, for more information.
332
-
333
- ### Pro: Fragment Caching
334
-
335
- Fragment caching is a [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro) feature. Fragment caching is a **HUGE** performance booster for your apps. Use the `cached_react_component` and `cached_react_component_hash`. The API is the same as `react_component` and `react_component_hash`, but for 2 differences:
336
-
337
- 1. The `cache_key` takes the same parameters as any Rails `cache` view helper.
338
- 1. The **props** are passed via a block so that evaluation of the props is not done unless the cache is broken. Suppose you put your props calculation into some method called `some_slow_method_that_returns_props`:
339
-
340
- ```ruby
341
- <%= cached_react_component("App", cache_key: [@user, @post], prerender: true) do
342
- some_slow_method_that_returns_props
343
- end %>
344
- ```
345
-
346
- Such fragment caching saves CPU work for your web server and greatly reduces the request time. It completely skips the evaluation costs of:
347
-
348
- 1. Database calls to compute the props.
349
- 2. Serialization the props values hash into a JSON string for evaluating JavaScript to server render.
350
- 3. Costs associated with evaluating JavaScript from your Ruby code.
351
- 4. Creating the HTML string containing the props and the server-rendered JavaScript code.
352
-
353
- Note, even without server rendering (without step 3 above), fragment caching is still effective.
354
-
355
- ### Pro: Integration with Node.js for Server Rendering
356
-
357
- Default server rendering is done by ExecJS. If you want to use a Node.js server for better performing server rendering, [email justin@shakacode.com](mailto:justin@shakacode.com). ShakaCode has built a premium Node rendering server that is part of [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
358
-
359
- ## Testimonials for ShakaCode
360
- [HVMN Testimonial, by Paul Benigeri, October 12, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn)
361
- > The price we paid for the consultation + the React on Rails pro license has already been made back a couple of times from hosting fees alone. The entire process was super hands off, and our core team was able to focus on shipping new feature during that sprint.
362
-
363
- [ResortPass Testimonial, by Leora Juster, December 10, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass)
364
-
365
- > Justin and his team were instrumental in assisting us in setting design foundations and standards for our transition to a react on rails application. Just three months of work with the team at Shaka code and we have a main page of our application server-side rendering at exponentially improved speeds.
366
-
367
- From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), January 30, 2017:
368
-
369
- ![2017-01-30_11-33-59](https://cloud.githubusercontent.com/assets/1118459/22443635/b3549fb4-e6e3-11e6-8ea2-6f589dc93ed3.png)
370
-
371
- For more testimonials, see [Live Projects](https://github.com/shakacode/react_on_rails/tree/master/PROJECTS.md) and [Kudos](https://github.com/shakacode/react_on_rails/tree/master/KUDOS.md).
372
-
373
77
  # Supporters
374
78
 
375
79
  The following companies support this open source project, and ShakaCode uses their products! Justin writes React on Rails on [RubyMine](https://www.jetbrains.com/ruby/). We use [Scout](https://scoutapp.com/) to monitor the live performance of [HiChee.com](https://HiChee.com), [Rails AutoScale](https://railsautoscale.com) to scale the dynos of HiChee, and [HoneyBadger](https://www.honeybadger.io/) to monitor application errors. We love [BrowserStack](https://www.browserstack.com) to solve problems with oddball browsers. [Status Hero](https://statushero.com/) keeps the team posted on daily progress; it's so much better than live standups.
@@ -386,7 +90,7 @@ ShakaCode's favorite project tracking tool is [ClubHouse](https://clubhouse.io/)
386
90
  Aloha and best wishes from Justin and the ShakaCode team!
387
91
 
388
92
  # Work with Us
389
- ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/career)** to work on our projects, including [HiChee](https://hichee.com).
93
+ ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/career)** to work on our projects, including [HiChee](https://hichee.com).
390
94
 
391
95
  # License
392
96
 
data/SUMMARY.md CHANGED
@@ -4,17 +4,17 @@
4
4
 
5
5
  ## **Basics**
6
6
  + [React on Rails Basic Installation Tutorial](./docs/tutorial.md)
7
- + [Webpack Configuration](./docs/basics/webpack-configuration.md)
7
+ + [Webpack Configuration](./docs/guides/webpack-configuration.md)
8
8
  + [How React on Rails Works](docs/outdated/how-react-on-rails-works.md)
9
- + [Client vs. Server Rendering](./docs/basics/client-vs-server-rendering.md)
10
- + [React Server Rendering](./docs/basics/react-server-rendering.md)
11
- + [Render-Functions and the RailsContext](docs/basics/render-functions-and-railscontext.md)
9
+ + [Client vs. Server Rendering](./docs/guides/client-vs-server-rendering.md)
10
+ + [React Server Rendering](./docs/guides/react-server-rendering.md)
11
+ + [Render-Functions and the RailsContext](docs/guides/render-functions-and-railscontext.md)
12
12
  + [Caching and Performance: React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki).
13
- + [Deployment](docs/basics/deployment.md).
14
- + [React on Rails Internationalization (I18n, localization)](docs/basics/i18n.md)
15
- + [RSpec Test Helpers Configuration](docs/basics/rspec-configuration.md)
16
- + [Minitest Configuration](docs/basics/minitest-configuration.md)
17
- + [Upgrading React on Rails](docs/basics/upgrading-react-on-rails.md)
13
+ + [Deployment](docs/guides/deployment.md).
14
+ + [React on Rails Internationalization (I18n, localization)](docs/guides/i18n.md)
15
+ + [RSpec Test Helpers Configuration](docs/guides/rspec-configuration.md)
16
+ + [Minitest Configuration](docs/guides/minitest-configuration.md)
17
+ + [Upgrading React on Rails](docs/guides/upgrading-react-on-rails.md)
18
18
 
19
19
  ## **API**
20
20
  - [View Helpers API](./docs/api/view-helpers-api.md)
@@ -22,8 +22,8 @@
22
22
  - [Redux Store API](./docs/api/redux-store-api.md)
23
23
 
24
24
  ## **Additional Details**
25
- + [Migration from react-rails](./docs/basics/migrating-from-react-rails.md)
26
- + [Generator Details](docs/basics/generator-details.md)
25
+ + [Migration from react-rails](./docs/guides/migrating-from-react-rails.md)
26
+ + [Generator Details](docs/guides/generator-details.md)
27
27
  + [Updating Dependencies](./docs/additional-reading/updating-dependencies.md)
28
28
  + [Manual Installation Overview](docs/outdated/manual-installation-overview.md)
29
29
  + [Upgrading from rails/webpacker v3 to v4](docs/additional-reading/upgrade-webpacker-v3-to-v4.md)
@@ -45,7 +45,7 @@
45
45
  + [AngularJS Integration and Migration to React on Rails](./docs/additional-reading/angular-js-integration-migration.md)
46
46
 
47
47
  ## **Deployment**
48
- + [Heroku Deployment](docs/basics/heroku-deployment.md)
48
+ + [Heroku Deployment](docs/guides/heroku-deployment.md)
49
49
  + [Elastic Beanstalk Deployment](./docs/additional-reading/elastic-beanstalk.md)
50
50
 
51
51
  ## Outdated Non-Webpack Docs
@@ -37,7 +37,7 @@ Then you may run
37
37
  `rails s`
38
38
  ```
39
39
 
40
- Another good option is to create a simple test app per the [Tutorial](https://www.shakacode.com/react-on-rails/docs/basics/tutorial).
40
+ Another good option is to create a simple test app per the [Tutorial](https://www.shakacode.com/react-on-rails/docs/guides/tutorial/).
41
41
 
42
42
  # Understanding the Organization of the Generated Client Code
43
43
  The generated client code follows our organization scheme. Each unique set of functionality, is given its own folder inside of `app/javascript/app/bundles`. Note, the recommended for bigger projects is `client/app/bundles`. This encourages for modularity of *domains*.
@@ -14,7 +14,7 @@ The only requirements within this directory for basic React on Rails integration
14
14
  1. Your webpack configuration files:
15
15
  1. Create outputs in a directory like `/public/webpack`, which is customizable in your `config/initializers/react_on_rails.rb`.
16
16
  1. Provide server rendering if you wish to use that feature.
17
- 1. Your JavaScript code "registers" any components and stores per the ReactOnRails APIs of ReactOnRails.register(components) and ReactOnRails.registerStore(stores). See [our javascript API docs](https://www.shakacode.com/react-on-rails/docs/api/javascript-api) and the [ReactOnRails.js source](https://github.com/shakacode/react_on_rails/tree/master/node_package/src/ReactOnRails.js).
17
+ 1. Your JavaScript code "registers" any components and stores per the ReactOnRails APIs of ReactOnRails.register(components) and ReactOnRails.registerStore(stores). See [our javascript API docs](https://www.shakacode.com/react-on-rails/docs/api/javascript-api/) and the [ReactOnRails.js source](https://github.com/shakacode/react_on_rails/tree/master/node_package/src/ReactOnRails.js).
18
18
  1. Set your registration file as an "entry" point in your Webpack configs.
19
19
  1. Add the [Manifest plugin](https://github.com/danethurber/webpack-manifest-plugin) to your config.
20
20
  The default path: `public/webpack` can be loaded with webpackConfigLoader as shown in the dummy example.
@@ -25,6 +25,6 @@ The default path: `public/webpack` can be loaded with webpackConfigLoader as sho
25
25
  1. Configure the `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/initializers/react_on_rails.rb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/initializers/react_on_rails.rb) for a detailed example of configuration, including comments on the different values to configure.
26
26
  1. Configure your Procfiles per the example apps. These are at the root of your Rails installation.
27
27
  1. Configure your top level JavaScript files for inclusion in your layout. You'll want a version that you use for static assets, and you want a file for any files in your setup that are not part of your webpack build. The reason for this is for use with hot-reloading. If you are not using hot reloading, then you only need to configure your `application.js` file to include your Webpack generated files.
28
- 1. If you are deploying to Heroku, see [our heroku deployment documentation](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment)
28
+ 1. If you are deploying to Heroku, see [our heroku deployment documentation](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment/)
29
29
 
30
30
  If I missed anything, please submit a PR or file an issue.
@@ -23,7 +23,7 @@ Uncommonly used options:
23
23
  ```
24
24
 
25
25
  - **component_name:** Can be a React component, created using a React Function Component, 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). Note, a "renderer function" is a special type of "Render-Function." A "renderer function" takes a 3rd param of a DOM ID.
26
- All options except `props, id, html_options` will inherit from your `react_on_rails.rb` initializer, as described [here](https://www.shakacode.com/react-on-rails/docs/basics/configuration).
26
+ All options except `props, id, html_options` will inherit from your `react_on_rails.rb` initializer, as described [here](https://www.shakacode.com/react-on-rails/docs/guides/configuration/).
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!
@@ -100,7 +100,7 @@ You can call `rails_context` or `rails_context(server_side: true|false)` from yo
100
100
 
101
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.
102
102
 
103
- Why would you want to call `ReactDOM.hydrate` yourself? One possible use case is [code splitting](https://www.shakacode.com/react-on-rails/docs/javascript/code-splitting). 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](https://www.shakacode.com/react-on-rails/docs/javascript/code-splitting/). 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.
104
104
 
105
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.
106
106
 
@@ -110,9 +110,9 @@ Renderer functions are not meant to be used on the server since there's no DOM o
110
110
 
111
111
  [React Router](https://github.com/reactjs/react-router) is supported, including server-side rendering! See:
112
112
 
113
- 1. [React on Rails docs for react-router](https://www.shakacode.com/react-on-rails/docs/javascript/react-router)
113
+ 1. [React on Rails docs for react-router](https://www.shakacode.com/react-on-rails/docs/javascript/react-router/)
114
114
  2. Examples in [spec/dummy/app/views/react_router](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/views/react_router) and follow to the JavaScript code in the [spec/dummy/client/app/startup/ServerRouterApp.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/startup/ServerRouterApp.jsx).
115
- 3. [Code Splitting docs](https://www.shakacode.com/react-on-rails/docs/javascript/code-splitting) for information about how to set up code splitting for server rendered routes.
115
+ 3. [Code Splitting docs](https://www.shakacode.com/react-on-rails/docs/javascript/code-splitting/) for information about how to set up code splitting for server rendered routes.
116
116
 
117
117
  ------------
118
118
 
@@ -1,5 +1,5 @@
1
1
  # Linters
2
- These linters support the [ShakaCode Style Guidelines](https://www.shakacode.com/react-on-rails/docs/misc/style)
2
+ These linters support the [ShakaCode Style Guidelines](https://www.shakacode.com/react-on-rails/docs/misc/style/)
3
3
 
4
4
  ## Autofix!
5
5
 
@@ -36,7 +36,7 @@ When making doc changes, we want the change to work on both the gitbook and the
36
36
 
37
37
  ### Links to other docs:
38
38
  * When making references to doc files, use a relative URL path like:
39
- `[Installation Overview](https://www.shakacode.com/react-on-rails/docs/additional-details/manual-installation-overview)`
39
+ `[Installation Overview](https://www.shakacode.com/react-on-rails/docs/additional-details/manual-installation-overview/)`
40
40
 
41
41
  * When making references to source code files, use a full url path like:
42
42
  `[spec/dummy/config/initializers/react_on_rails.rb](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/config/initializers/react_on_rails.rb)`
@@ -1,6 +1,6 @@
1
1
  # Client-Side Rendering vs. Server-Side Rendering
2
2
 
3
- *Also, see [our react server-rendering documentation](https://www.shakacode.com/react-on-rails/docs/basics/react-server-rendering).*
3
+ *Also, see [our react server-rendering documentation](https://www.shakacode.com/react-on-rails/docs/guides/react-server-rendering/).*
4
4
 
5
5
  In most cases, you should use the `prerender: false` (default behavior) with the provided helper method to render the React component from your Rails views. In some cases, such as when SEO is vital, or many users will not have JavaScript enabled, you can enable server-rendering by passing `prerender: true` to your helper, or you can simply change the default in `config/initializers/react_on_rails`.
6
6
 
File without changes
@@ -1,4 +1,4 @@
1
1
  # Deployment
2
2
 
3
3
  - `rails/webpacker` puts the necessary precompile steps automatically in the rake precompile step.
4
- - See the [Heroku Deployment](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment) doc for specifics regarding Heroku. The information for Heroku may apply to other deployments.
4
+ - See the [Heroku Deployment](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment/) doc for specifics regarding Heroku. The information for Heroku may apply to other deployments.