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/docs/home.md CHANGED
@@ -1,382 +1,23 @@
1
1
  # React on Rails
2
2
 
3
- *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).*
4
-
5
- **If you're viewing this page on Github, please go to [our documentation website](https://www.shakacode.com/react-on-rails/docs/) instead!**
6
-
7
- #### News
8
- **October 14, 2020**: [RUBY ROGUES
9
- 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/).
10
-
11
- **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
3
+ ## Details
4
+ 1. [Overview](https://www.shakacode.com/react-on-rails/docs/guides/react-on-rails-overview/)
5
+ 1. [Getting Started](https://www.shakacode.com/react-on-rails/docs/guides/getting-started/)
6
+ 1. [How React on Rails Works](https://www.shakacode.com/react-on-rails/docs/guides/how-react-on-rails-works/)
7
+ 1. [Webpack Configuration](https://www.shakacode.com/react-on-rails/docs/guides/webpack-configuration/)
8
+ 1. [View Helpers API](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/)
9
+ 1. [Caching and Performance: React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/).
10
+ 1. [Deployment](https://www.shakacode.com/react-on-rails/docs/guides/deployment/).
11
+
12
+ ## Changes and Upgrades
13
+ 1. [CHANGELOG.md](https://github.com/shakacode/react_on_rails/tree/master/CHANGELOG.md)
14
+ 2. [Upgrading React on Rails](https://www.shakacode.com/react-on-rails/docs/guides/upgrading-react-on-rails/#upgrading-to-v12).
15
+
16
+ ## Example Apps
17
+ 1. [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
12
18
  that supports SSR.
19
+ 2. 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`.
20
+ 3. Live, [open source](https://github.com/shakacode/react-webpack-rails-tutorial), example of this gem, see [reactrails.com](http://reactrails.com).
13
21
 
14
- **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`.
15
-
16
- **July 8, 2020**: Release v12 of React on Rails.
17
-
18
- **Major Improvements**
19
-
20
- 1. **React Hooks Support** for top level components
21
- 2. **Typescript bindings**
22
- 3. **rails/webpacker** "just works" with React on Rails by default.
23
- 4. i18n support for generating a JSON file rather than a JS file.
24
-
25
- Be sure to see the [CHANGELOG.md](https://github.com/shakacode/react_on_rails/tree/master/CHANGELOG.md) and read the upgrade instructions:
26
- [docs/basics/upgrading-react-on-rails](https://www.shakacode.com/react-on-rails/docs/basics/upgrading-react-on-rails#upgrading-to-v12).
27
-
28
- * See Justin's RailsConf talk: [Webpacker, It-Just-Works, But How?](http://railsconf.com/2020/video/justin-gordon-webpacker-it-just-works-but-how).
29
- * 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).
30
- * 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.
31
- ---
32
-
33
- #### About
34
- React on Rails integrates Rails with (server rendering of) Facebook's [React](https://github.com/facebook/react) front-end framework.
35
-
36
- 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.
37
-
38
- Interested in optimizing your webpack setup for React on Rails including code
39
- splitting with [react-router](https://github.com/ReactTraining/react-router#readme),
40
- and [loadable-components](https://loadable-components.com/) with server-side rendering?
41
- 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/).
42
-
43
- Feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com), maintainer of React on Rails, for more information.
44
-
45
- [Click to join **React + Rails Slack**](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
46
-
47
- # Intro
48
-
49
- ## Project Objective
50
-
51
- To provide a high performance framework for integrating Ruby on Rails with React via the [**Webpacker**](https://github.com/rails/webpacker) gem especially in regards to React Server-Side Rendering for better SEO and improved performance.
52
-
53
- ## Features and Why React on Rails?
54
-
55
- Given that `rails/webpacker` gem already provides basic React integration, why would you use "React on Rails"?
56
-
57
- 1. Easy passing of props directly from your Rails view to your React components rather than having your Rails view load and then make a separate request to your API.
58
- 1. Tight integration with [rails/webpacker](https://github.com/rails/webpacker).
59
- 1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance, is not offered by `rails/webpacker`.
60
- 1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/ReactTraining/react-router#readme) integration with server-side-rendering.
61
- 1. [Internationalization (I18n) and (localization)](https://www.shakacode.com/react-on-rails/docs/basics/i18n)
62
- 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/).
63
- 1. [Reason ML Support](https://github.com/shakacode/reason-react-on-rails-example).
64
-
65
- See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
66
-
67
- ## ShakaCode Forum Premium Content
68
- _Requires creating a free account._
69
-
70
- * [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)
71
-
72
- ----
73
-
74
- # Docs
75
-
76
- **Consider browsing this on our [website](https://www.shakacode.com/react-on-rails/docs/).**
77
-
78
- ## Prerequisites
79
-
80
- Ruby on Rails >=5 and rails/webpacker 4.2+.
81
-
82
- ## Getting Started
83
-
84
- 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.
85
-
86
- 1. Do the quick [tutorial](https://www.shakacode.com/react-on-rails/docs/basics/tutorial).
87
- 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).
88
- 3. Look at [spec/dummy](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy), a simple, no DB example.
89
- 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).
90
-
91
- ## Basic Installation
92
-
93
- *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).*
94
-
95
- 2. Add the `react_on_rails` gem to Gemfile:
96
-
97
- ```bash
98
- bundle add react_on_rails --strict
99
- ```
100
-
101
- 4. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
102
-
103
- 5. Run the generator:
104
-
105
- ```bash
106
- rails generate react_on_rails:install
107
- ```
108
-
109
- 6. Start the app:
110
-
111
- ```bash
112
- rails s
113
- ```
114
-
115
- 7. Visit http://localhost:3000/hello_world.
116
-
117
-
118
- ### Turning on server rendering
119
-
120
- With the code from running the React on Rails generator above:
121
-
122
- 1. Edit `app/views/hello_world/index.html.erb` and set `prerender` to `true`.
123
- 2. Refresh the page.
124
-
125
- Below is the line where you turn server rendering on by setting `prerender` to true:
126
-
127
- ```erb
128
- <%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %>
129
- ```
130
-
131
- Note, if you got an error in your console regarding "ReferenceError: window is not defined",
132
- then you need to edit `config/webpacker.yml` and set `hmr: false` and `inline: false`.
133
- See [rails/webpacker PR 2644](https://github.com/rails/webpacker/pull/2644) for a fix for this
134
- issue.
135
-
136
- ## Basic Usage
137
-
138
- ### Configuration
139
-
140
- * 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.
141
- * 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).
142
- * 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.
143
- * Your `public_output_path` must match your custom Webpack configuration for `output` of your bundles.
144
- * Only set `cache_manifest` to `true` in your production env.
145
-
146
- ## Including your React Component on your Rails Views
147
-
148
- - React component are rendered via your Rails Views. Here's an ERB sample:
149
-
150
- ```erb
151
- <%= react_component("HelloWorld", props: @some_props) %>
152
- ```
153
-
154
- - **Server-Side Rendering**: Your react component is first rendered into HTML on the server. Use the **prerender** option:
155
-
156
- ```erb
157
- <%= react_component("HelloWorld", props: @some_props, prerender: true) %>
158
- ```
159
-
160
- - 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:
161
-
162
- ```js
163
- import ReactOnRails from 'react-on-rails';
164
- import HelloWorld from './HelloWorld';
165
- ReactOnRails.register({ HelloWorld });
166
- ```
167
-
168
- 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.
169
-
170
- - `@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:
171
-
172
- ```ruby
173
- # Rails View
174
- <%= react_component("HelloWorld", props: { name: "Stranger" }) %>
175
- ```
176
-
177
- - 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.
178
-
179
- ```js
180
- import React from 'react';
181
-
182
- export default (props, railsContext) => {
183
- // Note wrap in a function to make this a React function component
184
- return () => (
185
- <div>
186
- Your locale is {railsContext.i18nLocale}.<br/>
187
- Hello, {props.name}!
188
- </div>
189
- );
190
- };
191
- ```
192
-
193
- 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`.
194
-
195
- ## Globally Exposing Your React Components
196
-
197
- For the React on Rails view helper `react_component` to use your React components, you will have to **register** them in your JavaScript code.
198
-
199
- 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**.
200
-
201
- This is how to expose a component to the `react_component` view helper.
202
-
203
- ```javascript
204
- // app/javascript/packs/hello-world-bundle.js
205
- import HelloWorld from '../components/HelloWorld';
206
- import ReactOnRails from 'react-on-rails';
207
- ReactOnRails.register({ HelloWorld });
208
- ```
209
-
210
- #### Different Server-Side Rendering Code (and a Server-Specific Bundle)
211
-
212
- 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() }`.
213
-
214
- 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.
215
-
216
- 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._)
217
-
218
- ## Specifying Your React Components: Register directly or use render-functions
219
-
220
- 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:
221
-
222
- 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`.
223
- 2. You can use the passed-in props to initialize a redux store or set up react-router.
224
- 3. You can return different components depending on what's in the props.
225
-
226
- Note, the return value of a **Render-Function** should be either a React Function or Class Component, or an object representing server rendering results.
227
-
228
- Do not return a React Element (JSX).
229
-
230
- ReactOnRails will automatically detect a registered Render-Function by the fact that the function takes
231
- more than 1 parameter. In other words, if you want the ability to provide a function that returns the
232
- React component, then you need to specify at least a second parameter. This is the `railsContext`.
233
- If you're not using this parameter, declare your function with the unused param:
234
-
235
- ```js
236
- const MyComponentGenerator = (props, _railsContext) => {
237
- if (props.print) {
238
- // This is a React FunctionComponent because it is wrapped in a function.
239
- return () => <H1>{JSON.stringify(props)}</H1>;
240
- }
241
- }
242
- ```
243
-
244
- Thus, there is no difference between registering a React Function Component or class Component versus a "Render-Function." Just call `ReactOnRails.register`.
245
-
246
- ## react_component_hash for Render-Functions
247
-
248
- 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`.
249
-
250
- 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:
251
-
252
- ```js
253
- { renderedHtml: { componentHtml, customKey1, customKey2} }
254
- ```
255
-
256
- 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).
257
-
258
- ## Error Handling
259
-
260
- * All errors from ReactOnRails will be of type ReactOnRails::Error.
261
- * Prerendering (server rendering) errors get context information for HoneyBadger and Sentry for easier debugging.
262
-
263
- ## I18n
264
-
265
- React on Rails provides an option for automatic conversions of Rails `*.yml` locale files into `*.json` or `*.js*.
266
- See the [How to add I18n](https://www.shakacode.com/react-on-rails/docs/basics/i18n) for a summary of adding I18n.
267
-
268
- ## More Details
269
-
270
- Browse the links in the [Summary Table of Contents](https://github.com/shakacode/react_on_rails/tree/master/SUMMARY.md)
271
-
272
- Here are some highly recommended next articles to read:
273
-
274
- 1. [How React on Rails Works](https://www.shakacode.com/react-on-rails/docs/basics/how-react-on-rails-works)
275
- 1. [Webpack Configuration](https://www.shakacode.com/react-on-rails/docs/basics/webpack-configuration)
276
- 1. [View Helpers API](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api)
277
- 1. [Caching and Performance: React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
278
- 1. [Deployment](https://www.shakacode.com/react-on-rails/docs/basics/deployment).
279
-
280
- # Support
281
-
282
- [Click to join **React + Rails Slack**](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
283
-
284
- ## Community Resources
285
-
286
- 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.
287
-
288
- [![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)
289
-
290
- - **Slack Room**: [Contact us](mailto:contact@shakacode.com) for an invite to the ShakaCode Slack room! Let us know if you want to contribute.
291
- - **[forum.shakacode.com](https://forum.shakacode.com)**: Post your questions
292
- - **[@railsonmaui on Twitter](https://twitter.com/railsonmaui)**
293
- - 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).
294
- - 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.
295
- - *See [NEWS.md](https://github.com/shakacode/react_on_rails/tree/master/NEWS.md) for more notes over time.*
296
-
297
- ## Contributing
298
-
299
- 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).
300
-
301
- ## React on Rails Pro
302
-
303
- React on Rails Pro provides 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://blog.shakacode.com/hvmns-90-reduction-in-server-response-time-from-react-on-rails-pro-eb08226687db). The [Wiki](https://github.com/shakacode/react_on_rails/wiki) contains more details.
304
-
305
- [![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)
306
-
307
- ## React on Rails Pro Support
308
-
309
- The [React on Rails Pro Support Plan](https://www.shakacode.com/react-on-rails-pro) can help!
310
-
311
- * Optimizing your webpack setup to the latest Webpack for React on Rails including code splitting with loadable-components.
312
- * Upgrading your app to use the current `rails/webpacker` setup that skips the Sprockets asset pipeline.
313
- * Better performance client and server side.
314
- * Best practices based on over 6 years of React on Rails experience on many production projects.
315
- * Using [Reason](https://reasonml.github.io/) with (or without) React on Rails.
316
-
317
- 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!
318
-
319
- Please email Justin Gordon [justin@shakacode.com](mailto:justin@shakacode.com), the maintainer of React on Rails, for more information.
320
-
321
- ### Fragment Caching
322
-
323
- 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:
324
-
325
- 1. The `cache_key` takes the same parameters as any Rails `cache` view helper.
326
- 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`:
327
-
328
- ```ruby
329
- <%= cached_react_component("App", cache_key: [@user, @post], prerender: true) do
330
- some_slow_method_that_returns_props
331
- end %>
332
- ```
333
-
334
- Such fragment caching saves CPU work for your web server and greatly reduces the request time. It completely skips the evaluation costs of:
335
-
336
- 1. Database calls to compute the props.
337
- 2. Serialization the props values hash into a JSON string for evaluating JavaScript to server render.
338
- 3. Costs associated with evaluating JavaScript from your Ruby code.
339
- 4. Creating the HTML string containing the props and the server-rendered JavaScript code.
340
-
341
- Note, even without server rendering (without step 3 above), fragment caching is still effective.
342
-
343
- ## Integration with Node.js for Server Rendering
344
-
345
- 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).
346
-
347
- ## Testimonials for ShakaCode
348
- [HVMN Testimonial, by Paul Benigeri, October 12, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn)
349
- > 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.
350
-
351
- [ResortPass Testimonial, by Leora Juster, December 10, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass)
352
-
353
- > 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.
354
-
355
- From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), January 30, 2017:
356
-
357
- ![2017-01-30_11-33-59](https://cloud.githubusercontent.com/assets/1118459/22443635/b3549fb4-e6e3-11e6-8ea2-6f589dc93ed3.png)
358
-
359
- 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).
360
-
361
- # Supporters
362
-
363
- 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 [HawaiiChee.com](https://www.hawaiichee.com), [BrowserStack](https://www.browserstack.com) to solve problems with oddball browsers, and [CodersRank](https://codersrank.io/) to find candidates for our team.
364
-
365
- [![2019-09-24_17-48-00](https://user-images.githubusercontent.com/1118459/65567887-96353780-def3-11e9-926d-4a55e2e186ff.png)](https://www.jetbrains.com/ruby/)
366
- [![Scout](https://user-images.githubusercontent.com/1118459/41828269-106b40f8-77d0-11e8-8d19-9c4b167ef9d8.png)](https://scoutapp.com/)
367
- [![BrowserStack](https://cloud.githubusercontent.com/assets/1118459/23203304/1261e468-f886-11e6-819e-93b1a3f17da4.png)](https://www.browserstack.com)
368
- [![CodersRank](https://user-images.githubusercontent.com/1118459/55040254-ad8a7b00-4fcb-11e9-8936-c6765eb30698.png)](https://codersrank.io/?utm_source=github&utm_medium=banner&utm_campaign=shakacode)
369
-
370
- ## Clubhouse
371
- I've just moved ShakaCode's development to [ClubHouse](https://clubhouse.io/) from Trello. We're going to be doing this with all our projects. If you want to **try ClubHouse and get 2 months free beyond the 14-day trial period**, click [here to use ShakaCode's referral code](http://r.clbh.se/mvfoNeH). We're participating in their awesome triple-sided referral program, which you can read about [here](https://clubhouse.io/blog/clubhouse-referral-program-5f614bb437c3). By using our [referral code](http://r.clbh.se/mvfoNeH) you'll be supporting ShakaCode and, thus, React on Rails!
372
-
373
- *If you'd like to support React on Rails and have your company listed here, [get in touch](mailto:justin@shakacode.com).*
374
-
375
- Aloha and best wishes from Justin and the ShakaCode team!
376
-
377
- # Work with Us
378
- ShakaCode is **[currently looking to hire](http://www.shakacode.com/about/#work-with-us)** like-minded, remote-first, developers that wish to work on our projects, including [Hawaii Chee](https://www.hawaiichee.com). Your main coding interview will be pairing with us on our open source! We're also using [ReasonML](https://reasonml.github.io/) extensively!
379
-
380
- # License
381
-
382
- The gem is available as open source under the terms of the [MIT License](https://github.com/shakacode/react_on_rails/tree/master/LICENSE.md).
22
+ # Other Resources
23
+ 1. RailsConf 2020 talk: [Webpacker, It-Just-Works, But How?](http://railsconf.com/2020/video/justin-gordon-webpacker-it-just-works-but-how)
@@ -68,7 +68,7 @@ ReactOnRails.register({
68
68
  RouterApp,
69
69
  });
70
70
  ```
71
- Note that you should not register a renderer on the server, since there won't be a domNodeId when we're server rendering. Note that the `RouterApp` imported by `serverRegistration.js` is from a different file. For an example of how to set up an app for server rendering, see the [react router docs](https://www.shakacode.com/react-on-rails/docs/javascript/react-router).
71
+ Note that you should not register a renderer on the server, since there won't be a domNodeId when we're server rendering. Note that the `RouterApp` imported by `serverRegistration.js` is from a different file. For an example of how to set up an app for server rendering, see the [react router docs](https://www.shakacode.com/react-on-rails/docs/javascript/react-router/).
72
72
 
73
73
  #### RouterAppRenderer.jsx
74
74
  ```jsx
@@ -150,7 +150,7 @@ config = {
150
150
 
151
151
  This causes Webpack to prepend the code chunk filename with `/assets/` in the request url. The react on rails sets up the webpack config to put webpack bundles in `app/assets/javascripts/webpack`, and modifies `config/initializers/assets.rb` so that rails detects the bundles. This means that when we prepend the request url with `/assets/`, rails will know what webpack is asking for.
152
152
 
153
- See [our rails assets documentation](https://www.shakacode.com/react-on-rails/docs/outdated/rails-assets) to learn more about static assets.
153
+ See [our rails assets documentation](https://www.shakacode.com/react-on-rails/docs/outdated/rails-assets/) to learn more about static assets.
154
154
 
155
155
  If you forget to set the public path, webpack will request the code chunk at `/{filename}`. This will cause the request to be handled by the Rails router, which will send back a 404 response, assuming that you don't have a catch-all route. In your javascript console, you'll get the following error:
156
156
 
@@ -6,7 +6,7 @@
6
6
  * [Webpacker Lite: Why Fork Webpacker?](https://blog.shakacode.com/webpacker-lite-why-fork-webpacker-f0a7707fac92)
7
7
  * [React on Rails, 2000+ 🌟 Stars](https://medium.com/shakacode/react-on-rails-2000-stars-32ff5cfacfbf#.6gmfb2gpy)
8
8
  * [The React on Rails Doctrine](https://medium.com/@railsonmaui/the-react-on-rails-doctrine-3c59a778c724)
9
- * [Simple Tutorial](https://www.shakacode.com/react-on-rails/docs/basics/tutorial).
9
+ * [Simple Tutorial](https://www.shakacode.com/react-on-rails/docs/guides/tutorial/).
10
10
 
11
11
  ## Videos
12
12
 
@@ -19,12 +19,12 @@ The React on Rails setup provides several key components related to front-end de
19
19
  6. Happiness for us is actively participating in open source, so we want to be where the action is, which is with the npm libraries on github.com.
20
20
  7. You can get set up on React on Rails **FAST** using our application generator.
21
21
  8. By placing all client-side development inside of the `/client` directory, pure JavaScript developers can productively do development separate from Rails. Instead of Rails APIs, stub APIs on an express server can provide a simple backend, allowing for rapid iteration of UI prototypes.
22
- 9. Just because we're not relying on the Rails asset pipeline for ES6 conversion does not mean that we're deploying Rails apps in any different way. We still use the asset pipeline to include our Webpack compiled JavaScript. This only requires a few small modifications, as explained in [our heroku deployment documentation](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment).
22
+ 9. Just because we're not relying on the Rails asset pipeline for ES6 conversion does not mean that we're deploying Rails apps in any different way. We still use the asset pipeline to include our Webpack compiled JavaScript. This only requires a few small modifications, as explained in [our heroku deployment documentation](https://www.shakacode.com/react-on-rails/docs/deployment/heroku-deployment/).
23
23
 
24
24
  ## Convention over Configuration
25
25
  * React on Rails has taken the hard work out of figuring out the JavaScript tooling that works best with Rails. Not only could you spend lots of time researching different tooling, but then you'd have to figure out how to splice it all together. This is where a lot of "JavaScript fatigue" comes from. The following keep the code clean and consistent:
26
- * [Style Guide](https://www.shakacode.com/react-on-rails/docs/misc/style)
27
- * [linters](https://www.shakacode.com/react-on-rails/docs/contributor-info/linters)
26
+ * [Style Guide](https://www.shakacode.com/react-on-rails/docs/misc/style/)
27
+ * [linters](https://www.shakacode.com/react-on-rails/docs/contributor-info/linters/)
28
28
 
29
29
  We're big believers in this quote from the Rails Doctrine:
30
30
 
@@ -77,7 +77,7 @@ Note: _You can output these files in the asset pipeline wherever you see fit. My
77
77
 
78
78
  Lastly, we will set the publicPath to our file(s). This will be the endpoint on our rails web server that you can visit to reach the asset (if you don't know how this works, read the [intro](#using-webpack-bundled-assets-with-the-rails-asset-pipeline)). If you've been following the previous steps, you know that we set our outputPath for our assets to be absolute at `app/assets/webpack/webpack-assets/`, which your rails app should end up hosting at `/assets/webpack-assets/file-name+hash.ext` when the server is run.
79
79
 
80
- Note: _If you're having a hard time figuring out what an asset's path will be on your rails server, simply run `rake assets:precompile` and `cd public/`. The path from there to your file will then be the path/url on your web server to that asset. On top of this, it is also a good idea to check out [this doc](https://www.shakacode.com/react-on-rails/docs/outdated/rails-assets) to understand how `react_on_rails` allows us to access these files after precompilation, when Rails applies another hash onto the asset._
80
+ Note: _If you're having a hard time figuring out what an asset's path will be on your rails server, simply run `rake assets:precompile` and `cd public/`. The path from there to your file will then be the path/url on your web server to that asset. On top of this, it is also a good idea to check out [this doc](https://www.shakacode.com/react-on-rails/docs/outdated/rails-assets/) to understand how `react_on_rails` allows us to access these files after precompilation, when Rails applies another hash onto the asset._
81
81
 
82
82
  Our publicPath setting will match the path to our outputted assets on our rails web server. Given our assets in this example will be outputted to `/app/assets/webpack/webpack-assets/` and hosted at `/assets/webpack-assets/`, our publicPath would be:
83
83
 
@@ -192,4 +192,4 @@ module.exports = {
192
192
  };
193
193
  ```
194
194
 
195
- If you'd like to understand how react_on_rails handles these bundled assets after asset precompilation and in production mode, check out: [Rails Assets](https://www.shakacode.com/react-on-rails/docs/outdated/rails-assets).
195
+ If you'd like to understand how react_on_rails handles these bundled assets after asset precompilation and in production mode, check out: [Rails Assets](https://www.shakacode.com/react-on-rails/docs/outdated/rails-assets/).
@@ -30,7 +30,7 @@ will have the Webpack digested name (MD5 hash). Since the Webpack generated CSS
30
30
  just one level of "digesting", this "double-digesting" from Rails will cause such these assets
31
31
  fail to load.
32
32
 
33
- _If you are interested in learning how to use assets in your React components, read this doc: [Webpack, the Asset Pipeline, and Using Assets w/ React](https://www.shakacode.com/react-on-rails/docs/outdated/rails-assets-relative-paths)_
33
+ _If you are interested in learning how to use assets in your React components, read this doc: [Webpack, the Asset Pipeline, and Using Assets w/ React](https://www.shakacode.com/react-on-rails/docs/outdated/rails-assets-relative-paths/)_
34
34
 
35
35
  ## The Solution: Symlink Original File Names to New File Names
36
36
  _Note, this solution was removed in v14. If you're intersted in this symlink solution, please create
@@ -16,4 +16,4 @@ Rails will start creating the app and will skip the files you have already creat
16
16
  3. If it is removeing some of your code then press "n" and add all additions manually
17
17
  ```
18
18
 
19
- 3. Run `bundle install` and follow [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/basics/installation-into-an-existing-rails-app)
19
+ 3. Run `bundle install` and follow [the instructions for installing into an existing Rails app](https://www.shakacode.com/react-on-rails/docs/guides/installation-into-an-existing-rails-app/)
@@ -14,24 +14,15 @@ s.add_dependency 'react_on_rails', '~> 6'
14
14
  ```ruby
15
15
  require "react_on_rails"
16
16
  ```
17
- + In your `lib/tasks/<engine_name>_tasks.rake`:
18
- ```ruby
19
- Rake.application.remove_task('react_on_rails:assets:compile_environment')
20
-
21
- task 'react_on_rails:assets:compile_environment' do
22
- path = File.join(YourEngineName::Engine.root, 'client')
23
- sh "cd #{path} && #{ReactOnRails.configuration.build_production_command}"
24
- end
25
- ```
26
17
  ## In the project including your engine
27
18
 
28
19
  Place `gem 'react_on_rails', '~> 6'` before the gem pointing at your engine in your gemfile.
29
20
 
30
- This is necessary because React on Rails attaches itself to the rake assets:precompile task. It then uses a direct path to cd into client, which will not exist in the main app that includes your engine. Since you'll always be precompiling assets in the parent app, this will always fail. The workaround then, is to remove the task and replace it with one that goes into your Engine's root. The reason you have to include the react on rails gem before your engine is so that the `react_on_rails:assets:compile_environment` task is defined by the time your engine gets loaded to remove it.
31
-
32
21
  Requiring `react_on_rails` and including the helper will get rid of any issues where react on rails or react_component is undefined.
33
22
 
34
- As far as solving the assets issue, `lib/tasks/assets.rake` in `react_on_rails` would somehow have to know that `react_on_rails` was included in an engine, and decide the path accordingly. This might be impossible, especially in the case of multiple engines using `react_on_rails` in a single application. Another solution would be to detach this rake task from the rails assets:precompile task, and let people use it separately.
23
+ As far as solving the assets issue, `lib/tasks/assets.rake` in `react_on_rails` would somehow have to know that `react_on_rails` was included in an engine, and decide the path accordingly. This might be impossible, especially in the case of multiple engines using `react_on_rails` in a single application.
24
+
25
+ Another solution would be to detach this rake task from the `rails assets:precompile` task. This can be done by adding `REACT_ON_RAILS_PRECOMPILE=false` to your environment. If you do so, then react assets will have to be bundled separately from `rails assets:precompile`.
35
26
 
36
27
  # Github Issues
37
28
 
@@ -0,0 +1,43 @@
1
+ ## React on Rails Pro
2
+
3
+ Support React on Rails development [by becoming a Github sponsor](https://github.com/sponsors/shakacode) and get these benefits:
4
+
5
+ 1. 1-hour per month of support via Slack, PR reviews, and Zoom for React on Rails,
6
+ React-Rails, rails/webpacker, ReScript (ReasonML), TypeScript, Rust, etc.
7
+ 2. React on Rails Pro Software that extends React on Rails with Node server rendering,
8
+ fragment caching, code-splitting, and other performance enhancements for React on Rails.
9
+
10
+ See the [React on Rails Pro Support Plan](https://www.shakacode.com/react-on-rails-pro/).
11
+
12
+ ShakaCode can also help you with your custom software development needs. We specialize in
13
+ marketplace and e-commerce applications that utilize both Rails and React.
14
+ Because we own [HiChee.com](https://hichee.com), we can leverage that code for your app!
15
+
16
+ Please email Justin Gordon [justin@shakacode.com](mailto:justin@shakacode.com), the
17
+ maintainer of React on Rails, for more information.
18
+
19
+ ### Pro: Fragment Caching
20
+
21
+ 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:
22
+
23
+ 1. The `cache_key` takes the same parameters as any Rails `cache` view helper.
24
+ 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`:
25
+
26
+ ```ruby
27
+ <%= cached_react_component("App", cache_key: [@user, @post], prerender: true) do
28
+ some_slow_method_that_returns_props
29
+ end %>
30
+ ```
31
+
32
+ Such fragment caching saves CPU work for your web server and greatly reduces the request time. It completely skips the evaluation costs of:
33
+
34
+ 1. Database calls to compute the props.
35
+ 2. Serialization the props values hash into a JSON string for evaluating JavaScript to server render.
36
+ 3. Costs associated with evaluating JavaScript from your Ruby code.
37
+ 4. Creating the HTML string containing the props and the server-rendered JavaScript code.
38
+
39
+ Note, even without server rendering (without step 3 above), fragment caching is still effective.
40
+
41
+ ### Pro: Integration with Node.js for Server Rendering
42
+
43
+ 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).
@@ -1,17 +1,17 @@
1
1
  # Testimonials
2
- # [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn)
2
+ # [HVMN Testimonial, Written by Paul Benigeri, October 12, 2018](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn/)
3
3
 
4
4
  > 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.
5
5
 
6
- Full writeup [here](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn).
6
+ Full writeup [here](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn/).
7
7
 
8
8
  ---
9
9
 
10
- # [Leora from ResortPass](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass), December 10, 2018
10
+ # [Leora from ResortPass](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass/), December 10, 2018
11
11
 
12
12
  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.
13
13
 
14
- Full writeup [here](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass).
14
+ Full writeup [here](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass/).
15
15
 
16
16
  ---
17
17
 
@@ -536,6 +536,12 @@ module ReactOnRails
536
536
 
537
537
  controller.is_a?(ActionMailer::Base)
538
538
  end
539
+
540
+ if defined?(ScoutApm)
541
+ include ScoutApm::Tracer
542
+ instrument_method :react_component, type: "ReactOnRails", name: "react_component"
543
+ instrument_method :react_component_hash, type: "ReactOnRails", name: "react_component_hash"
544
+ end
539
545
  end
540
546
  end
541
547
  # rubocop:enable Metrics/ModuleLength
@@ -54,18 +54,13 @@ module ReactOnRails
54
54
  end
55
55
 
56
56
  def locale_files
57
- # rubocop:disable Layout/IndentationWidth, Style/RedundantBegin
58
- @locale_files ||= begin
59
- if i18n_yml_dir.present?
60
- Dir["#{i18n_yml_dir}/**/*.yml"]
61
- else
62
- ReactOnRails::Utils.truthy_presence(
63
- Rails.application && Rails.application.config.i18n.load_path
64
- ).presence
65
- end
66
- end
67
-
68
- # rubocop:enable Layout/IndentationWidth, Style/RedundantBegin
57
+ @locale_files ||= if i18n_yml_dir.present?
58
+ Dir["#{i18n_yml_dir}/**/*.yml"]
59
+ else
60
+ ReactOnRails::Utils.truthy_presence(
61
+ Rails.application && Rails.application.config.i18n.load_path
62
+ ).presence
63
+ end
69
64
  end
70
65
 
71
66
  def i18n_dir