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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +23 -11
  3. data/.eslintrc +2 -0
  4. data/.prettierrc +0 -3
  5. data/.rubocop.yml +40 -2
  6. data/CHANGELOG.md +56 -26
  7. data/CONTRIBUTING.md +3 -2
  8. data/Gemfile.development_dependencies +4 -3
  9. data/NEWS.md +9 -4
  10. data/README.md +28 -323
  11. data/Rakefile +1 -1
  12. data/SUMMARY.md +12 -12
  13. data/docs/{basics → additional-details}/generator-details.md +1 -6
  14. data/docs/{outdated → additional-details}/manual-installation-overview.md +6 -6
  15. data/docs/{basics → additional-details}/migrating-from-react-rails.md +0 -0
  16. data/docs/{additional-reading → additional-details}/recommended-project-structure.md +0 -0
  17. data/docs/{additional-reading → additional-details}/updating-dependencies.md +0 -0
  18. data/docs/additional-details/upgrade-webpacker-v3-to-v4.md +10 -0
  19. data/docs/api/javascript-api.md +2 -2
  20. data/docs/api/redux-store-api.md +3 -3
  21. data/docs/api/view-helpers-api.md +7 -8
  22. data/docs/contributor-info/linters.md +5 -6
  23. data/docs/contributor-info/pull-requests.md +2 -4
  24. data/docs/contributor-info/releasing.md +1 -1
  25. data/docs/{additional-reading → deployment}/elastic-beanstalk.md +0 -0
  26. data/docs/{basics → deployment}/heroku-deployment.md +0 -0
  27. data/docs/{basics → guides}/client-vs-server-rendering.md +3 -3
  28. data/docs/{basics → guides}/configuration.md +45 -25
  29. data/docs/guides/deployment.md +4 -0
  30. data/docs/guides/getting-started.md +183 -0
  31. data/docs/{basics → guides}/hmr-and-hot-reloading-with-the-webpack-dev-server.md +0 -0
  32. data/docs/{outdated → guides}/how-react-on-rails-works.md +9 -8
  33. data/docs/guides/how-to-conditionally-server-render-based-on-device-type.md +39 -0
  34. data/docs/guides/how-to-use-different-files-for-client-and-server-rendering.md +98 -0
  35. data/docs/{basics → guides}/i18n.md +0 -0
  36. data/docs/{basics → guides}/installation-into-an-existing-rails-app.md +3 -3
  37. data/docs/{basics → guides}/minitest-configuration.md +0 -0
  38. data/docs/guides/rails-webpacker-react-integration-options.md +182 -0
  39. data/docs/guides/react-on-rails-overview.md +30 -0
  40. data/docs/{basics → guides}/react-server-rendering.md +3 -3
  41. data/docs/{basics → guides}/render-functions-and-railscontext.md +0 -0
  42. data/docs/{basics → guides}/rspec-configuration.md +10 -10
  43. data/docs/{tutorial.md → guides/tutorial.md} +9 -11
  44. data/docs/{basics → guides}/upgrading-react-on-rails.md +7 -7
  45. data/docs/{basics → guides}/webpack-configuration.md +4 -6
  46. data/docs/home.md +23 -0
  47. data/docs/{additional-reading → javascript}/angular-js-integration-migration.md +0 -0
  48. data/docs/{additional-reading → javascript}/asset-pipeline.md +0 -0
  49. data/docs/{additional-reading → javascript}/capistrano-deployment.md +0 -0
  50. data/docs/{outdated → javascript}/code-splitting.md +3 -3
  51. data/docs/{additional-reading → javascript}/converting-from-custom-webpack-config-to-rails-webpacker-config.md +3 -3
  52. data/docs/{additional-reading → javascript}/credits.md +0 -0
  53. data/docs/{additional-reading → javascript}/foreman-issues.md +0 -0
  54. data/docs/{additional-reading → javascript}/images.md +5 -6
  55. data/docs/{additional-reading → javascript}/node-dependencies-and-npm.md +0 -0
  56. data/docs/{additional-reading → javascript}/react-and-redux.md +0 -0
  57. data/docs/{additional-reading → javascript}/react-helmet.md +0 -0
  58. data/docs/{additional-reading → javascript}/react-router.md +0 -0
  59. data/docs/{additional-reading → javascript}/server-rendering-tips.md +0 -0
  60. data/docs/{additional-reading → javascript}/troubleshooting-when-using-webpacker.md +0 -0
  61. data/docs/{additional-reading → javascript}/webpack-v1-notes.md +0 -0
  62. data/docs/{additional-reading → javascript}/webpack.md +0 -0
  63. data/docs/{articles.md → misc/articles.md} +1 -1
  64. data/docs/misc/doctrine.md +5 -5
  65. data/docs/{coding-style → misc}/style.md +0 -0
  66. data/docs/{additional-reading → misc}/tips.md +0 -0
  67. data/docs/outdated/deferred-rendering.md +39 -0
  68. data/docs/outdated/rails-assets-relative-paths.md +3 -3
  69. data/docs/outdated/rails-assets.md +8 -8
  70. data/docs/outdated/rails3.md +2 -2
  71. data/docs/{additional-reading → rails}/convert-rails-5-api-only-app.md +1 -1
  72. data/docs/{additional-reading → rails}/rails-engine-integration.md +3 -12
  73. data/docs/{additional-reading → rails}/rails_view_rendering_from_inline_javascript.md +0 -0
  74. data/docs/{additional-reading → rails}/turbolinks.md +13 -1
  75. data/docs/react-on-rails-pro/react-on-rails-pro.md +43 -0
  76. data/docs/testimonials/testimonials.md +6 -6
  77. data/lib/generators/react_on_rails/base_generator.rb +1 -1
  78. data/lib/generators/react_on_rails/dev_tests_generator.rb +1 -1
  79. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +4 -1
  80. data/lib/generators/react_on_rails/templates/dev_tests/spec/{features → system}/hello_world_spec.rb +2 -2
  81. data/lib/react_on_rails/helper.rb +26 -2
  82. data/lib/react_on_rails/locales/base.rb +7 -9
  83. data/lib/react_on_rails/react_component/render_options.rb +16 -7
  84. data/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb +11 -0
  85. data/lib/react_on_rails/utils.rb +16 -2
  86. data/lib/react_on_rails/version.rb +1 -1
  87. data/lib/react_on_rails/webpacker_utils.rb +5 -1
  88. data/lib/tasks/assets.rake +17 -6
  89. data/package.json +24 -29
  90. data/rakelib/release.rake +22 -6
  91. data/rakelib/task_helpers.rb +15 -2
  92. data/yarn.lock +2549 -5169
  93. metadata +56 -49
  94. data/.release-it.json +0 -3
  95. data/docs/additional-reading/upgrade-webpacker-v3-to-v4.md +0 -10
  96. data/docs/basics/deployment.md +0 -4
@@ -1,6 +1,6 @@
1
1
  # Code Splitting (Outdated)
2
2
 
3
- _Note: This document is outdated._ Please email [justin@shakacode.com](mailto:justin@shakacode.com)
3
+ _Note: This document is outdated._ Please email [justin@shakacode.com](mailto:justin@shakacode.com)
4
4
  if you would be interested in help with code splitting using
5
5
  [loadable-components.com](https://loadable-components.com/docs) with React on Rails.
6
6
 
@@ -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](../additional-reading/react-router.md).
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 [rails-assets.md](docs/outdated/rails-assets.md) 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
 
@@ -1,10 +1,10 @@
1
1
  # Converting from Custom Webpack Config to Rails Webpacker Config
2
2
 
3
- 1. Compare your package.json and the dependencies in https://github.com/rails/webpacker/blob/master/package.json#L14-L48
4
- and avoid any duplicates. We don't want different versions of the same packages.
3
+ 1. Compare your package.json and the dependencies in https://github.com/rails/webpacker/blob/master/package.json
4
+ and avoid any duplicates. We don't want different versions of the same packages.
5
5
  We want the versions from rails/webpacker unless we specifically want to override them.
6
6
  2. Search the rails/webpacker repo for anything you're not sure about in terms of package names.
7
7
  3. run `bin/webpack` and make sure there are zero errors
8
8
  4. update webpack plugins and loaders to current or close to current
9
- 5. Make sure that your bin/webpack and bin/webpacker match the latest on
9
+ 5. Make sure that your bin/webpack and bin/webpacker match the latest on
10
10
  https://github.com/rails/webpacker/tree/master/lib/install/bin
File without changes
@@ -1,8 +1,8 @@
1
1
  # Images
2
2
 
3
- 1. leading slash necessary on the
3
+ 1. leading slash necessary on the
4
4
  a. Option name for the file-loader and url-loader (todo reference)
5
- b. Option publicPath for the output (todo reference)
5
+ b. Option publicPath for the output (todo reference)
6
6
 
7
7
 
8
8
 
@@ -39,13 +39,13 @@ const assetLoaderRules = [
39
39
 
40
40
 
41
41
 
42
- A full example can be found at [spec/dummy/client/app/components/ImageExample/ImageExample.jsx](../../spec/dummy/client/app/components/ImageExample/ImageExample.jsx)
42
+ A full example can be found at [spec/dummy/client/app/components/ImageExample/ImageExample.jsx](https://github.com/shakacode/react_on_rails/tree/master/spec/dummy/client/app/components/ImageExample/ImageExample.jsx)
43
43
 
44
- You are free to use images either in image tags or as background images in SCSS files. You can
44
+ You are free to use images either in image tags or as background images in SCSS files. You can
45
45
  use a "global" location of /client/app/assets/images or a relative path to your JS or SCSS file, as
46
46
  is done with CSS modules.
47
47
 
48
- **images** is a defined alias, so "images/foobar.jpg" would point to the file at
48
+ **images** is a defined alias, so "images/foobar.jpg" would point to the file at
49
49
  `/client/app/assets/images/foobar.jpg.`
50
50
 
51
51
  ```
@@ -55,4 +55,3 @@ is done with CSS modules.
55
55
  },
56
56
  },
57
57
  ```
58
-
File without changes
@@ -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](docs/tutorial.md).
9
+ * [Simple Tutorial](https://www.shakacode.com/react-on-rails/docs/guides/tutorial/).
10
10
 
11
11
  ## Videos
12
12
 
@@ -4,7 +4,7 @@ By Justin Gordon, January 26, 2016
4
4
 
5
5
  This document is an extension and complement to [The Rails Doctrine](http://rubyonrails.org/doctrine/). If you haven't read that document, I suggest you do so first.
6
6
 
7
- As stated in the [React on Rails README](../../README.md), the project objective is to provide an opinionated and optimal framework for integrating **Ruby on Rails** with modern JavaScript tooling and libraries. When considering what goes into **react_on_rails**, we ask ourselves, is the functionality related to the intersection of using Rails and with modern JavaScript? A good example is view helper integration of React components on a Rails view. If the answer is yes, then the functionality belongs right here. In other cases, we're releasing separate npm packages or Ruby gems. For example, we needed an easy way to integrate [Twitter Bootstrap](http://getbootstrap.com/) with Webpack, and we released the [npm bootstrap-loader](https://github.com/shakacode/bootstrap-loader/).
7
+ As stated in the [React on Rails README](https://www.shakacode.com/react-on-rails/docs/), the project objective is to provide an opinionated and optimal framework for integrating **Ruby on Rails** with modern JavaScript tooling and libraries. When considering what goes into **react_on_rails**, we ask ourselves, is the functionality related to the intersection of using Rails and with modern JavaScript? A good example is view helper integration of React components on a Rails view. If the answer is yes, then the functionality belongs right here. In other cases, we're releasing separate npm packages or Ruby gems. For example, we needed an easy way to integrate [Twitter Bootstrap](http://getbootstrap.com/) with Webpack, and we released the [npm bootstrap-loader](https://github.com/shakacode/bootstrap-loader/).
8
8
 
9
9
  Besides the project objective, let's stick with the "Rails Doctrine" and keep the following in mind.
10
10
 
@@ -19,14 +19,14 @@ 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 doc [Heroku Deployment](docs/basics/heroku-deployment.md).
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](../coding-style/style.md)
27
- * [linters](../contributor-info/linters.md)
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
- We're big believers in this quote from the Rails Doctrine:
29
+ We're big believers in this quote from the Rails Doctrine:
30
30
 
31
31
  > The same goes even when you understand how all the pieces go together. When there’s an obvious next step for every change, we can scoot through the many parts of an application that is the same or very similar to all the other applications that went before it. A place for everything and everything in its place. Constraints liberate even the most able minds.
32
32
 
File without changes
File without changes
@@ -0,0 +1,39 @@
1
+ # Deferred Rendering
2
+
3
+ Please see [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/] if you are interested in code splitting using
4
+ [loadable-components.com](https://loadable-components.com/docs) with React on Rails.
5
+
6
+ -----
7
+
8
+ What is code splitting? From the webpack documentation:
9
+
10
+ > For big web apps it’s not efficient to put all code into a single file, especially if some blocks of code are only required under some circumstances. Webpack has a feature to split your codebase into “chunks” which are loaded on demand. Some other bundlers call them “layers”, “rollups”, or “fragments”. This feature is called “code splitting”.
11
+
12
+ ## Server Rendering and Code Splitting
13
+
14
+ Let's say you're requesting a page that needs to fetch a code chunk from the server before it's able to render. If you do all your rendering on the client side, you don't have to do anything special. However, if the page is rendered on the server, you'll find that React will spit out the following error:
15
+
16
+ > Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server:
17
+
18
+ > (client) <!-- react-empty: 1 -
19
+
20
+ > (server) <div data-reactroot="
21
+ <!--This comment is here because the comment beginning on line 13 messes up Sublime's markdown parsing-->
22
+
23
+ Different markup is generated on the client than on the server. Why does this happen? When you register a component or Render-Function with `ReactOnRails.register`, React on Rails will by default render the component as soon as the page loads. However, code splitting requires that components render at a later time when the JavaScript chunks have loaded.
24
+
25
+ ## Solution
26
+
27
+ To prevent this, you have to wait until the code chunk is fetched before doing the initial render on the client side. To accomplish this, react on rails allows you to register a renderer. This works just like registering a Render-Function, except that the function you pass takes three arguments: `renderer(props, railsContext, domNodeId)`, and is responsible for calling `ReactDOM.render` or `ReactDOM.hydrate` to render the component to the DOM. React on rails will automatically detect when a Render-Function takes three arguments, and will **not** call `ReactDOM.render` or `ReactDOM.hydrate`, instead allowing you to control the initial render yourself. Note, you have to be careful to call `ReactDOM.hydrate` rather than `ReactDOM.render` if you are are server rendering.
28
+
29
+
30
+ ## Server vs. Client Code Caveats
31
+
32
+ If you're going to try to do code splitting with server rendered routes, you'll probably need to use seperate route definitions for client and server to prevent code splitting from happening for the server bundle. The server bundle should be one file containing all the JavaScript code. This will require you to have seperate webpack configurations for client and server.
33
+
34
+ Do not attempt to register a renderer function on the server. Instead, register either a Render-Function or a component. If you register a renderer in the server bundle, you'll get an error when react on rails tries to server render the component.
35
+
36
+
37
+ ## React on Rails Pro
38
+ [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/] includes a complete setup using this technique for code splitting using
39
+ [loadable-components.com](https://loadable-components.com/docs) with React on Rails.
@@ -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](docs/outdated/rails-assets.md) 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
 
@@ -179,7 +179,7 @@ module.exports = {
179
179
  // The important stuff
180
180
  test: /\.(jpg|jpeg|png)(\?.*)?$/, // Load only .jpg .jpeg, and .png files
181
181
  use: {
182
- loader: 'file-loader',
182
+ loader: 'file-loader',
183
183
  options: {
184
184
  name: '[name][md5:hash].[ext]', // Name of bundled asset
185
185
  outputPath: 'webpack-assets/', // Output location for assets. Final: `app/assets/webpack/webpack-assets/`
@@ -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](docs/outdated/rails-assets.md).
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/).
@@ -13,24 +13,24 @@ CSS and fonts for CSS. However, this applies to any file that might be processed
13
13
  Webpack file loader.
14
14
 
15
15
  ## The Problem
16
- To understand the problem, it helps to read this article:
16
+ To understand the problem, it helps to read this article:
17
17
  [What is fingerprinting and why should I care](http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark)
18
18
  Basically, when Rails prepares assets for production deployments, it also adds a digest
19
- to the file names. E.g., `img1.jpg` becomes `img1-dbu097452jf2v2.jpg`.
19
+ to the file names. E.g., `img1.jpg` becomes `img1-dbu097452jf2v2.jpg`.
20
20
 
21
- When compiling its native css Rails transforms all urls and links to digested
22
- versions, i.e. `background-image: image-url(img1.jpg)` becomes
23
- `background-image: url(img1-dbu097452jf2v2.jpg)`. However this doesn't happen for js and
24
- css files compiled by webpack on the client side, because they don't use
21
+ When compiling its native css Rails transforms all urls and links to digested
22
+ versions, i.e. `background-image: image-url(img1.jpg)` becomes
23
+ `background-image: url(img1-dbu097452jf2v2.jpg)`. However this doesn't happen for js and
24
+ css files compiled by webpack on the client side, because they don't use
25
25
  `image-url` and `asset-url`. Without some fix, these assets would fail to load.
26
26
 
27
- When Webpack's client JavaScript uses images in render methods, e.g. `<img src='...' />` or
27
+ When Webpack's client JavaScript uses images in render methods, e.g. `<img src='...' />` or
28
28
  in css, e.g. `background-image: url(...)` The code (such as the CSS) generated by the Webpack
29
29
  will have the Webpack digested name (MD5 hash). Since the Webpack generated CSS expects
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](../additional-reading/rails-assets-relative-paths.md)._
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
@@ -1,9 +1,9 @@
1
1
  # Rails 3
2
2
 
3
- * Please let us know if you find any issues with Rails 3.
3
+ * Please let us know if you find any issues with Rails 3.
4
4
  * Rails 3 is confirmed to work up with versions up to 6.8.x.
5
5
  * We are not testing it for new releases. If you find an issue, you will have to submit a PR to get it fixed.
6
6
 
7
7
  ## Known Issues
8
8
 
9
- 1. If you do not skip bootstrap for the generator, you cannot generate a working app, as bootstrap-sass does not not support Rails 3, or at least the version we're using.
9
+ 1. If you do not skip bootstrap for the generator, you cannot generate a working app, as bootstrap-sass does not support Rails 3, or at least the version we're using.
@@ -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](../basics/installation-into-an-existing-rails-app.md).*
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
 
@@ -1,4 +1,15 @@
1
- # Turbolinks
1
+ # Turbolinks and Turbo
2
+
3
+ ## Updated to support Turbo
4
+ * See [PR 1374](https://github.com/shakacode/react_on_rails/pull/1374).
5
+ * Ability to use with Turbo (@hotwired/turbo), as Turbolinks gets obsolete.
6
+
7
+ To configure turbo the following option can be set:
8
+ `ReactOnRails.setOptions({ turbo: true })`
9
+
10
+ Turbo is not auto-detected like older Turbolinks.
11
+
12
+ *Below docs maybe outdated*
2
13
 
3
14
  * See [Turbolinks on Github](https://github.com/rails/turbolinks)
4
15
  * React on Rails currently supports 2.5.x of Turbolinks and 5.0.0 of Turbolinks 5.
@@ -73,6 +84,7 @@ To turn on tracing of Turbolinks events, put this in your registration file, whe
73
84
  ```js
74
85
  ReactOnRails.setOptions({
75
86
  traceTurbolinks: true,
87
+ turbo: true,
76
88
  });
77
89
  ```
78
90
 
@@ -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](./hvmn.md)
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](./hvmn.md).
6
+ Full writeup [here](https://www.shakacode.com/react-on-rails/docs/testimonials/hvmn/).
7
7
 
8
8
  ---
9
9
 
10
- # [Leora from ResortPass](./resortpass.md), December 10, 2018
10
+ # [Leora from ResortPass](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass/), December 10, 2018
11
11
 
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.
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](./testimonials/resortpass.md).
14
+ Full writeup [here](https://www.shakacode.com/react-on-rails/docs/testimonials/resortpass/).
15
15
 
16
16
  ---
17
17
 
@@ -25,4 +25,4 @@ From Kyle Maune of Cooper Aerial, May 4, 2018
25
25
 
26
26
  ![image](https://user-images.githubusercontent.com/1118459/40891236-9b0b406e-671d-11e8-80ee-c026dbd1d5a2.png)
27
27
 
28
- For more testimonials, see [Live Projects](PROJECTS.md) and [Kudos](KUDOS.md).
28
+ 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).
@@ -132,7 +132,7 @@ module ReactOnRails
132
132
  # From https://github.com/rails/rails/blob/4c940b2dbfb457f67c6250b720f63501d74a45fd/railties/lib/rails/generators/rails/app/app_generator.rb
133
133
  def app_name
134
134
  @app_name ||= (defined_app_const_base? ? defined_app_name : File.basename(destination_root))
135
- .tr('\\', "").tr(". ", "_")
135
+ .tr("\\", "").tr(". ", "_")
136
136
  end
137
137
 
138
138
  def defined_app_name
@@ -25,7 +25,7 @@ module ReactOnRails
25
25
  end
26
26
 
27
27
  def copy_tests
28
- %w[spec/features/hello_world_spec.rb].each { |file| copy_file(file) }
28
+ %w[spec/system/hello_world_spec.rb].each { |file| copy_file(file) }
29
29
  end
30
30
 
31
31
  def add_test_related_gems_to_gemfile
@@ -13,7 +13,6 @@ require_relative "spec_helper"
13
13
  require "rspec/rails"
14
14
  require "capybara/rspec"
15
15
  require "capybara/rails"
16
- Capybara.javascript_driver = :selenium_chrome
17
16
  Capybara.register_driver :selenium_chrome do |app|
18
17
  options = Selenium::WebDriver::Chrome::Options.new
19
18
  options.add_argument("--headless")
@@ -41,6 +40,10 @@ end
41
40
  # ActiveRecord::Migration.maintain_test_schema!
42
41
 
43
42
  RSpec.configure do |config|
43
+ config.before(:each, type: :system, js: true) do
44
+ driven_by :selenium_chrome
45
+ end
46
+
44
47
  # Ensure that if we are running js tests, we are using latest webpack assets
45
48
  # This will use the defaults of :js and :server_rendering meta tags
46
49
  ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
@@ -2,8 +2,8 @@
2
2
 
3
3
  require_relative "../rails_helper"
4
4
 
5
- feature "Hello World", js: true do
6
- scenario "the hello world example works" do
5
+ describe "Hello World", js: true do
6
+ it "the hello world example works" do
7
7
  visit "/hello_world"
8
8
  expect(heading).to have_text("Hello World")
9
9
  expect(message).to have_text("Stranger")
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # rubocop:disable Metrics/ModuleLength
4
+ # rubocop:disable Metrics/MethodLength
4
5
  # NOTE:
5
6
  # For any heredoc JS:
6
7
  # 1. The white spacing in this file matters!
@@ -182,7 +183,7 @@ module ReactOnRails
182
183
  # Helper method to take javascript expression and returns the output from evaluating it.
183
184
  # If you have more than one line that needs to be executed, wrap it in an IIFE.
184
185
  # JS exceptions are caught and console messages are handled properly.
185
- # Options include:{ prerender:, trace:, raise_on_prerender_error: }
186
+ # Options include:{ prerender:, trace:, raise_on_prerender_error:, throw_js_errors: }
186
187
  def server_render_js(js_expression, options = {})
187
188
  render_options = ReactOnRails::ReactComponent::RenderOptions
188
189
  .new(react_component_name: "generic-js", options: options)
@@ -192,6 +193,8 @@ module ReactOnRails
192
193
  var htmlResult = '';
193
194
  var consoleReplayScript = '';
194
195
  var hasErrors = false;
196
+ var renderingError = null;
197
+ var renderingErrorObject = {};
195
198
 
196
199
  try {
197
200
  htmlResult =
@@ -199,9 +202,17 @@ module ReactOnRails
199
202
  return #{js_expression};
200
203
  })();
201
204
  } catch(e) {
205
+ renderingError = e;
206
+ if (#{render_options.throw_js_errors}) {
207
+ throw e;
208
+ }
202
209
  htmlResult = ReactOnRails.handleError({e: e, name: null,
203
210
  jsCode: '#{escape_javascript(js_expression)}', serverSide: true});
204
211
  hasErrors = true;
212
+ renderingErrorObject = {
213
+ message: renderingError.message,
214
+ stack: renderingError.stack,
215
+ }
205
216
  }
206
217
 
207
218
  consoleReplayScript = ReactOnRails.buildConsoleReplay();
@@ -209,7 +220,8 @@ module ReactOnRails
209
220
  return JSON.stringify({
210
221
  html: htmlResult,
211
222
  consoleReplayScript: consoleReplayScript,
212
- hasErrors: hasErrors
223
+ hasErrors: hasErrors,
224
+ renderingError: renderingErrorObject
213
225
  });
214
226
 
215
227
  })()
@@ -255,8 +267,13 @@ module ReactOnRails
255
267
  i18nLocale: I18n.locale,
256
268
  i18nDefaultLocale: I18n.default_locale,
257
269
  rorVersion: ReactOnRails::VERSION,
270
+ # TODO: v13 just use the version if existing
258
271
  rorPro: ReactOnRails::Utils.react_on_rails_pro?
259
272
  }
273
+ if ReactOnRails::Utils.react_on_rails_pro?
274
+ result[:rorProVersion] = ReactOnRails::Utils.react_on_rails_pro_version
275
+ end
276
+
260
277
  if defined?(request) && request.present?
261
278
  # Check for encoding of the request's original_url and try to force-encoding the
262
279
  # URLs as UTF-8. This situation can occur in browsers that do not encode the
@@ -519,6 +536,13 @@ module ReactOnRails
519
536
 
520
537
  controller.is_a?(ActionMailer::Base)
521
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
522
545
  end
523
546
  end
524
547
  # rubocop:enable Metrics/ModuleLength
548
+ # rubocop:enable Metrics/MethodLength
@@ -54,15 +54,13 @@ module ReactOnRails
54
54
  end
55
55
 
56
56
  def locale_files
57
- @locale_files ||= begin
58
- if i18n_yml_dir.present?
59
- Dir["#{i18n_yml_dir}/**/*.yml"]
60
- else
61
- ReactOnRails::Utils.truthy_presence(
62
- Rails.application && Rails.application.config.i18n.load_path
63
- ).presence
64
- end
65
- end
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
66
64
  end
67
65
 
68
66
  def i18n_dir