react-on-rails 12.4.0 → 12.6.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.
- package/CHANGELOG.md +32 -2
- package/README.md +22 -12
- package/node_package/lib/ReactOnRails.js +4 -3
- package/node_package/lib/clientStartup.js +6 -3
- package/node_package/lib/reactHydrate.d.ts +2 -0
- package/node_package/lib/reactHydrate.js +15 -0
- package/node_package/lib/reactRender.d.ts +2 -0
- package/node_package/lib/reactRender.js +18 -0
- package/node_package/lib/supportsReactCreateRoot.d.ts +2 -0
- package/node_package/lib/supportsReactCreateRoot.js +8 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -17,6 +17,31 @@ Changes since last non-beta release.
|
|
|
17
17
|
|
|
18
18
|
*Please add entries here for your pull requests that are not yet released.*
|
|
19
19
|
|
|
20
|
+
### [12.6.0] - 2022-01-22
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- A `rendering_props_extension` configuration which takes a module with an `adjust_props_for_client_side_hydration` method, which is used to process props differently for server/client if `prerender` is set to `true`. [PR 1413](https://github.com/shakacode/react_on_rails/pull/1413) by [gscarv13](https://github.com/gscarv13) & [judahmeek](https://github.com/judahmeek).
|
|
24
|
+
|
|
25
|
+
### [12.5.2] - 2021-12-29
|
|
26
|
+
### Fixed
|
|
27
|
+
- Usage of config.build_production_command for custom command for production builds fixed. [PR 1415](https://github.com/shakacode/react_on_rails/pull/1415) by [judahmeek](https://github.com/judahmeek).
|
|
28
|
+
|
|
29
|
+
### [12.5.1] - 2021-12-27
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
- A fatal server rendering error if running an ReactOnRails >=12.4.0 with ReactOnRails Pro <2.4.0. [PR 1412](https://github.com/shakacode/react_on_rails/pull/1412) by [judahmeek](https://github.com/judahmeek).
|
|
33
|
+
|
|
34
|
+
### [12.5.0] - 2021-12-26
|
|
35
|
+
|
|
36
|
+
#### Added
|
|
37
|
+
- Support for React 18, including the changed SSR API. [PR 1409](https://github.com/shakacode/react_on_rails/pull/1409) by [kylemellander](https://github.com/kylemellander).
|
|
38
|
+
- Added webpack configuration files as part of the generator and updated webpacker to version 6. [PR 1404](https://github.com/shakacode/react_on_rails/pull/1404) by [gscarv13](https://github.com/gscarv13).
|
|
39
|
+
- Supports Rails 7.
|
|
40
|
+
|
|
41
|
+
#### Changed
|
|
42
|
+
- Changed logic of determining the usage of the default rails/webpacker webpack config or a custom command to only check if the config.build_production_command is defined. [PR 1402](https://github.com/shakacode/react_on_rails/pull/1402)by [justin808](https://github.com/justin808) and [gscarv13](https://github.com/gscarv13).
|
|
43
|
+
- Minimimum required Ruby is 2.7 to match lastest rails/webpacker.
|
|
44
|
+
|
|
20
45
|
### [12.4.0] - 2021-09-22
|
|
21
46
|
#### Added
|
|
22
47
|
- ScoutAPM tracing support for server rendering [PR 1379](https://github.com/shakacode/react_on_rails/pull/1379) by [justin808](https://github.com/justin808).
|
|
@@ -82,7 +107,7 @@ invoked to return the React component. In that case, you won't need to pass any
|
|
|
82
107
|
[PR 1268](https://github.com/shakacode/react_on_rails/pull/1268) by [justin808](https://github.com/justin808)
|
|
83
108
|
|
|
84
109
|
See [docs/guides/upgrading-react-on-rails](https://www.shakacode.com/react-on-rails/docs/guides/upgrading-react-on-rails#upgrading-to-v12)
|
|
85
|
-
for details.
|
|
110
|
+
for details.
|
|
86
111
|
|
|
87
112
|
#### Other Updates
|
|
88
113
|
* `react_on_rails` fully supports `rails/webpacker`. The example test app in `spec/dummy` was recently converted over to use rails/webpacker v4+. It's a good example of how to leverage rails/webpacker's webpack configuration for server-side rendering.
|
|
@@ -974,7 +999,12 @@ Best done with Object destructing:
|
|
|
974
999
|
##### Fixed
|
|
975
1000
|
- Fix several generator related issues.
|
|
976
1001
|
|
|
977
|
-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.
|
|
1002
|
+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/12.6.0...master
|
|
1003
|
+
[12.6.0]: https://github.com/shakacode/react_on_rails/compare/12.5.2...12.6.0
|
|
1004
|
+
[12.5.2]: https://github.com/shakacode/react_on_rails/compare/12.5.1...12.5.2
|
|
1005
|
+
[12.5.1]: https://github.com/shakacode/react_on_rails/compare/12.5.0...12.5.1
|
|
1006
|
+
[12.5.0]: https://github.com/shakacode/react_on_rails/compare/12.4.0...12.5.0
|
|
1007
|
+
[12.4.0]: https://github.com/shakacode/react_on_rails/compare/12.3.0...12.4.0
|
|
978
1008
|
[12.3.0]: https://github.com/shakacode/react_on_rails/compare/12.2.0...12.3.0
|
|
979
1009
|
[12.2.0]: https://github.com/shakacode/react_on_rails/compare/12.1.0...12.2.0
|
|
980
1010
|
[12.1.0]: https://github.com/shakacode/react_on_rails/compare/12.0.4...12.1.0
|
package/README.md
CHANGED
|
@@ -11,6 +11,15 @@
|
|
|
11
11
|
|
|
12
12
|
[](LICENSE.md) [](https://travis-ci.org/shakacode/react_on_rails) [](https://badge.fury.io/rb/react_on_rails) [](https://badge.fury.io/js/react-on-rails) [](https://codeclimate.com/github/shakacode/react_on_rails) [](https://coveralls.io/github/shakacode/react_on_rails?branch=master) [](https://rubygems.org/gems/react_on_rails)
|
|
13
13
|
|
|
14
|
+
# News
|
|
15
|
+
* ShakaCode now maintains the official successor to `rails/webpacker`, [`shakapacker`](https://github.com/shakacode/shakapacker).
|
|
16
|
+
* Project is updated to support Rails 7!
|
|
17
|
+
* **React and Webpack with Ruby on Rails**: The current version of https://github.com/rails/webpacker will soon ship. While it won't be the default for Rails 7, it is not "deprecated." The core webpack configuration has become slimmer, allowing easier extension. If you want to get started today, use the master branch of [shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh) with `gem "webpacker", "6.0.0.rc.6"` Any updates to get to v6 from this point forward should be simple.
|
|
18
|
+
|
|
19
|
+
If you have time, please comment on Justin's final proposals for Webpacker v6: [webpacker/pulls/justin808](https://github.com/rails/webpacker/pulls/justin808).
|
|
20
|
+
|
|
21
|
+
-----
|
|
22
|
+
|
|
14
23
|
*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
24
|
|
|
16
25
|
#### About
|
|
@@ -18,20 +27,20 @@ React on Rails integrates Rails with (server rendering of) Facebook's [React](ht
|
|
|
18
27
|
|
|
19
28
|
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/).
|
|
20
29
|
|
|
21
|
-
|
|
30
|
+
Are you interested in optimizing your webpack setup for React on Rails including code
|
|
22
31
|
splitting with [react-router](https://github.com/ReactTraining/react-router#readme) and
|
|
23
32
|
[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/).
|
|
33
|
+
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/). Several years later, Popmenu is serving millions of SSR requests per day React on Rails.
|
|
25
34
|
|
|
26
|
-
|
|
35
|
+
Check out [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/). For more information, feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com), maintainer of React on Rails.
|
|
27
36
|
|
|
28
37
|
# Documentation
|
|
29
38
|
|
|
30
|
-
See the documentation at [shakacode.com/react-on-rails/docs](https://www.shakacode.com/react-on-rails/docs/)
|
|
39
|
+
See the documentation at **[shakacode.com/react-on-rails/docs](https://www.shakacode.com/react-on-rails/docs/)**.
|
|
31
40
|
|
|
32
41
|
## Project Objective
|
|
33
42
|
|
|
34
|
-
To provide a high performance framework for integrating Ruby on Rails with React via the [**Webpacker**](https://github.com/rails/webpacker) gem especially
|
|
43
|
+
To provide a high performance framework for integrating Ruby on Rails with React via the [**Webpacker**](https://github.com/rails/webpacker) gem, especially regarding React Server-Side Rendering for better SEO and improved performance.
|
|
35
44
|
|
|
36
45
|
## Features and Why React on Rails?
|
|
37
46
|
|
|
@@ -47,7 +56,9 @@ Given that `rails/webpacker` gem already provides basic React integration, why w
|
|
|
47
56
|
|
|
48
57
|
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
58
|
|
|
50
|
-
|
|
59
|
+
## Online demo
|
|
60
|
+
* See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
|
|
61
|
+
* A deployed version of the project `spec/dummy` which demonstrates several uses of `react_on_rails` is available on heroku [through this link](https://ror-spec-dummy.herokuapp.com/)
|
|
51
62
|
|
|
52
63
|
## ShakaCode Forum Premium Content
|
|
53
64
|
_Requires creating a free account._
|
|
@@ -55,20 +66,19 @@ _Requires creating a free account._
|
|
|
55
66
|
* [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
67
|
* [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)
|
|
57
68
|
|
|
58
|
-
|
|
59
69
|
## Prerequisites
|
|
60
70
|
|
|
61
|
-
Ruby on Rails >=5
|
|
71
|
+
Ruby on Rails >=5, rails/webpacker >= 4.2, Ruby >= 2.7
|
|
62
72
|
|
|
63
73
|
# Support
|
|
64
74
|
|
|
65
75
|
* [Click to join **React + Rails Slack**](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
|
|
66
76
|
- [**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.
|
|
67
|
-
-
|
|
77
|
+
- [Discussions](https://github.com/shakacode/react_on_rails/discussions): Post your questions regarding React on Rails
|
|
78
|
+
- **[forum.shakacode.com](https://forum.shakacode.com)**: Other discussions
|
|
68
79
|
- **[@railsonmaui on Twitter](https://twitter.com/railsonmaui)**
|
|
69
80
|
- *See [NEWS.md](https://github.com/shakacode/react_on_rails/tree/master/NEWS.md) for more notes over time.*
|
|
70
81
|
- 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.*
|
|
72
82
|
|
|
73
83
|
## Contributing
|
|
74
84
|
|
|
@@ -85,12 +95,12 @@ The following companies support this open source project, and ShakaCode uses the
|
|
|
85
95
|
[](https://www.honeybadger.io/)
|
|
86
96
|
[](https://statushero.com/)
|
|
87
97
|
|
|
88
|
-
ShakaCode's favorite project tracking tool is [
|
|
98
|
+
ShakaCode's favorite project tracking tool is [Shortcut](https://shortcut.com/). If you want to **try Shortcut 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!
|
|
89
99
|
|
|
90
100
|
Aloha and best wishes from Justin and the ShakaCode team!
|
|
91
101
|
|
|
92
102
|
# Work with Us
|
|
93
|
-
ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/career)** to work on our projects, including [HiChee](https://hichee.com)
|
|
103
|
+
ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/career)** to work on our projects, including [HiChee](https://hichee.com)!
|
|
94
104
|
|
|
95
105
|
# License
|
|
96
106
|
|
|
@@ -22,7 +22,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
var react_dom_1 = __importDefault(require("react-dom"));
|
|
26
25
|
var ClientStartup = __importStar(require("./clientStartup"));
|
|
27
26
|
var handleError_1 = __importDefault(require("./handleError"));
|
|
28
27
|
var ComponentRegistry_1 = __importDefault(require("./ComponentRegistry"));
|
|
@@ -32,6 +31,8 @@ var buildConsoleReplay_1 = __importDefault(require("./buildConsoleReplay"));
|
|
|
32
31
|
var createReactOutput_1 = __importDefault(require("./createReactOutput"));
|
|
33
32
|
var Authenticity_1 = __importDefault(require("./Authenticity"));
|
|
34
33
|
var context_1 = __importDefault(require("./context"));
|
|
34
|
+
var reactHydrate_1 = __importDefault(require("./reactHydrate"));
|
|
35
|
+
var reactRender_1 = __importDefault(require("./reactRender"));
|
|
35
36
|
var ctx = context_1.default();
|
|
36
37
|
if (ctx === undefined) {
|
|
37
38
|
throw new Error("The context (usually Window or NodeJS's Global) is undefined.");
|
|
@@ -173,9 +174,9 @@ ctx.ReactOnRails = {
|
|
|
173
174
|
render: function (name, props, domNodeId, hydrate) {
|
|
174
175
|
var componentObj = ComponentRegistry_1.default.get(name);
|
|
175
176
|
var reactElement = createReactOutput_1.default({ componentObj: componentObj, props: props, domNodeId: domNodeId });
|
|
176
|
-
var render = hydrate ?
|
|
177
|
+
var render = hydrate ? reactHydrate_1.default : reactRender_1.default;
|
|
177
178
|
// eslint-disable-next-line react/no-render-return-value
|
|
178
|
-
return render(
|
|
179
|
+
return render(document.getElementById(domNodeId), reactElement);
|
|
179
180
|
},
|
|
180
181
|
/**
|
|
181
182
|
* Get the component that you registered
|
|
@@ -12,6 +12,8 @@ exports.clientStartup = exports.reactOnRailsPageLoaded = void 0;
|
|
|
12
12
|
var react_dom_1 = __importDefault(require("react-dom"));
|
|
13
13
|
var createReactOutput_1 = __importDefault(require("./createReactOutput"));
|
|
14
14
|
var isServerRenderResult_1 = require("./isServerRenderResult");
|
|
15
|
+
var reactHydrate_1 = __importDefault(require("./reactHydrate"));
|
|
16
|
+
var reactRender_1 = __importDefault(require("./reactRender"));
|
|
15
17
|
var REACT_ON_RAILS_STORE_ATTRIBUTE = 'data-js-react-on-rails-store';
|
|
16
18
|
function findContext() {
|
|
17
19
|
if (typeof window.ReactOnRails !== 'undefined') {
|
|
@@ -108,7 +110,8 @@ function render(el, railsContext) {
|
|
|
108
110
|
return;
|
|
109
111
|
}
|
|
110
112
|
// Hydrate if available and was server rendered
|
|
111
|
-
|
|
113
|
+
// @ts-expect-error potentially present if React 18 or greater
|
|
114
|
+
var shouldHydrate = !!(react_dom_1.default.hydrate || react_dom_1.default.hydrateRoot) && !!domNode.innerHTML;
|
|
112
115
|
var reactElementOrRouterResult = createReactOutput_1.default({
|
|
113
116
|
componentObj: componentObj,
|
|
114
117
|
props: props,
|
|
@@ -121,10 +124,10 @@ function render(el, railsContext) {
|
|
|
121
124
|
throw new Error("You returned a server side type of react-router error: " + JSON.stringify(reactElementOrRouterResult) + "\nYou should return a React.Component always for the client side entry point.");
|
|
122
125
|
}
|
|
123
126
|
else if (shouldHydrate) {
|
|
124
|
-
|
|
127
|
+
reactHydrate_1.default(domNode, reactElementOrRouterResult);
|
|
125
128
|
}
|
|
126
129
|
else {
|
|
127
|
-
|
|
130
|
+
reactRender_1.default(domNode, reactElementOrRouterResult);
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var react_dom_1 = __importDefault(require("react-dom"));
|
|
7
|
+
var supportsReactCreateRoot_1 = __importDefault(require("./supportsReactCreateRoot"));
|
|
8
|
+
function reactHydrate(domNode, reactElement) {
|
|
9
|
+
if (supportsReactCreateRoot_1.default) {
|
|
10
|
+
// @ts-expect-error potentially present if React 18 or greater
|
|
11
|
+
return react_dom_1.default.hydrateRoot(domNode, reactElement);
|
|
12
|
+
}
|
|
13
|
+
return react_dom_1.default.hydrate(reactElement, domNode);
|
|
14
|
+
}
|
|
15
|
+
exports.default = reactHydrate;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var react_dom_1 = __importDefault(require("react-dom"));
|
|
7
|
+
var supportsReactCreateRoot_1 = __importDefault(require("./supportsReactCreateRoot"));
|
|
8
|
+
function reactRender(domNode, reactElement) {
|
|
9
|
+
if (supportsReactCreateRoot_1.default) {
|
|
10
|
+
// @ts-expect-error potentially present if React 18 or greater
|
|
11
|
+
var root = react_dom_1.default.createRoot(domNode);
|
|
12
|
+
root.render(reactElement);
|
|
13
|
+
return root;
|
|
14
|
+
}
|
|
15
|
+
// eslint-disable-next-line react/no-render-return-value
|
|
16
|
+
return react_dom_1.default.render(reactElement, domNode);
|
|
17
|
+
}
|
|
18
|
+
exports.default = reactRender;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var react_dom_1 = __importDefault(require("react-dom"));
|
|
7
|
+
var reactMajorVersion = parseInt(react_dom_1.default.version.split('.')[0], 10);
|
|
8
|
+
exports.default = reactMajorVersion >= 18;
|