react_on_rails_pro 16.2.0.beta.20 → 16.2.0.rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -1
  3. data/CONTRIBUTING.md +64 -43
  4. data/Gemfile.lock +4 -4
  5. data/README.md +1 -1
  6. data/docs/bundle-caching.md +22 -8
  7. data/docs/caching.md +39 -27
  8. data/docs/code-splitting-loadable-components.md +2 -2
  9. data/docs/code-splitting.md +74 -70
  10. data/docs/configuration.md +6 -6
  11. data/docs/contributors-info/onboarding-customers.md +2 -1
  12. data/docs/contributors-info/releasing.md +1 -0
  13. data/docs/contributors-info/style.md +23 -15
  14. data/docs/home-pro.md +33 -15
  15. data/docs/installation.md +51 -2
  16. data/docs/js-memory-leaks.md +2 -3
  17. data/docs/node-renderer/debugging.md +5 -1
  18. data/docs/node-renderer/error-reporting-and-tracing.md +27 -15
  19. data/docs/node-renderer/heroku.md +4 -5
  20. data/docs/profiling-server-side-rendering-code.md +43 -42
  21. data/docs/react-server-components/add-streaming-and-interactivity.md +1 -1
  22. data/docs/react-server-components/create-without-ssr.md +18 -18
  23. data/docs/react-server-components/glossary.md +22 -3
  24. data/docs/react-server-components/how-react-server-components-work.md +25 -18
  25. data/docs/react-server-components/inside-client-components.md +19 -18
  26. data/docs/react-server-components/purpose-and-benefits.md +24 -14
  27. data/docs/react-server-components/rendering-flow.md +7 -3
  28. data/docs/react-server-components/server-side-rendering.md +23 -22
  29. data/docs/release-notes/4.0.md +103 -94
  30. data/docs/release-notes/v4-react-server-components.md +16 -16
  31. data/docs/streaming-server-rendering.md +2 -4
  32. data/docs/troubleshooting.md +5 -2
  33. data/docs/updating.md +49 -13
  34. data/lib/react_on_rails_pro/request.rb +18 -3
  35. data/lib/react_on_rails_pro/version.rb +1 -1
  36. data/rakelib/dummy_apps.rake +4 -4
  37. data/rakelib/lint.rake +1 -1
  38. data/rakelib/run_rspec.rake +3 -3
  39. metadata +4 -4
@@ -1,33 +1,41 @@
1
1
  # Code Style
2
+
2
3
  This document describes the coding style of [ShakaCode](http://www.shakacode.com). Yes, it's opinionated, as all style guidelines should be. We shall put as little as possible into this guide and instead rely on:
3
4
 
4
- * Use of linters with our standard linter configuration.
5
- * References to existing style guidelines that support the linter configuration.
6
- * Anything additional goes next.
5
+ - Use of linters with our standard linter configuration.
6
+ - References to existing style guidelines that support the linter configuration.
7
+ - Anything additional goes next.
7
8
 
8
9
  ## Client Side JavaScript and React
9
- * See the [Shakacode JavaScript Style Guide](https://github.com/shakacode/style-guide-javascript)
10
+
11
+ - See the [Shakacode JavaScript Style Guide](https://github.com/shakacode/style-guide-javascript)
10
12
 
11
13
  ## Style Guides to Follow
14
+
12
15
  Follow these style guidelines per the linter configuration. Basically, lint your code and if you have questions about the suggested fixes, look here:
13
16
 
14
17
  ### Ruby Coding Standards
15
- * [ShakaCode Ruby Coding Standards](https://github.com/shakacode/style-guide-ruby)
16
- * [Ruby Documentation](http://guides.rubyonrails.org/api_documentation_guidelines.html)
18
+
19
+ - [ShakaCode Ruby Coding Standards](https://github.com/shakacode/style-guide-ruby)
20
+ - [Ruby Documentation](http://guides.rubyonrails.org/api_documentation_guidelines.html)
17
21
 
18
22
  ### JavaScript Coding Standards
19
- * [ShakaCode Javascript](https://github.com/shakacode/style-guide-javascript)
20
- * Use the [eslint-config-shakacode](https://github.com/shakacode/style-guide-javascript/tree/master/packages/eslint-config-shakacode) npm package with eslint.
21
- * [JSDoc](http://usejsdoc.org/)
23
+
24
+ - [ShakaCode Javascript](https://github.com/shakacode/style-guide-javascript)
25
+ - Use the [eslint-config-shakacode](https://github.com/shakacode/style-guide-javascript/tree/master/packages/eslint-config-shakacode) npm package with eslint.
26
+ - [JSDoc](http://usejsdoc.org/)
22
27
 
23
28
  ### Git coding Standards
24
- * [Git Coding Standards](http://chlg.co/1GV2m9p)
29
+
30
+ - [Git Coding Standards](http://chlg.co/1GV2m9p)
25
31
 
26
32
  ### Sass Coding Standards
27
- * [Sass Guidelines](http://sass-guidelin.es/) by [Hugo Giraudel](http://hugogiraudel.com/)
28
- * [Github Front End Guidelines](http://primercss.io/guidelines/)
33
+
34
+ - [Sass Guidelines](http://sass-guidelin.es/) by [Hugo Giraudel](http://hugogiraudel.com/)
35
+ - [GitHub Front End Guidelines](http://primercss.io/guidelines/)
29
36
 
30
37
  # Git Usage
31
- * Follow a github-flow model where you branch off of master for features.
32
- * Before merging a branch to master, rebase it on top of master, by using command like `git fetch; git checkout my-branch; git rebase -i origin/master`. Clean up your commit message at this point. Be super careful to communicate with anybody else working on this branch and do not do this when others have uncommitted changes. Ideally, your merge of your feature back to master should be one nice commit.
33
- * Run hosted CI and code coverage.
38
+
39
+ - Follow a github-flow model where you branch off of master for features.
40
+ - Before merging a branch to master, rebase it on top of master, by using command like `git fetch; git checkout my-branch; git rebase -i origin/master`. Clean up your commit message at this point. Be super careful to communicate with anybody else working on this branch and do not do this when others have uncommitted changes. Ideally, your merge of your feature back to master should be one nice commit.
41
+ - Run hosted CI and code coverage.
data/docs/home-pro.md CHANGED
@@ -3,67 +3,77 @@
3
3
  Node rendering and caching performance enhancements for [React on Rails](https://github.com/shakacode/react_on_rails). Now supports React 18 with updates to React on Rails! Check the [React on Rails CHANGELOG.md](https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md) for details and the updates to the [loadable-components instructions](https://github.com/shakacode/react_on_rails_pro/blob/master/docs/code-splitting-loadable-components.md).
4
4
 
5
5
  ## Getting Started
6
+
6
7
  The best way to see how React on Rails Pro works is to install this repo locally and take a look at
7
8
  the example application:
8
9
 
9
- [spec/dummy](https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/README.md)
10
+ [spec/dummy](https://github.com/shakacode/react_on_rails/blob/master/react_on_rails/spec/dummy/README.md)
11
+
10
12
  1. Uses a @rails/webpacker standard configuration.
11
13
  1. Has pages that demonstrate:
12
14
  1. caching
13
15
  2. loadable-components
14
- 1. Has all the basic react_on_rails specs that run against the Node Renderer
16
+ 1. Has all the basic react_on_rails specs that run against the Node Renderer
15
17
  1. Demonstrates using HMR and loadable-components with almost the same example that is present in [loadable-components for SSR](https://github.com/gregberge/loadable-components/tree/main/examples/server-side-rendering)
16
-
18
+
17
19
  See the README.md in those sample apps for more details.
18
20
 
19
21
  ## Features
20
22
 
21
23
  ### 🚀 Next-Gen Server Rendering: Streaming with React 18's Latest APIs
24
+
22
25
  React on Rails Pro supports React 18's Streaming Server-Side Rendering, allowing you to progressively render and stream HTML content to the client. This enables faster page loads and better user experience.
23
26
 
24
27
  See [docs/streaming-server-rendering](./streaming-server-rendering.md) for more details.
25
28
 
26
29
  ### Caching
30
+
27
31
  Caching of SSR is critical for achieving optimum performance.
28
32
 
29
- * **Fragment Caching**: for `react_component` and `react_component_hash`, including lazy evaluation of props.
30
- * **Prerender Caching**: Server rendering JavaScript evaluation is cached if `prerender_caching` is turned on in your Rails config. This applies to all JavaScript evaluation methods.
33
+ - **Fragment Caching**: for `react_component` and `react_component_hash`, including lazy evaluation of props.
34
+ - **Prerender Caching**: Server rendering JavaScript evaluation is cached if `prerender_caching` is turned on in your Rails config. This applies to all JavaScript evaluation methods.
31
35
 
32
36
  See [docs/caching](./caching.md) for more details.
33
37
 
34
38
  ### Clearing of Global State
39
+
35
40
  Suppose you detect that some library used in server-rendering is leaking state between calls to server render. In that case, you can set the `config.ssr_pre_hook_js` in your `config/initializers/react_on_rails_pro.rb` to run some JavaScript to clear the globally leaked state at the beginning of each call to server render.
36
41
 
37
- For more details, see [Rails Configuration](https://github.com/shakacode/react_on_rails/blob/master/docs/configuration.md).
42
+ For more details, see [Rails Configuration](https://github.com/shakacode/react_on_rails/blob/master/docs/configuration/configuration.md).
38
43
 
39
44
  ### React On Rails Pro Node Renderer
45
+
40
46
  The "React on Rails Pro Node Renderer" provides more efficient server rendering on a standalone Node JS server.
41
47
  See the [Node Renderer Docs](./node-renderer/basics.md).
42
48
 
43
49
  ### Bundle Caching
50
+
44
51
  Don't wait for the same webpack bundles to be built over and over. See the [bundle-caching docs](./bundle-caching.md).
45
52
 
46
53
  ## Other Utility Methods
54
+
47
55
  See the [Ruby API](./ruby-api.md).
48
56
 
49
57
  ## References
50
58
 
51
- * [Installation](./installation.md)
52
- * [Streaming Server Rendering](./streaming-server-rendering.md)
53
- * [Caching](./caching.md)
54
- * [Rails Configuration](./configuration.md)
55
- * [Node Renderer Docs](./node-renderer/basics.md)
59
+ - [Installation](./installation.md)
60
+ - [Streaming Server Rendering](./streaming-server-rendering.md)
61
+ - [Caching](./caching.md)
62
+ - [Rails Configuration](./configuration.md)
63
+ - [Node Renderer Docs](./node-renderer/basics.md)
56
64
 
57
65
  # Features
66
+
58
67
  ## Code Splitting
59
68
 
60
69
  From [The Cost of JavaScript in 2018](https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4):
61
70
 
62
71
  > To stay fast, only load JavaScript needed for the current page. Prioritize what a user will need and lazy-load the rest with code-splitting. This gives you the best chance at loading and getting interactive fast. Stacks with route-based code-splitting by default are game-changers.
63
72
 
64
-
65
73
  ## Caching
74
+
66
75
  ### Server Rendering
76
+
67
77
  Server rendering of JavaScript evaluation is cached if `prerender_caching` is turned on in your Rails config. This applies to all JavaScript evaluation methods, including ExecJS and the Node VM Renderer.
68
78
 
69
79
  ### Pro: Fragment Caching
@@ -90,24 +100,31 @@ Note, even without server rendering (without step 3 above), fragment caching is
90
100
  See [Caching](./caching.md) for more additional details.
91
101
 
92
102
  ## React On Rails Pro Node React Render
103
+
93
104
  The "React on Rails Pro Node React Renderer" provides more efficient React Server Side Rendering on a standalone Node JS server.
94
105
 
95
106
  ### Overall Management Memory and CPU on both the Rendering and Ruby Servers
107
+
96
108
  A separate Node rendering server is easier to manage in terms of monitoring memory and CPU performance, allocating dynos, etc. This also makes it easier to manage the ruby servers, as you no longer have to consider the impact of starting an embedded V8. Thus, you can never hang your Ruby servers due to JavaScript memory leaks.
97
109
 
98
110
  ### Proper Node Tooling
111
+
99
112
  A disadvantage of Ruby embedded JavaScript (ExecJS) is that it precludes the use of standard Node tooling for doing things like profiling and tracking down memory leaks. With the renderer on a separate Node.js server, we were able to use node-memwatch (https://github.com/marcominetti/node-memwatch) to find few memory leaks in the Egghead React code.
100
113
 
101
114
  ### Caching of React Rendering
115
+
102
116
  To limit the load on the renderer server or embedded ExecJS, caching of React rendering requests can be enabled by a config setting. Because current React rendering requests are idempotent (same value regardless of calls), caching should be feasible for all server rendering calls. The current renderer does not allow any asynchronous calls to fetch data. The rendering request includes all data for rendering.
103
117
 
104
118
  ### Rolling Restart of Node Workers
119
+
105
120
  Due to poor performance and crashes due to memory leaks, the rolling restart of node workers was thus added as an option to the core rendering product. This option is cheap insurance against the renderer getting too slow from a memory leak due to a bug in some newly deployed JavaScript code.
106
121
 
107
122
  ### Docs
123
+
108
124
  See the [Node React Render Docs](./node-renderer/basics.md).
109
125
 
110
126
  ## Other Utility Methods
127
+
111
128
  See the [Ruby API](./ruby-api.md).
112
129
 
113
130
  # Testimonials
@@ -121,9 +138,10 @@ For details, see [Egghead React on Rails Pro Deployment Highlights](https://gith
121
138
 
122
139
  ## Why should I use React on Rails Pro if ExecJS seems to work?
123
140
 
124
- Caching is extremely useful to any server rendering you're doing, with or without ExecJS.
141
+ Caching is extremely useful to any server rendering you're doing, with or without ExecJS.
125
142
 
126
143
  React on Rails pro support caching at 2 levels:
144
+
127
145
  1. Caching of rendering request to ExecJS (or the Node renderer). This avoids extra calls to ExecJS.
128
146
  2. Fragment caching of server rendering. This avoids even the calculations of prop values from the database and the cost of converting the props to a string (lots of CPU there)
129
147
 
@@ -142,5 +160,5 @@ For more info, email [justin@shakacode.com](mailto:justin@shakacode.com).
142
160
 
143
161
  # References
144
162
 
145
- * [Caching](./caching.md)
146
- * [Rails Configuration](./configuration.md)
163
+ - [Caching](./caching.md)
164
+ - [Rails Configuration](./configuration.md)
data/docs/installation.md CHANGED
@@ -72,9 +72,58 @@ ReactOnRailsPro.configure do |config|
72
72
  end
73
73
  ```
74
74
 
75
- # Node Package Installation
75
+ # Client Package Installation
76
76
 
77
- **Note:** You only need to install the Node Package if you are using the standalone node renderer (`NodeRenderer`). If you're using `ExecJS` (the default), skip this section.
77
+ All React on Rails Pro users need to install the `react-on-rails-pro` npm package for client-side React integration.
78
+
79
+ ## Install react-on-rails-pro
80
+
81
+ ### Using npm:
82
+
83
+ ```bash
84
+ npm install react-on-rails-pro
85
+ ```
86
+
87
+ ### Using yarn:
88
+
89
+ ```bash
90
+ yarn add react-on-rails-pro
91
+ ```
92
+
93
+ ### Using pnpm:
94
+
95
+ ```bash
96
+ pnpm add react-on-rails-pro
97
+ ```
98
+
99
+ ## Usage
100
+
101
+ **Important:** Import from `react-on-rails-pro`, not `react-on-rails`. The Pro package re-exports everything from the core package plus Pro-exclusive features.
102
+
103
+ ```javascript
104
+ // Correct - use react-on-rails-pro
105
+ import ReactOnRails from 'react-on-rails-pro';
106
+
107
+ // Register components
108
+ ReactOnRails.register({ MyComponent });
109
+ ```
110
+
111
+ Pro-exclusive imports:
112
+
113
+ ```javascript
114
+ // React Server Components
115
+ import { RSCRoute } from 'react-on-rails-pro/RSCRoute';
116
+ import registerServerComponent from 'react-on-rails-pro/registerServerComponent/client';
117
+
118
+ // Async component loading
119
+ import { wrapServerComponentRenderer } from 'react-on-rails-pro/wrapServerComponentRenderer/client';
120
+ ```
121
+
122
+ See the [React Server Components tutorial](./react-server-components/tutorial.md) for detailed usage.
123
+
124
+ # Node Renderer Installation
125
+
126
+ **Note:** You only need to install the Node Renderer if you are using the standalone node renderer (`NodeRenderer`). If you're using `ExecJS` (the default), skip this section.
78
127
 
79
128
  ## Install react-on-rails-pro-node-renderer
80
129
 
@@ -1,11 +1,11 @@
1
1
  # JS Memory Leaks
2
2
 
3
3
  ## Finding Memory Leaks
4
+
4
5
  For memory leaks, see [node-memwatch](https://github.com/marcominetti/node-memwatch). Use the `—inspect` flag to make and compare heap snapshots.
5
6
 
6
7
  ## Causes of Memory Leaks
7
8
 
8
-
9
9
  ### Mobx (mobx-react)
10
10
 
11
11
  ```js
@@ -18,5 +18,4 @@ const App = (props, railsContext) => {
18
18
  useStaticRendering(true);
19
19
  ```
20
20
 
21
- * See details here: [Mobx site](https://github.com/mobxjs/mobx-react#server-side-rendering-with-usestaticrendering)
22
-
21
+ - See details here: [Mobx site](https://github.com/mobxjs/mobx-react#server-side-rendering-with-usestaticrendering)
@@ -1,12 +1,14 @@
1
1
  Because the renderer communicates over a port to the server, you can start a renderer instance in this repo and hack on it.
2
2
 
3
3
  # Yalc vs Yarn Link
4
+
4
5
  The project is setup to use [yalc](https://github.com/whitecolor/yalc). This means that at the top level
5
- directory, `yalc publish` will send the node package files to the global yalc store. Running `yarn` in the
6
+ directory, `yalc publish` will send the node package files to the global yalc store. Running `yarn` in the
6
7
  `/spec/dummy/client` directory will copy the files from the global yalc store over to the local `node_modules`
7
8
  directory.
8
9
 
9
10
  # Debugging the Node Renderer
11
+
10
12
  1. cd to the top level of the project.
11
13
  1. `yarn` to install any libraries.
12
14
  1. To compile renderer files on changes, open console and run `yarn build:dev`.
@@ -17,9 +19,11 @@ directory.
17
19
  1. Check out the top level nps task `nps renderer.debug` and `spec/dummy/package.json` which has script `"node-renderer-debug"`.
18
20
 
19
21
  ## Debugging using the Node debugger
22
+
20
23
  1. See [this article](https://github.com/shakacode/react_on_rails/issues/1196) on setting up the debugger.
21
24
 
22
25
  ## Debugging Jest tests
26
+
23
27
  1. See [the Jest documentation](https://jestjs.io/docs/troubleshooting) for overall guidance.
24
28
  2. For RubyMine, see [the RubyMine documentation](https://www.jetbrains.com/help/ruby/running-unit-tests-on-jest.html) for the current information. The original [Testing With Jest in WebStorm](https://blog.jetbrains.com/webstorm/2018/10/testing-with-jest-in-webstorm/) post can be useful as well.
25
29
 
@@ -13,8 +13,8 @@ It should initialize the services according to your requirements and then enable
13
13
  2. Call `Sentry.init` with the desired options according to [the documentation](https://docs.sentry.io/platforms/javascript/guides/fastify/configuration/).
14
14
  3. Then load the integration:
15
15
 
16
- ```js
17
- require('react-on-rails-pro-node-renderer/integrations/sentry').init();
16
+ ```js
17
+ require('react-on-rails-pro-node-renderer/integrations/sentry').init();
18
18
  ```
19
19
 
20
20
  - Use `react-on-rails-pro-node-renderer/integrations/sentry6` instead of `.../sentry` for versions of Sentry SDK older than 7.63.0.
@@ -22,12 +22,13 @@ It should initialize the services according to your requirements and then enable
22
22
 
23
23
  ### Sentry Tracing
24
24
 
25
- To enable Sentry Tracing:
25
+ To enable Sentry Tracing:
26
+
26
27
  1. Include `enableTracing`, `tracesSampleRate`, or `tracesSampler` in your `Sentry.init` call. See [the Sentry documentation](https://docs.sentry.io/platforms/javascript/tracing/) for details, but ignore `Sentry.browserTracingIntegration()`.
27
- 2. Depending on your Sentry SDK version:
28
- - if it is older than 7.63.0, install `@sentry/tracing` as well as `@sentry/node` (with the same exact version) and pass `integrations: [new Sentry.Integrations.Http({ tracing: true })]` to `Sentry.init`.
29
- - for newer v7.x.y, pass `integrations: Sentry.autoDiscoverNodePerformanceMonitoringIntegrations()`.
30
- - for v8.x.y, Node HTTP tracing is included by default.
28
+ 2. Depending on your Sentry SDK version:
29
+ - if it is older than 7.63.0, install `@sentry/tracing` as well as `@sentry/node` (with the same exact version) and pass `integrations: [new Sentry.Integrations.Http({ tracing: true })]` to `Sentry.init`.
30
+ - for newer v7.x.y, pass `integrations: Sentry.autoDiscoverNodePerformanceMonitoringIntegrations()`.
31
+ - for v8.x.y, Node HTTP tracing is included by default.
31
32
  3. Pass `{ tracing: true }` to the `init` function of the integration. It can be combined with `fastify: true`.
32
33
 
33
34
  ### Sentry Profiling
@@ -39,13 +40,14 @@ To enable Sentry Tracing:
39
40
  1. [Set up Honeybadger](https://docs.honeybadger.io/lib/javascript/integration/node/). Call `Honeybadger.configure` with the desired options in the configuration script.
40
41
  2. Then load the integration:
41
42
 
42
- ```js
43
- require('react-on-rails-pro-node-renderer/integrations/honeybadger').init();
44
- ```
43
+ ```js
44
+ require('react-on-rails-pro-node-renderer/integrations/honeybadger').init();
45
+ ```
45
46
 
46
- Use `init({ fastify: true })` to capture additional Fastify-related information.
47
+ Use `init({ fastify: true })` to capture additional Fastify-related information.
47
48
 
48
49
  ## Other services
50
+
49
51
  You can create your own integrations in the same way as the provided ones.
50
52
  If you have access to the React on Rails Pro repository,
51
53
  you can use [their implementations](https://github.com/shakacode/react_on_rails_pro/tree/master/packages/node-renderer/src/integrations) as examples.
@@ -57,13 +59,18 @@ Import these functions from `react-on-rails-pro-node-renderer/integrations/api`:
57
59
  - Use `addNotifier` if the service uses the same reporting function for both JavaScript `Error`s and string messages.
58
60
 
59
61
  For example, integrating with BugSnag can be as simple as
62
+
60
63
  ```js
61
64
  const Bugsnag = require('@bugsnag/js');
62
65
  const { addNotifier } = require('react-on-rails-pro-node-renderer/integrations/api');
63
66
 
64
- Bugsnag.start({ /* your options */ });
67
+ Bugsnag.start({
68
+ /* your options */
69
+ });
65
70
 
66
- addNotifier((msg) => { Bugsnag.notify(msg); });
71
+ addNotifier((msg) => {
72
+ Bugsnag.notify(msg);
73
+ });
67
74
  ```
68
75
 
69
76
  ### Tracing services
@@ -74,11 +81,14 @@ addNotifier((msg) => { Bugsnag.notify(msg); });
74
81
 
75
82
  To track requests as [sessions](https://docs.bugsnag.com/platforms/javascript/capturing-sessions/#startsession) in BugSnag 8.x+,
76
83
  the above example becomes
84
+
77
85
  ```js
78
86
  const Bugsnag = require('@bugsnag/js');
79
87
  const { addNotifier, setupTracing } = require('react-on-rails-pro-node-renderer/integrations/api');
80
88
 
81
- Bugsnag.start({ /* your options */ });
89
+ Bugsnag.start({
90
+ /* your options */
91
+ });
82
92
 
83
93
  addNotifier((msg) => {
84
94
  Bugsnag.notify(msg);
@@ -119,7 +129,9 @@ Bugsnag v7 is a bit more complicated:
119
129
  const Bugsnag = require('@bugsnag/js');
120
130
  const { addNotifier, setupTracing } = require('react-on-rails-pro-node-renderer/integrations/api');
121
131
 
122
- Bugsnag.start({ /* your options */ });
132
+ Bugsnag.start({
133
+ /* your options */
134
+ });
123
135
 
124
136
  addNotifier((msg, { bugsnag = Bugsnag }) => {
125
137
  bugsnag.notify(msg);
@@ -34,10 +34,12 @@ renderer: bin/node-renderer
34
34
  cd client
35
35
  yarn run node-renderer
36
36
  ```
37
+
37
38
  Be sure your script to run the node-renderer sets some port, like 3800 which is also set as the
38
39
  config.renderer_url for your Rails server.
39
40
 
40
41
  ### node-renderer
42
+
41
43
  Any task in client/package.json that starts the node-renderer
42
44
 
43
45
  ### Modifying Precompile Task
@@ -76,14 +78,13 @@ Errno::EADDRINUSE: Address already in use - bind(2) for "0.0.0.0" port 21752
76
78
  /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.3/lib/puma/binder.rb:229:in `initialize'
77
79
  ```
78
80
 
79
-
80
81
  ## Separate Rails and Node Render Instances
81
82
 
82
83
  ### Deploy Node renderer to Heroku
83
84
 
84
85
  1. Create your **Heroku** app with **Node.js** buildpack, say `renderer-test.herokuapp.com`.
85
86
  2. In your JS configuration file or
86
- 1. If setting the port, ensure the port uses `process.env.PORT` so it will use port number provided by **Heroku** environment. The default is to use the env value RENDERER_PORT if available. (*TODO: Need to check on this*)
87
+ 1. If setting the port, ensure the port uses `process.env.PORT` so it will use port number provided by **Heroku** environment. The default is to use the env value `RENDERER_PORT` if available.
87
88
  2. Set password in your configuration to something like `process.env.RENDERER_PASSWORD` and configure the corresponding **ENV variable** on your **Heroku** dyno so the `config/initializers/react_on_rails_pro.rb` uses this value.
88
89
  3. Run deployment process (usually by pushing changes to **Git** repo associated with created **Heroku** app).
89
90
  4. Once deployment process is finished, renderer should start listening from something like `renderer-test.herokuapp.com` host.
@@ -95,8 +96,6 @@ Errno::EADDRINUSE: Address already in use - bind(2) for "0.0.0.0" port 21752
95
96
  3. Run deployment process (usually by pushing changes to **Git** repo associated with created **Heroku** app).
96
97
  4. Once deployment process is finished, all rendering requests form your `react_on_rails` app should be served by `<your-heroku-app>.herokuapp.com` app via **HTTPS**.
97
98
 
98
-
99
-
100
99
  ## References
101
100
 
102
- * [Heroku Node Settings](https://github.com/damianmr/heroku-node-settings)
101
+ - [Heroku Node Settings](https://github.com/damianmr/heroku-node-settings)
@@ -7,53 +7,53 @@ This guide uses the RORP dummy app in profiling the server-side code.
7
7
  ## Profiling Server-Side Code Running On Node Renderer
8
8
 
9
9
  1. Run node-renderer using the `--inspect` node option.
10
-
11
- Open the `spec/dummy/Procfile.dev` file and update the `node-renderer` process to run the renderer using `node --inspect` command. Change the following line
12
-
13
- ```bash
14
- node-renderer: RENDERER_LOG_LEVEL=debug yarn run node-renderer
15
- ```
16
-
17
- To
18
-
19
- ```bash
20
- node-renderer: RENDERER_LOG_LEVEL=debug RENDERER_PORT=3800 node --inspect client/node-renderer.js
21
- ```
10
+
11
+ Open the `spec/dummy/Procfile.dev` file and update the `node-renderer` process to run the renderer using `node --inspect` command. Change the following line
12
+
13
+ ```bash
14
+ node-renderer: RENDERER_LOG_LEVEL=debug yarn run node-renderer
15
+ ```
16
+
17
+ To
18
+
19
+ ```bash
20
+ node-renderer: RENDERER_LOG_LEVEL=debug RENDERER_PORT=3800 node --inspect client/node-renderer.js
21
+ ```
22
22
 
23
23
  1. Run the App
24
-
25
- ```bash
26
- bin/dev
27
- ```
24
+
25
+ ```bash
26
+ bin/dev
27
+ ```
28
28
 
29
29
  1. Visit `chrome://inspect` on Chrome browser and you should see something like this:
30
-
31
- ![Chrome Inspect Tab](https://github.com/shakacode/react_on_rails_pro/assets/7099193/2a64660f-9381-4bbb-b385-318aa833389d)
30
+
31
+ ![Chrome Inspect Tab](https://github.com/shakacode/react_on_rails_pro/assets/7099193/2a64660f-9381-4bbb-b385-318aa833389d)
32
32
 
33
33
  1. Click the `inspect` link. This should open a developer tools window. Open the performance tab there
34
-
35
- ![Chrome Performance Tab](https://github.com/shakacode/react_on_rails_pro/assets/7099193/ddf572bd-182f-4911-bb8f-4bafa4ec1034)
34
+
35
+ ![Chrome Performance Tab](https://github.com/shakacode/react_on_rails_pro/assets/7099193/ddf572bd-182f-4911-bb8f-4bafa4ec1034)
36
36
 
37
37
  1. Click the `record` button
38
-
39
- ![Chrome Performance Tab](https://github.com/shakacode/react_on_rails_pro/assets/7099193/20848091-d446-4690-988b-09db59ddf9e0)
38
+
39
+ ![Chrome Performance Tab](https://github.com/shakacode/react_on_rails_pro/assets/7099193/20848091-d446-4690-988b-09db59ddf9e0)
40
40
 
41
41
  1. Open the web app you want to test and refresh it multiple times. We use the React on Rails Pro dummy app for this tutorial. So, we will open it in the browser by going to [http://localhost:3000](http://localhost:3000)
42
-
43
- ![RORP Dummy App](https://github.com/shakacode/react_on_rails_pro/assets/7099193/8dc1ef3d-62e4-492d-a5b4-c693b7f7e08c)
42
+
43
+ ![RORP Dummy App](https://github.com/shakacode/react_on_rails_pro/assets/7099193/8dc1ef3d-62e4-492d-a5b4-c693b7f7e08c)
44
44
 
45
45
  1. If you get any `Timeout Error` while visiting the page, you may need to increase the `ssr_timeout` in the Ruby on Rails initializer file. **Running node-renderer** using the `--inspect` flag makes it slower. So, you can increase the `ssr_timeout` to `10 seconds` by adding the following line to `config/initializers/react_on_rails_pro.rb` file
46
-
47
- ```ruby
48
- config.ssr_timeout = 10
49
- ```
46
+
47
+ ```ruby
48
+ config.ssr_timeout = 10
49
+ ```
50
50
 
51
51
  1. Stop performance recording
52
-
53
- ![Running profiler at the performance tab](https://github.com/shakacode/react_on_rails_pro/assets/7099193/bc02bbd6-3358-4edf-ba3a-36e11620a096)
52
+
53
+ ![Running profiler at the performance tab](https://github.com/shakacode/react_on_rails_pro/assets/7099193/bc02bbd6-3358-4edf-ba3a-36e11620a096)
54
54
 
55
55
  1. You should see something like this
56
-
56
+
57
57
  ![Recorded Node JS profile](https://github.com/shakacode/react_on_rails_pro/assets/7099193/6dc098bb-9f07-49be-9a1f-2149f6712631)
58
58
 
59
59
  ## Profile Analysis
@@ -89,24 +89,25 @@ config.prerender_caching = false
89
89
  To see the renderer behavior while there are many requests coming to it, you can use the `ApacheBench (ab)` tool that lets you make many HTTP requests to a specific end points at the same time.
90
90
 
91
91
  1. The `ApacheBench (ab)` is installed on macOS by default. You can install it on Linux by running the following command
92
-
93
- ```bash
94
- sudo apt-get install apache2-utils
95
- ```
92
+
93
+ ```bash
94
+ sudo apt-get install apache2-utils
95
+ ```
96
96
 
97
97
  1. Do all steps in `Profiling Server-Side Code Running On Node Renderer` section except the step number 6. Instead of opening the page in the browser, let the `ab` tool make many HTTP requests for you by running the following command.
98
-
99
- ```bash
100
- ab -n 100 -c 10 http://localhost:3000/
101
- ```
102
98
 
103
- 1. Now, we you open the noder-renderer profile, you will see it very busy responding to all requests
104
-
105
- ![Busy renderer profile](https://github.com/shakacode/react_on_rails_pro/assets/7099193/2ce69bf2-45ee-4a9d-af33-37e20aed86bc)
99
+ ```bash
100
+ ab -n 100 -c 10 http://localhost:3000/
101
+ ```
102
+
103
+ 1. Now, when you open the node-renderer profile, you will see it very busy responding to all requests
104
+
105
+ ![Busy renderer profile](https://github.com/shakacode/react_on_rails_pro/assets/7099193/2ce69bf2-45ee-4a9d-af33-37e20aed86bc)
106
106
 
107
107
  1. Then, you can analyze the renderer behavior of each request as stated in `Profile Analysis` section.
108
108
 
109
109
  ### ExecJS
110
+
110
111
  React on Rails Pro supports profiling with ExecJS starting from version **4.0.0**. You will need to do more work to profile ExecJS if you are using an older version.
111
112
 
112
113
  If you are using **v4.0.0** or later, you can enable the profiler by setting the `profile_server_rendering_js_code` config by adding the following line to the ReactOnRails initializer.
@@ -3,6 +3,7 @@
3
3
  Before reading this document, please read the [Create React Server Component without SSR](./create-without-ssr.md) document.
4
4
 
5
5
  ## Make the React Server Component Page Progressively Load
6
+
6
7
  React Server Components support progressive loading, which means they can be built as asynchronous functions that resolve and render after the initial HTML is sent to the client. This enables a better user experience by:
7
8
 
8
9
  1. Showing initial content quickly while async data loads;
@@ -163,7 +164,6 @@ It's important to note that while client components (like `ToggleContainer`) can
163
164
 
164
165
  This pattern allows us to optimize performance by keeping most of the component logic on the server while selectively adding interactivity where needed on the client.
165
166
 
166
-
167
167
  ## Checking The Network Requests
168
168
 
169
169
  Let's check what bundles are being loaded for this page. By opening the browser's developer tools and going to the "Network" tab, you can see JavaScript bundles being loaded for this page.