react-on-rails 12.4.0-rc.0 → 12.5.2

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/README.md CHANGED
@@ -11,6 +11,14 @@
11
11
 
12
12
  [![License](https://img.shields.io/badge/license-mit-green.svg)](LICENSE.md) [![Build Status](https://travis-ci.org/shakacode/react_on_rails.svg?branch=master)](https://travis-ci.org/shakacode/react_on_rails) [![Gem Version](https://badge.fury.io/rb/react_on_rails.svg)](https://badge.fury.io/rb/react_on_rails) [![npm version](https://badge.fury.io/js/react-on-rails.svg)](https://badge.fury.io/js/react-on-rails) [![Code Climate](https://codeclimate.com/github/shakacode/react_on_rails/badges/gpa.svg)](https://codeclimate.com/github/shakacode/react_on_rails) [![Coverage Status](https://coveralls.io/repos/shakacode/react_on_rails/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react_on_rails?branch=master) [![](https://ruby-gem-downloads-badge.herokuapp.com/react_on_rails?type=total)](https://rubygems.org/gems/react_on_rails)
13
13
 
14
+ # News
15
+ * Project is updated to support Rails 7!
16
+ * **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.
17
+
18
+ If you have time, please comment on Justin's final proposals for Webpacker v6: [webpacker/pulls/justin808](https://github.com/rails/webpacker/pulls/justin808).
19
+
20
+ -----
21
+
14
22
  *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
23
 
16
24
  #### About
@@ -18,20 +26,20 @@ React on Rails integrates Rails with (server rendering of) Facebook's [React](ht
18
26
 
19
27
  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
28
 
21
- Interested in optimizing your webpack setup for React on Rails including code
29
+ Are you interested in optimizing your webpack setup for React on Rails including code
22
30
  splitting with [react-router](https://github.com/ReactTraining/react-router#readme) and
23
- and [loadable-components](https://loadable-components.com/) with server-side rendering for SEO and hot-reloading for developers?
31
+ [loadable-components](https://loadable-components.com/) with server-side rendering for SEO and hot-reloading for developers?
24
32
  We did this for Popmenu, [lowering Heroku costs 20-25% while getting a 73% decrease in average response times](https://www.shakacode.com/recent-work/popmenu/). Check out [React on Rails Pro](https://www.shakacode.com/react-on-rails-pro/).
25
33
 
26
- Feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com), maintainer of React on Rails, for more information.
34
+ For more information, feel free to contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com), maintainer of React on Rails.
27
35
 
28
36
  # Documentation
29
37
 
30
- See the documentation at [shakacode.com/react-on-rails/docs](https://www.shakacode.com/react-on-rails/docs/).
38
+ See the documentation at **[shakacode.com/react-on-rails/docs](https://www.shakacode.com/react-on-rails/docs/)**.
31
39
 
32
40
  ## Project Objective
33
41
 
34
- To provide a high performance framework for integrating Ruby on Rails with React via the [**Webpacker**](https://github.com/rails/webpacker) gem especially in regards to React Server-Side Rendering for better SEO and improved performance.
42
+ 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
43
 
36
44
  ## Features and Why React on Rails?
37
45
 
@@ -47,7 +55,9 @@ Given that `rails/webpacker` gem already provides basic React integration, why w
47
55
 
48
56
  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
57
 
50
- See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
58
+ ## Online demo
59
+ * See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
60
+ * 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
61
 
52
62
  ## ShakaCode Forum Premium Content
53
63
  _Requires creating a free account._
@@ -55,10 +65,9 @@ _Requires creating a free account._
55
65
  * [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
66
  * [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
67
 
58
-
59
68
  ## Prerequisites
60
69
 
61
- Ruby on Rails >=5 and rails/webpacker 4.2+.
70
+ Ruby on Rails >=5, rails/webpacker >= 4.2, Ruby >= 2.7
62
71
 
63
72
  # Support
64
73
 
@@ -85,12 +94,12 @@ The following companies support this open source project, and ShakaCode uses the
85
94
  [![HoneyBadger](https://user-images.githubusercontent.com/1118459/114100696-63962a00-9860-11eb-8ac1-75ca02856d8e.png)](https://www.honeybadger.io/)
86
95
  [![StatusHero](https://user-images.githubusercontent.com/1118459/126868048-3fe64e54-4d6d-4066-9df2-8cf6fbaeb314.png)](https://statushero.com/)
87
96
 
88
- ShakaCode's favorite project tracking tool is [ClubHouse](https://clubhouse.io/). If you want to **try ClubHouse and get 2 months free beyond the 14-day trial period**, click [here to use ShakaCode's referral code](http://r.clbh.se/mvfoNeH). We're participating in their awesome triple-sided referral program, which you can read about [here](https://clubhouse.io/referral/). By using our [referral code](http://r.clbh.se/mvfoNeH) you'll be supporting ShakaCode and, thus, React on Rails!
97
+ 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
98
 
90
99
  Aloha and best wishes from Justin and the ShakaCode team!
91
100
 
92
101
  # 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).
102
+ ShakaCode is **[hiring passionate software engineers](http://www.shakacode.com/career)** to work on our projects, including [HiChee](https://hichee.com)!
94
103
 
95
104
  # License
96
105
 
@@ -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 ? react_dom_1.default.hydrate : react_dom_1.default.render;
177
+ var render = hydrate ? reactHydrate_1.default : reactRender_1.default;
177
178
  // eslint-disable-next-line react/no-render-return-value
178
- return render(reactElement, document.getElementById(domNodeId));
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
- var shouldHydrate = !!react_dom_1.default.hydrate && !!domNode.innerHTML;
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
- react_dom_1.default.hydrate(reactElementOrRouterResult, domNode);
127
+ reactHydrate_1.default(domNode, reactElementOrRouterResult);
125
128
  }
126
129
  else {
127
- react_dom_1.default.render(reactElementOrRouterResult, domNode);
130
+ reactRender_1.default(domNode, reactElementOrRouterResult);
128
131
  }
129
132
  }
130
133
  }
@@ -0,0 +1,2 @@
1
+ import { ReactElement, Component } from 'react';
2
+ export default function reactHydrate(domNode: Element, reactElement: ReactElement): void | Element | Component;
@@ -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,2 @@
1
+ import { ReactElement, Component } from 'react';
2
+ export default function reactRender(domNode: Element, reactElement: ReactElement): void | Element | Component;
@@ -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,2 @@
1
+ declare var _default: boolean;
2
+ export default _default;
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "12.4.0-rc.0",
3
+ "version": "12.5.2",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {