react_on_rails 12.0.5.beta.0 → 12.4.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +23 -11
- data/.eslintrc +2 -0
- data/.prettierrc +0 -3
- data/.rubocop.yml +40 -2
- data/CHANGELOG.md +56 -26
- data/CONTRIBUTING.md +3 -2
- data/Gemfile.development_dependencies +4 -3
- data/NEWS.md +9 -4
- data/README.md +28 -323
- data/Rakefile +1 -1
- data/SUMMARY.md +12 -12
- data/docs/{basics → additional-details}/generator-details.md +1 -6
- data/docs/{outdated → additional-details}/manual-installation-overview.md +6 -6
- data/docs/{basics → additional-details}/migrating-from-react-rails.md +0 -0
- data/docs/{additional-reading → additional-details}/recommended-project-structure.md +0 -0
- data/docs/{additional-reading → additional-details}/updating-dependencies.md +0 -0
- data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +10 -0
- data/docs/api/javascript-api.md +2 -2
- data/docs/api/redux-store-api.md +3 -3
- data/docs/api/view-helpers-api.md +7 -8
- data/docs/contributor-info/linters.md +5 -6
- data/docs/contributor-info/pull-requests.md +2 -4
- data/docs/contributor-info/releasing.md +1 -1
- data/docs/{additional-reading → deployment}/elastic-beanstalk.md +0 -0
- data/docs/{basics → deployment}/heroku-deployment.md +0 -0
- data/docs/{basics → guides}/client-vs-server-rendering.md +3 -3
- data/docs/{basics → guides}/configuration.md +45 -25
- data/docs/guides/deployment.md +4 -0
- data/docs/guides/getting-started.md +183 -0
- data/docs/{basics → guides}/hmr-and-hot-reloading-with-the-webpack-dev-server.md +0 -0
- data/docs/{outdated → guides}/how-react-on-rails-works.md +9 -8
- data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +39 -0
- data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +98 -0
- data/docs/{basics → guides}/i18n.md +0 -0
- data/docs/{basics → guides}/installation-into-an-existing-rails-app.md +3 -3
- data/docs/{basics → guides}/minitest-configuration.md +0 -0
- data/docs/guides/rails-webpacker-react-integration-options.md +182 -0
- data/docs/guides/react-on-rails-overview.md +30 -0
- data/docs/{basics → guides}/react-server-rendering.md +3 -3
- data/docs/{basics → guides}/render-functions-and-railscontext.md +0 -0
- data/docs/{basics → guides}/rspec-configuration.md +10 -10
- data/docs/{tutorial.md → guides/tutorial.md} +9 -11
- data/docs/{basics → guides}/upgrading-react-on-rails.md +7 -7
- data/docs/{basics → guides}/webpack-configuration.md +4 -6
- data/docs/home.md +23 -0
- data/docs/{additional-reading → javascript}/angular-js-integration-migration.md +0 -0
- data/docs/{additional-reading → javascript}/asset-pipeline.md +0 -0
- data/docs/{additional-reading → javascript}/capistrano-deployment.md +0 -0
- data/docs/{outdated → javascript}/code-splitting.md +3 -3
- data/docs/{additional-reading → javascript}/converting-from-custom-webpack-config-to-rails-webpacker-config.md +3 -3
- data/docs/{additional-reading → javascript}/credits.md +0 -0
- data/docs/{additional-reading → javascript}/foreman-issues.md +0 -0
- data/docs/{additional-reading → javascript}/images.md +5 -6
- data/docs/{additional-reading → javascript}/node-dependencies-and-npm.md +0 -0
- data/docs/{additional-reading → javascript}/react-and-redux.md +0 -0
- data/docs/{additional-reading → javascript}/react-helmet.md +0 -0
- data/docs/{additional-reading → javascript}/react-router.md +0 -0
- data/docs/{additional-reading → javascript}/server-rendering-tips.md +0 -0
- data/docs/{additional-reading → javascript}/troubleshooting-when-using-webpacker.md +0 -0
- data/docs/{additional-reading → javascript}/webpack-v1-notes.md +0 -0
- data/docs/{additional-reading → javascript}/webpack.md +0 -0
- data/docs/{articles.md → misc/articles.md} +1 -1
- data/docs/misc/doctrine.md +5 -5
- data/docs/{coding-style → misc}/style.md +0 -0
- data/docs/{additional-reading → misc}/tips.md +0 -0
- data/docs/outdated/deferred-rendering.md +39 -0
- data/docs/outdated/rails-assets-relative-paths.md +3 -3
- data/docs/outdated/rails-assets.md +8 -8
- data/docs/outdated/rails3.md +2 -2
- data/docs/{additional-reading → rails}/convert-rails-5-api-only-app.md +1 -1
- data/docs/{additional-reading → rails}/rails-engine-integration.md +3 -12
- data/docs/{additional-reading → rails}/rails_view_rendering_from_inline_javascript.md +0 -0
- data/docs/{additional-reading → rails}/turbolinks.md +13 -1
- data/docs/react-on-rails-pro/react-on-rails-pro.md +43 -0
- data/docs/testimonials/testimonials.md +6 -6
- data/lib/generators/react_on_rails/base_generator.rb +1 -1
- data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +4 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb +2 -2
- data/lib/react_on_rails/helper.rb +26 -2
- data/lib/react_on_rails/locales/base.rb +7 -9
- data/lib/react_on_rails/react_component/render_options.rb +16 -7
- data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +11 -0
- data/lib/react_on_rails/utils.rb +16 -2
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/react_on_rails/webpacker_utils.rb +5 -1
- data/lib/tasks/assets.rake +17 -6
- data/package.json +24 -29
- data/rakelib/release.rake +22 -6
- data/rakelib/task_helpers.rb +15 -2
- data/yarn.lock +2549 -5169
- metadata +56 -49
- data/.release-it.json +0 -3
- data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +0 -10
- data/docs/basics/deployment.md +0 -4
data/README.md
CHANGED
@@ -3,58 +3,31 @@
|
|
3
3
|
<p align="center">
|
4
4
|
<a href="https://shakacode.com/"><img src="https://user-images.githubusercontent.com/10421828/79436256-517d0500-7fd9-11ea-9300-dfbc7c293f26.png"></a>
|
5
5
|
<a href="https://forum.shakacode.com/"><img src="https://user-images.githubusercontent.com/10421828/79436266-53df5f00-7fd9-11ea-94b3-b985e1b05bdc.png"></a>
|
6
|
-
<a href="https://
|
6
|
+
<a href="https://www.shakacode.com/react-on-rails-pro"><img src="https://user-images.githubusercontent.com/10421828/79436265-53df5f00-7fd9-11ea-8220-fc474f6a856c.png"></a>
|
7
7
|
<a href="https://github.com/sponsors/shakacode"><img src="https://user-images.githubusercontent.com/10421828/79466109-cdd90d80-8004-11ea-88e5-25f9a9ddcf44.png"></a>
|
8
8
|
</p>
|
9
9
|
|
10
10
|
---
|
11
11
|
|
12
|
-
[![License](https://img.shields.io/badge/license-mit-green.svg)](
|
12
|
+
[![License](https://img.shields.io/badge/license-mit-green.svg)](LICENSE.md) [![Build Status](https://travis-ci.org/shakacode/react_on_rails.svg?branch=master)](https://travis-ci.org/shakacode/react_on_rails) [![Gem Version](https://badge.fury.io/rb/react_on_rails.svg)](https://badge.fury.io/rb/react_on_rails) [![npm version](https://badge.fury.io/js/react-on-rails.svg)](https://badge.fury.io/js/react-on-rails) [![Code Climate](https://codeclimate.com/github/shakacode/react_on_rails/badges/gpa.svg)](https://codeclimate.com/github/shakacode/react_on_rails) [![Coverage Status](https://coveralls.io/repos/shakacode/react_on_rails/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react_on_rails?branch=master) [![](https://ruby-gem-downloads-badge.herokuapp.com/react_on_rails?type=total)](https://rubygems.org/gems/react_on_rails)
|
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
|
-
|
18
|
-
**October 14, 2020**: [RUBY ROGUES
|
19
|
-
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/).
|
20
|
-
|
21
|
-
**October 1, 2020**: See the [spec/dummy](./spec/dummy) example repo for a simple configuration of webpack via the rails/webpacker gem
|
22
|
-
that supports SSR.
|
23
|
-
|
24
|
-
**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`.
|
25
|
-
|
26
|
-
**July 8, 2020**: Release v12 of React on Rails.
|
27
|
-
|
28
|
-
**Major Improvements**
|
29
|
-
|
30
|
-
1. **React Hooks Support** for top level components
|
31
|
-
2. **Typescript bindings**
|
32
|
-
3. **rails/webpacker** "just works" with React on Rails by default.
|
33
|
-
4. i18n support for generating a JSON file rather than a JS file.
|
34
|
-
|
35
|
-
Be sure to see the [CHANGELOG.md](./CHANGELOG.md) and read the upgrade instructions:
|
36
|
-
[docs/basics/upgrading-react-on-rails](./docs/basics/upgrading-react-on-rails.md#upgrading-to-v12).
|
37
|
-
|
38
|
-
* See Justin's RailsConf talk: [Webpacker, It-Just-Works, But How?](http://railsconf.com/2020/video/justin-gordon-webpacker-it-just-works-but-how).
|
39
|
-
* 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).
|
40
|
-
* 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.
|
41
|
-
---
|
42
|
-
|
43
16
|
#### About
|
44
17
|
React on Rails integrates Rails with (server rendering of) Facebook's [React](https://github.com/facebook/react) front-end framework.
|
45
18
|
|
46
|
-
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/).
|
47
20
|
|
48
21
|
Interested in optimizing your webpack setup for React on Rails including code
|
49
|
-
splitting with [react-router](https://github.com/ReactTraining/react-router#readme)
|
50
|
-
and [loadable-components](https://loadable-components.com/) with server-side rendering?
|
51
|
-
We
|
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/).
|
52
25
|
|
53
26
|
Feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com), maintainer of React on Rails, for more information.
|
54
27
|
|
55
|
-
|
28
|
+
# Documentation
|
56
29
|
|
57
|
-
|
30
|
+
See the documentation at [shakacode.com/react-on-rails/docs](https://www.shakacode.com/react-on-rails/docs/).
|
58
31
|
|
59
32
|
## Project Objective
|
60
33
|
|
@@ -62,331 +35,63 @@ To provide a high performance framework for integrating Ruby on Rails with React
|
|
62
35
|
|
63
36
|
## Features and Why React on Rails?
|
64
37
|
|
65
|
-
Given that `rails/webpacker` gem already provides basic React integration, why would you use "React on Rails"?
|
38
|
+
Given that `rails/webpacker` gem already provides basic React integration, why would you use "React on Rails"?
|
66
39
|
|
67
40
|
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.
|
68
41
|
1. Tight integration with [rails/webpacker](https://github.com/rails/webpacker).
|
69
42
|
1. Server-Side Rendering (SSR), often used for SEO crawler indexing and UX performance, is not offered by `rails/webpacker`.
|
70
43
|
1. [Redux](https://github.com/reactjs/redux) and [React Router](https://github.com/ReactTraining/react-router#readme) integration with server-side-rendering.
|
71
|
-
1. [Internationalization (I18n) and (localization)](https://
|
44
|
+
1. [Internationalization (I18n) and (localization)](https://www.shakacode.com/react-on-rails/docs/guides/i18n)
|
72
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/).
|
73
46
|
1. [Reason ML Support](https://github.com/shakacode/reason-react-on-rails-example).
|
74
47
|
|
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.
|
49
|
+
|
75
50
|
See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
|
76
51
|
|
77
52
|
## ShakaCode Forum Premium Content
|
78
53
|
_Requires creating a free account._
|
79
|
-
|
80
|
-
* [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)
|
81
54
|
|
82
|
-
|
83
|
-
|
84
|
-
# Docs
|
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)
|
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)
|
85
57
|
|
86
|
-
**Consider browsing this on our [documentation Gitbook](https://shakacode.gitbooks.io/react-on-rails/content/).**
|
87
58
|
|
88
59
|
## Prerequisites
|
89
60
|
|
90
61
|
Ruby on Rails >=5 and rails/webpacker 4.2+.
|
91
62
|
|
92
|
-
## Getting Started
|
93
|
-
|
94
|
-
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.
|
95
|
-
|
96
|
-
1. Do the quick [tutorial](docs/tutorial.md).
|
97
|
-
1. Add React on Rails to an existing Rails app per [the instructions](docs/basics/installation-into-an-existing-rails-app.md).
|
98
|
-
1. Look at [spec/dummy](spec/dummy), a simple, no DB example. This has an example of using `rails/webpacker` to configure server-side rendering.
|
99
|
-
1. 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`.
|
100
|
-
1. 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).
|
101
|
-
|
102
|
-
## Basic Installation
|
103
|
-
|
104
|
-
*See also [the instructions for installing into an existing Rails app](docs/basics/installation-into-an-existing-rails-app.md).*
|
105
|
-
|
106
|
-
1. Add the `rails/webpacker` gem if you don't yet have it.
|
107
|
-
|
108
|
-
1. Add the `react_on_rails` gem to Gemfile. _Use the latest version for react_on_rails._
|
109
|
-
```bash
|
110
|
-
bundle add react_on_rails --version=12.0.4 --strict
|
111
|
-
```
|
112
|
-
|
113
|
-
1. Commit this to git (or else you cannot run the generator unless you pass the option `--ignore-warnings`).
|
114
|
-
|
115
|
-
1. Run the generator:
|
116
|
-
```bash
|
117
|
-
rails generate react_on_rails:install
|
118
|
-
```
|
119
|
-
|
120
|
-
1. Start the app:
|
121
|
-
```bash
|
122
|
-
rails s
|
123
|
-
```
|
124
|
-
|
125
|
-
1. Visit http://localhost:3000/hello_world.
|
126
|
-
|
127
|
-
|
128
|
-
### Turning on server rendering
|
129
|
-
|
130
|
-
With the code from running the React on Rails generator above:
|
131
|
-
|
132
|
-
1. Edit `app/views/hello_world/index.html.erb` and set `prerender` to `true`.
|
133
|
-
2. Refresh the page.
|
134
|
-
|
135
|
-
Below is the line where you turn server rendering on by setting `prerender` to true:
|
136
|
-
|
137
|
-
```erb
|
138
|
-
<%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %>
|
139
|
-
```
|
140
|
-
|
141
|
-
Note, if you got an error in your console regarding "ReferenceError: window is not defined",
|
142
|
-
then you need to edit `config/webpacker.yml` and set `hmr: false` and `inline: false`.
|
143
|
-
See [rails/webpacker PR 2644](https://github.com/rails/webpacker/pull/2644) for a fix for this
|
144
|
-
issue.
|
145
|
-
|
146
|
-
## Basic Usage
|
147
|
-
|
148
|
-
### Configuration
|
149
|
-
|
150
|
-
* Configure `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [docs/basics/configuration.md](docs/basics/configuration.md) for documentation of all configuration options.
|
151
|
-
* 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](./spec/dummy/config/webpacker.yml) example or the official default [webpacker.yml](https://github.com/rails/webpacker/blob/master/lib/install/config/webpacker.yml).
|
152
|
-
* 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.
|
153
|
-
* Your `public_output_path` must match your custom Webpack configuration for `output` of your bundles.
|
154
|
-
* Only set `cache_manifest` to `true` in your production env.
|
155
|
-
|
156
|
-
## Including your React Component on your Rails Views
|
157
|
-
|
158
|
-
- React component are rendered via your Rails Views. Here's an ERB sample:
|
159
|
-
|
160
|
-
```erb
|
161
|
-
<%= react_component("HelloWorld", props: @some_props) %>
|
162
|
-
```
|
163
|
-
|
164
|
-
- **Server-Side Rendering**: Your react component is first rendered into HTML on the server. Use the **prerender** option:
|
165
|
-
|
166
|
-
```erb
|
167
|
-
<%= react_component("HelloWorld", props: @some_props, prerender: true) %>
|
168
|
-
```
|
169
|
-
|
170
|
-
- 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:
|
171
|
-
|
172
|
-
```js
|
173
|
-
import ReactOnRails from 'react-on-rails';
|
174
|
-
import HelloWorld from './HelloWorld';
|
175
|
-
ReactOnRails.register({ HelloWorld });
|
176
|
-
```
|
177
|
-
|
178
|
-
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.
|
179
|
-
|
180
|
-
- `@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:
|
181
|
-
|
182
|
-
```ruby
|
183
|
-
# Rails View
|
184
|
-
<%= react_component("HelloWorld", props: { name: "Stranger" }) %>
|
185
|
-
```
|
186
|
-
|
187
|
-
- 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](docs/basics/render-functions-and-railscontext.md) for more details on this topic.
|
188
|
-
|
189
|
-
```js
|
190
|
-
import React from 'react';
|
191
|
-
|
192
|
-
export default (props, railsContext) => {
|
193
|
-
// Note wrap in a function to make this a React function component
|
194
|
-
return () => (
|
195
|
-
<div>
|
196
|
-
Your locale is {railsContext.i18nLocale}.<br/>
|
197
|
-
Hello, {props.name}!
|
198
|
-
</div>
|
199
|
-
);
|
200
|
-
};
|
201
|
-
```
|
202
|
-
|
203
|
-
See the [View Helpers API](./docs/api/view-helpers-api.md) for more details on `react_component` and its sibling function `react_component_hash`.
|
204
|
-
|
205
|
-
## Globally Exposing Your React Components
|
206
|
-
|
207
|
-
For the React on Rails view helper `react_component` to use your React components, you will have to **register** them in your JavaScript code.
|
208
|
-
|
209
|
-
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**.
|
210
|
-
|
211
|
-
This is how to expose a component to the `react_component` view helper.
|
212
|
-
|
213
|
-
```javascript
|
214
|
-
// app/javascript/packs/hello-world-bundle.js
|
215
|
-
import HelloWorld from '../components/HelloWorld';
|
216
|
-
import ReactOnRails from 'react-on-rails';
|
217
|
-
ReactOnRails.register({ HelloWorld });
|
218
|
-
```
|
219
|
-
|
220
|
-
#### Different Server-Side Rendering Code (and a Server-Specific Bundle)
|
221
|
-
|
222
|
-
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() }`.
|
223
|
-
|
224
|
-
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.
|
225
|
-
|
226
|
-
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._)
|
227
|
-
|
228
|
-
## Specifying Your React Components: Register directly or use render-functions
|
229
|
-
|
230
|
-
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:
|
231
|
-
|
232
|
-
1. You to have access to the `railsContext`. See [documentation for the railsContext](./docs/basics/render-functions-and-railscontext.md) in terms of why you might need it. You **need** a Render-Function to access the `railsContext`.
|
233
|
-
2. You can use the passed-in props to initialize a redux store or set up react-router.
|
234
|
-
3. You can return different components depending on what's in the props.
|
235
|
-
|
236
|
-
Note, the return value of a **Render-Function** should be either a React Function or Class Component, or an object representing server rendering results.
|
237
|
-
|
238
|
-
Do not return a React Element (JSX).
|
239
|
-
|
240
|
-
ReactOnRails will automatically detect a registered Render-Function by the fact that the function takes
|
241
|
-
more than 1 parameter. In other words, if you want the ability to provide a function that returns the
|
242
|
-
React component, then you need to specify at least a second parameter. This is the `railsContext`.
|
243
|
-
If you're not using this parameter, declare your function with the unused param:
|
244
|
-
|
245
|
-
```js
|
246
|
-
const MyComponentGenerator = (props, _railsContext) => {
|
247
|
-
if (props.print) {
|
248
|
-
// This is a React FunctionComponent because it is wrapped in a function.
|
249
|
-
return () => <H1>{JSON.stringify(props)}</H1>;
|
250
|
-
}
|
251
|
-
}
|
252
|
-
```
|
253
|
-
|
254
|
-
Thus, there is no difference between registering a React Function Component or class Component versus a "Render-Function." Just call `ReactOnRails.register`.
|
255
|
-
|
256
|
-
## react_component_hash for Render-Functions
|
257
|
-
|
258
|
-
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`.
|
259
|
-
|
260
|
-
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:
|
261
|
-
|
262
|
-
```js
|
263
|
-
{ renderedHtml: { componentHtml, customKey1, customKey2} }
|
264
|
-
```
|
265
|
-
|
266
|
-
For details on using react_component_hash with react-helmet, see the docs below for the helper API and [docs/additional-reading/react-helmet.md](docs/additional-reading/react-helmet.md).
|
267
|
-
|
268
|
-
## Error Handling
|
269
|
-
|
270
|
-
* All errors from ReactOnRails will be of type ReactOnRails::Error.
|
271
|
-
* Prerendering (server rendering) errors get context information for HoneyBadger and Sentry for easier debugging.
|
272
|
-
|
273
|
-
## I18n
|
274
|
-
|
275
|
-
React on Rails provides an option for automatic conversions of Rails `*.yml` locale files into `*.json` or `*.js*.
|
276
|
-
See the [How to add I18n](docs/basics/i18n.md) for a summary of adding I18n.
|
277
|
-
|
278
|
-
## More Details
|
279
|
-
|
280
|
-
Browse the links in the [Summary Table of Contents](./SUMMARY.md)
|
281
|
-
|
282
|
-
Here are some highly recommended next articles to read:
|
283
|
-
|
284
|
-
1. [How React on Rails Works](docs/outdated/how-react-on-rails-works.md)
|
285
|
-
1. [Webpack Configuration](./docs/basics/webpack-configuration.md)
|
286
|
-
1. [View Helpers API](./docs/api/view-helpers-api.md)
|
287
|
-
1. [Caching and Performance: React on Rails Pro](https://www.shakacode.com/react-on-rails-pro).
|
288
|
-
1. [Deployment](docs/basics/deployment.md).
|
289
|
-
|
290
63
|
# Support
|
291
64
|
|
292
|
-
[Click to join **React + Rails Slack**](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
|
293
|
-
|
294
|
-
## Community Resources
|
295
|
-
|
296
|
-
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.
|
297
|
-
|
298
|
-
[![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)
|
299
|
-
|
300
|
-
- **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.
|
301
67
|
- **[forum.shakacode.com](https://forum.shakacode.com)**: Post your questions
|
302
68
|
- **[@railsonmaui on Twitter](https://twitter.com/railsonmaui)**
|
303
|
-
-
|
304
|
-
- See [Projects](PROJECTS.md) using and [KUDOS](
|
305
|
-
- *See [NEWS.md](NEWS.md) for more notes over time.*
|
69
|
+
- *See [NEWS.md](https://github.com/shakacode/react_on_rails/tree/master/NEWS.md) for more notes over time.*
|
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.
|
71
|
+
- *See [NEWS.md](https://github.com/shakacode/react_on_rails/tree/master/NEWS.md) for more notes over time.*
|
306
72
|
|
307
73
|
## Contributing
|
308
74
|
|
309
|
-
Bug reports and pull requests are welcome. See [Contributing](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).
|
310
|
-
|
311
|
-
## React on Rails Pro
|
312
|
-
|
313
|
-
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.
|
314
|
-
|
315
|
-
[![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)
|
316
|
-
|
317
|
-
## React on Rails Pro Support
|
318
|
-
|
319
|
-
The [React on Rails Pro Support Plan](https://www.shakacode.com/react-on-rails-pro) can help!
|
320
|
-
|
321
|
-
* Optimizing your webpack setup to the latest Webpack for React on Rails including code splitting with loadable-components.
|
322
|
-
* Upgrading your app to use the current `rails/webpacker` setup that skips the Sprockets asset pipeline.
|
323
|
-
* Better performance client and server side.
|
324
|
-
* Best practices based on over 6 years of React on Rails experience on many production projects.
|
325
|
-
* Using [Reason](https://reasonml.github.io/) with (or without) React on Rails.
|
326
|
-
|
327
|
-
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!
|
328
|
-
|
329
|
-
Please email Justin Gordon [justin@shakacode.com](mailto:justin@shakacode.com), the maintainer of React on Rails, for more information.
|
330
|
-
|
331
|
-
### Fragment Caching
|
332
|
-
|
333
|
-
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:
|
334
|
-
|
335
|
-
1. The `cache_key` takes the same parameters as any Rails `cache` view helper.
|
336
|
-
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`:
|
337
|
-
|
338
|
-
```ruby
|
339
|
-
<%= cached_react_component("App", cache_key: [@user, @post], prerender: true) do
|
340
|
-
some_slow_method_that_returns_props
|
341
|
-
end %>
|
342
|
-
```
|
343
|
-
|
344
|
-
Such fragment caching saves CPU work for your web server and greatly reduces the request time. It completely skips the evaluation costs of:
|
345
|
-
|
346
|
-
1. Database calls to compute the props.
|
347
|
-
2. Serialization the props values hash into a JSON string for evaluating JavaScript to server render.
|
348
|
-
3. Costs associated with evaluating JavaScript from your Ruby code.
|
349
|
-
4. Creating the HTML string containing the props and the server-rendered JavaScript code.
|
350
|
-
|
351
|
-
Note, even without server rendering (without step 3 above), fragment caching is still effective.
|
352
|
-
|
353
|
-
## Integration with Node.js for Server Rendering
|
354
|
-
|
355
|
-
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).
|
356
|
-
|
357
|
-
## Testimonials for ShakaCode
|
358
|
-
[HVMN Testimonial, by Paul Benigeri, October 12, 2018](./docs/testimonials/hvmn.md)
|
359
|
-
> 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.
|
360
|
-
|
361
|
-
[ResortPass Testimonial, by Leora Juster, December 10, 2018](./docs/testimonials/resortpass.md)
|
362
|
-
|
363
|
-
> 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.
|
364
|
-
|
365
|
-
From Joel Hooks, Co-Founder, Chief Nerd at [egghead.io](https://egghead.io/), January 30, 2017:
|
366
|
-
|
367
|
-
![2017-01-30_11-33-59](https://cloud.githubusercontent.com/assets/1118459/22443635/b3549fb4-e6e3-11e6-8ea2-6f589dc93ed3.png)
|
368
|
-
|
369
|
-
For more testimonials, see [Live Projects](PROJECTS.md) and [Kudos](./KUDOS.md).
|
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).
|
370
76
|
|
371
77
|
# Supporters
|
372
78
|
|
373
|
-
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 [
|
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.
|
374
80
|
|
375
|
-
[![
|
81
|
+
[![RubyMine](https://user-images.githubusercontent.com/1118459/114100597-3b0e3000-9860-11eb-9b12-73beb1a184b2.png)](https://www.jetbrains.com/ruby/)
|
376
82
|
[![Scout](https://user-images.githubusercontent.com/1118459/41828269-106b40f8-77d0-11e8-8d19-9c4b167ef9d8.png)](https://scoutapp.com/)
|
83
|
+
[![Rails AutoScale](https://user-images.githubusercontent.com/1118459/103197530-48dc0e80-488a-11eb-8b1b-a16664b30274.png)](https://railsautoscale.com/)
|
377
84
|
[![BrowserStack](https://cloud.githubusercontent.com/assets/1118459/23203304/1261e468-f886-11e6-819e-93b1a3f17da4.png)](https://www.browserstack.com)
|
378
|
-
[![
|
379
|
-
|
380
|
-
## Clubhouse
|
381
|
-
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!
|
85
|
+
[![HoneyBadger](https://user-images.githubusercontent.com/1118459/114100696-63962a00-9860-11eb-8ac1-75ca02856d8e.png)](https://www.honeybadger.io/)
|
86
|
+
[![StatusHero](https://user-images.githubusercontent.com/1118459/126868048-3fe64e54-4d6d-4066-9df2-8cf6fbaeb314.png)](https://statushero.com/)
|
382
87
|
|
383
|
-
|
88
|
+
ShakaCode's favorite project tracking tool is [ClubHouse](https://clubhouse.io/). 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/referral/). By using our [referral code](http://r.clbh.se/mvfoNeH) you'll be supporting ShakaCode and, thus, React on Rails!
|
384
89
|
|
385
90
|
Aloha and best wishes from Justin and the ShakaCode team!
|
386
91
|
|
387
92
|
# Work with Us
|
388
|
-
ShakaCode is **[
|
93
|
+
ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/career)** to work on our projects, including [HiChee](https://hichee.com).
|
389
94
|
|
390
95
|
# License
|
391
96
|
|
392
|
-
The gem is available as open source under the terms of the [MIT License](LICENSE.md).
|
97
|
+
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).
|
data/Rakefile
CHANGED
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/
|
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/
|
10
|
-
+ [React Server Rendering](./docs/
|
11
|
-
+ [Render-Functions and the RailsContext](docs/
|
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/
|
14
|
-
+ [React on Rails Internationalization (I18n, localization)](docs/
|
15
|
-
+ [RSpec Test Helpers Configuration](docs/
|
16
|
-
+ [Minitest Configuration](docs/
|
17
|
-
+ [Upgrading React on Rails](docs/
|
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/
|
26
|
-
+ [Generator Details](docs/
|
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/
|
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
|
@@ -35,13 +35,9 @@ can pass the redux option if you'd like to have redux setup for you automaticall
|
|
35
35
|
Then you may run
|
36
36
|
|
37
37
|
`rails s`
|
38
|
-
|
39
|
-
More Details:
|
40
|
-
|
41
|
-
`https://github.com/shakacode/react_on_rails/blob/master/docs/basics/generator-details.md`
|
42
38
|
```
|
43
39
|
|
44
|
-
Another good option is to create a simple test app per the [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/).
|
45
41
|
|
46
42
|
# Understanding the Organization of the Generated Client Code
|
47
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*.
|
@@ -58,4 +54,3 @@ You may also notice the `app/lib` folder. This is for any code that is common be
|
|
58
54
|
If you have used the `--redux` generator option, you will notice the familiar additional redux folders in addition to the aforementioned folders. The Hello World example has also been modified to use Redux.
|
59
55
|
|
60
56
|
Note the organizational paradigm of "bundles". These are like application domains and are used for grouping your code into webpack bundles, in case you decide to create different bundles for deployment. This is also useful for separating out logical parts of your application. The concept is that each bundle will have it's own Redux store. If you have code that you want to reuse across bundles, including components and reducers, place them under `/client/app/lib`.
|
61
|
-
|
@@ -14,17 +14,17 @@ 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 API docs
|
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
|
-
1. Add the [Manifest plugin](https://github.com/danethurber/webpack-manifest-plugin) to your config.
|
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.
|
21
21
|
1. You create scripts in `client/package.json` per the example apps. These are used for building your Webpack assets. Also do this for your top level `package.json`.
|
22
22
|
|
23
23
|
## Rails Steps (outside of /client)
|
24
|
-
1. Add `gem "webpacker"` to the Gemfile, run bundle. The gem provides the `stylesheet_pack_tag` and `javascript_pack_tag` helpers which is used to load the bundled assets to your layouts.[Dummy Example](spec/dummy/app/views/layouts/application.html.erb)
|
25
|
-
1. Configure the `config/initializers/react_on_rails.rb`. You can adjust some necessary settings and defaults. See file [spec/dummy/config/initializers/react_on_rails.rb](spec/dummy/config/initializers/react_on_rails.rb) for a detailed example of configuration, including comments on the different values to configure.
|
24
|
+
1. Add `gem "webpacker"` to the Gemfile, run bundle. The gem provides the `stylesheet_pack_tag` and `javascript_pack_tag` helpers which is used to load the bundled assets to your layouts.[Dummy Example](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/app/views/layouts/application.html.erb)
|
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
|
-
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 [heroku
|
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/)
|
29
29
|
|
30
30
|
If I missed anything, please submit a PR or file an issue.
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Upgrading rails/webpacker v3.5 to v4
|
2
|
+
|
3
|
+
The following steps can be followed to update a Webpacker v3.5 app to v4.
|
4
|
+
|
5
|
+
1. Update the gem `webpacker` and the package `@rails/webpacker`
|
6
|
+
1. Merge changes from the new default [.babelrc](https://github.com/shakacode/react_on_rails/tree/master/lib/install/config/.babelrc) to your `/.babelrc`. If you are using React, you need to add `"@babel/preset-react"`, to the list of `presets`.
|
7
|
+
1. Copy the file [.browserslistrc](https://github.com/shakacode/react_on_rails/tree/master/lib/install/config/.browserslistrc) to `/`.
|
8
|
+
1. Merge any differences between [config/webpacker.yml](https://github.com/shakacode/react_on_rails/tree/master/lib/install/config/webpacker.yml) and your `/config/webpacker.yml`.
|
9
|
+
|
10
|
+
Here is an [example commit of these changes](https://github.com/shakacode/react_on_rails-tutorial-v11/pull/1/files).
|
data/docs/api/javascript-api.md
CHANGED
@@ -34,7 +34,7 @@ The best source of docs is the main [ReactOnRails.js](https://github.com/shakaco
|
|
34
34
|
* Your Ruby code with get this Object as a Hash containing keys componentHtml and any other
|
35
35
|
* custom keys that you added:
|
36
36
|
* { renderedHtml: { componentHtml, customKey1, customKey2 } }
|
37
|
-
* See the example in /docs/
|
37
|
+
* See the example in https://www.shakacode.com/react-on-rails/docs/javascript/react-helmet
|
38
38
|
* @param components (key is component name, value is component)
|
39
39
|
*/
|
40
40
|
register(components)
|
@@ -69,7 +69,7 @@ The best source of docs is the main [ReactOnRails.js](https://github.com/shakaco
|
|
69
69
|
* Allow directly calling the page loaded script in case the default events that trigger react
|
70
70
|
* rendering are not sufficient, such as when loading JavaScript asynchronously with TurboLinks:
|
71
71
|
* More details can be found here:
|
72
|
-
* https://
|
72
|
+
* https://www.shakacode.com/react-on-rails/docs/rails/turbolinks
|
73
73
|
*/
|
74
74
|
reactOnRailsPageLoaded()
|
75
75
|
|
data/docs/api/redux-store-api.md
CHANGED
@@ -13,7 +13,7 @@ Consider using the `redux_store` helper for the two following use cases:
|
|
13
13
|
|
14
14
|
## Multiple React Components on a Page with One Store
|
15
15
|
|
16
|
-
You may wish to have 2 React components share the same the Redux store. For example, if your navbar is a React component, you may want it to use the same store as your component in the main area of the page. You may even want multiple React components in the main area, which allows for greater modularity. Also, you may want this to work with Turbolinks to minimize reloading the JavaScript.
|
16
|
+
You may wish to have 2 React components share the same the Redux store. For example, if your navbar is a React component, you may want it to use the same store as your component in the main area of the page. You may even want multiple React components in the main area, which allows for greater modularity. Also, you may want this to work with Turbolinks to minimize reloading the JavaScript.
|
17
17
|
|
18
18
|
A good example of this would be something like a notifications counter in a header. As each notification is read in the body of the page, you would like to update the header. If both the header and body share the same Redux store, then this is trivial. Otherwise, we have to rely on other solutions, such as the header polling the server to see how many unread notifications exist.
|
19
19
|
|
@@ -98,5 +98,5 @@ Place this view helper (no parameters) at the end of your shared layout so React
|
|
98
98
|
|
99
99
|
# More Details
|
100
100
|
|
101
|
-
* [lib/react_on_rails/controller.rb](
|
102
|
-
* [lib/react_on_rails/helper.rb](
|
101
|
+
* [lib/react_on_rails/controller.rb](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/controller.rb) source
|
102
|
+
* [lib/react_on_rails/helper.rb](https://github.com/shakacode/react_on_rails/tree/master/lib/react_on_rails/helper.rb) source
|