react-on-rails 13.4.0 → 14.0.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/README.md +2 -2
- package/node_package/lib/ReactOnRails.d.ts +1 -0
- package/node_package/lib/ReactOnRails.js +4 -0
- package/node_package/lib/clientStartup.js +0 -1
- package/node_package/lib/reactApis.js +1 -1
- package/node_package/lib/serverRenderReactComponent.js +1 -0
- package/node_package/lib/types/index.d.ts +9 -7
- package/package.json +23 -24
- package/webpackConfigLoader.js +0 -71
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ See [Rails/Webpacker React Integration Options](https://www.shakacode.com/react-
|
|
|
63
63
|
|
|
64
64
|
## Online demo
|
|
65
65
|
* See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
|
|
66
|
-
* A deployed version of the project `spec/dummy
|
|
66
|
+
* A deployed version of the project `spec/dummy`, which demonstrates several uses of `react_on_rails`, will soon be available on [Control Plane through this link](https://ror-spec-dummy.reactrails.com/)
|
|
67
67
|
|
|
68
68
|
## ShakaCode Forum Premium Content
|
|
69
69
|
_Requires creating a free account._
|
|
@@ -73,7 +73,7 @@ _Requires creating a free account._
|
|
|
73
73
|
|
|
74
74
|
## Prerequisites
|
|
75
75
|
|
|
76
|
-
Ruby on Rails >=5, rails/webpacker >= 4.2 or shakapacker > 6, Ruby >=
|
|
76
|
+
Ruby on Rails >=5, rails/webpacker >= 4.2 or shakapacker > 6, Ruby >= 3.0.0
|
|
77
77
|
|
|
78
78
|
# Support
|
|
79
79
|
|
|
@@ -22,6 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
25
28
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
30
|
};
|
|
@@ -259,4 +262,5 @@ ctx.ReactOnRails = {
|
|
|
259
262
|
};
|
|
260
263
|
ctx.ReactOnRails.resetOptions();
|
|
261
264
|
ClientStartup.clientStartup(ctx);
|
|
265
|
+
__exportStar(require("./types"), exports);
|
|
262
266
|
exports.default = ctx.ReactOnRails;
|
|
@@ -245,7 +245,6 @@ function clientStartup(context) {
|
|
|
245
245
|
if (!isWindow(context)) {
|
|
246
246
|
return;
|
|
247
247
|
}
|
|
248
|
-
var document = context.document;
|
|
249
248
|
// Tried with a file local variable, but the install handler gets called twice.
|
|
250
249
|
// eslint-disable-next-line no-underscore-dangle
|
|
251
250
|
if (context.__REACT_ON_RAILS_EVENT_HANDLERS_RAN_ONCE__) {
|
|
@@ -6,7 +6,7 @@ var _a;
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.supportsRootApi = void 0;
|
|
8
8
|
var react_dom_1 = __importDefault(require("react-dom"));
|
|
9
|
-
var reactMajorVersion = ((_a = react_dom_1.default.version) === null || _a === void 0 ? void 0 : _a.split('.')[0]) || 16;
|
|
9
|
+
var reactMajorVersion = Number((_a = react_dom_1.default.version) === null || _a === void 0 ? void 0 : _a.split('.')[0]) || 16;
|
|
10
10
|
// TODO: once we require React 18, we can remove this and inline everything guarded by it.
|
|
11
11
|
// Not the default export because others may be added for future React versions.
|
|
12
12
|
// eslint-disable-next-line import/prefer-default-export
|
|
@@ -45,6 +45,7 @@ var createReactOutput_1 = __importDefault(require("./createReactOutput"));
|
|
|
45
45
|
var isServerRenderResult_1 = require("./isServerRenderResult");
|
|
46
46
|
var buildConsoleReplay_1 = __importDefault(require("./buildConsoleReplay"));
|
|
47
47
|
var handleError_1 = __importDefault(require("./handleError"));
|
|
48
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
48
49
|
function serverRenderReactComponentInternal(options) {
|
|
49
50
|
var _this = this;
|
|
50
51
|
var name = options.name, domNodeId = options.domNodeId, trace = options.trace, props = options.props, railsContext = options.railsContext, renderingReturnsPromises = options.renderingReturnsPromises, throwJsErrors = options.throwJsErrors;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ReactElement, ReactNode, Component,
|
|
1
|
+
import type { ReactElement, ReactNode, Component, ComponentType } from 'react';
|
|
2
2
|
type Store = any;
|
|
3
|
-
type ReactComponent =
|
|
3
|
+
type ReactComponent = ComponentType<any> | string;
|
|
4
4
|
export interface RailsContext {
|
|
5
5
|
railsEnv: string;
|
|
6
6
|
inMailer: boolean;
|
|
@@ -10,14 +10,13 @@ export interface RailsContext {
|
|
|
10
10
|
rorPro: boolean;
|
|
11
11
|
rorProVersion?: string;
|
|
12
12
|
serverSide: boolean;
|
|
13
|
-
originalUrl: string;
|
|
14
13
|
href: string;
|
|
15
14
|
location: string;
|
|
16
15
|
scheme: string;
|
|
17
16
|
host: string;
|
|
18
|
-
port:
|
|
17
|
+
port: number | null;
|
|
19
18
|
pathname: string;
|
|
20
|
-
search: string;
|
|
19
|
+
search: string | null;
|
|
21
20
|
httpAcceptLanguage: string;
|
|
22
21
|
}
|
|
23
22
|
type AuthenticityHeaders = {
|
|
@@ -28,7 +27,10 @@ type AuthenticityHeaders = {
|
|
|
28
27
|
};
|
|
29
28
|
type StoreGenerator = (props: Record<string, unknown>, railsContext: RailsContext) => Store;
|
|
30
29
|
interface ServerRenderResult {
|
|
31
|
-
renderedHtml?: string
|
|
30
|
+
renderedHtml?: string | {
|
|
31
|
+
componentHtml: string;
|
|
32
|
+
[key: string]: string;
|
|
33
|
+
};
|
|
32
34
|
redirectLocation?: {
|
|
33
35
|
pathname: string;
|
|
34
36
|
search: string;
|
|
@@ -39,7 +41,7 @@ interface ServerRenderResult {
|
|
|
39
41
|
type CreateReactOutputResult = ServerRenderResult | ReactElement | Promise<string>;
|
|
40
42
|
type RenderFunctionResult = ReactComponent | ServerRenderResult | Promise<string>;
|
|
41
43
|
interface RenderFunction {
|
|
42
|
-
(props?:
|
|
44
|
+
(props?: any, railsContext?: RailsContext, domNodeId?: string): RenderFunctionResult;
|
|
43
45
|
renderFunction?: boolean;
|
|
44
46
|
}
|
|
45
47
|
type ReactComponentOrRenderFunction = ReactComponent | RenderFunction;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-on-rails",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"description": "react-on-rails JavaScript for react_on_rails Ruby gem",
|
|
5
5
|
"main": "node_package/lib/ReactOnRails.js",
|
|
6
6
|
"directories": {
|
|
@@ -14,40 +14,40 @@
|
|
|
14
14
|
"@babel/preset-env": "^7.20.2",
|
|
15
15
|
"@babel/preset-react": "^7.18.6",
|
|
16
16
|
"@babel/types": "^7.20.7",
|
|
17
|
-
"@types/jest": "^
|
|
18
|
-
"@types/react": "^
|
|
19
|
-
"@types/react-dom": "^
|
|
20
|
-
"@types/turbolinks": "^5.2.
|
|
21
|
-
"@types/webpack-env": "^1.18.
|
|
22
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
23
|
-
"@typescript-eslint/parser": "^
|
|
17
|
+
"@types/jest": "^29.0.0",
|
|
18
|
+
"@types/react": "^17.0.0",
|
|
19
|
+
"@types/react-dom": "^17.0.0",
|
|
20
|
+
"@types/turbolinks": "^5.2.2",
|
|
21
|
+
"@types/webpack-env": "^1.18.4",
|
|
22
|
+
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
|
23
|
+
"@typescript-eslint/parser": "^6.18.1",
|
|
24
24
|
"babelify": "^10.0.0",
|
|
25
25
|
"blue-tape": "^1.0.0",
|
|
26
|
+
"concurrently": "^8.2.2",
|
|
26
27
|
"create-react-class": "^15.7.0",
|
|
27
28
|
"eslint": "^7.32.0",
|
|
28
29
|
"eslint-config-prettier": "^7.0.0",
|
|
29
30
|
"eslint-config-shakacode": "^16.0.1",
|
|
30
|
-
"eslint-plugin-import": "^2.
|
|
31
|
-
"eslint-plugin-jsx-a11y": "^6.
|
|
31
|
+
"eslint-plugin-import": "^2.29.1",
|
|
32
|
+
"eslint-plugin-jsx-a11y": "^6.8.0",
|
|
32
33
|
"eslint-plugin-prettier": "^3.4.1",
|
|
33
|
-
"eslint-plugin-react": "^7.
|
|
34
|
-
"jest": "^
|
|
35
|
-
"jest-environment-jsdom": "^
|
|
36
|
-
"jsdom": "^
|
|
34
|
+
"eslint-plugin-react": "^7.33.2",
|
|
35
|
+
"jest": "^29.0.0",
|
|
36
|
+
"jest-environment-jsdom": "^29.0.0",
|
|
37
|
+
"jsdom": "^22.1.0",
|
|
37
38
|
"nps": "^5.9.3",
|
|
38
|
-
"prettier": "^2.8.
|
|
39
|
+
"prettier": "^2.8.8",
|
|
39
40
|
"prettier-eslint-cli": "^5.0.0",
|
|
40
41
|
"prop-types": "^15.8.1",
|
|
41
|
-
"react": "^
|
|
42
|
-
"react-dom": "^
|
|
42
|
+
"react": "^17.0.0",
|
|
43
|
+
"react-dom": "^17.0.0",
|
|
43
44
|
"react-transform-hmr": "^1.0.4",
|
|
44
|
-
"redux": "^4.2.
|
|
45
|
-
"ts-jest": "^
|
|
46
|
-
"typescript": "^
|
|
45
|
+
"redux": "^4.2.1",
|
|
46
|
+
"ts-jest": "^29.1.0",
|
|
47
|
+
"typescript": "^5.3.3"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
|
-
"@babel/runtime-corejs3": "^7.12.5"
|
|
50
|
-
"concurrently": "^5.1.0"
|
|
50
|
+
"@babel/runtime-corejs3": "^7.12.5"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"js-yaml": ">= 3.0.0",
|
|
@@ -55,8 +55,7 @@
|
|
|
55
55
|
"react-dom": ">= 16"
|
|
56
56
|
},
|
|
57
57
|
"files": [
|
|
58
|
-
"node_package/lib"
|
|
59
|
-
"webpackConfigLoader.js"
|
|
58
|
+
"node_package/lib"
|
|
60
59
|
],
|
|
61
60
|
"scripts": {
|
|
62
61
|
"test": "jest node_package/tests",
|
package/webpackConfigLoader.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TODO: THIS SHOULD BE REMOVED
|
|
3
|
-
*
|
|
4
|
-
* Allow defaults for the config/webpacker.yml. Thee values in this file MUST match values
|
|
5
|
-
* in https://github.com/rails/webpacker/blob/master/lib/install/config/webpacker.yml
|
|
6
|
-
*
|
|
7
|
-
* NOTE: for HMR reloading, env.WEBPACKER_HMR value will override any config value. This env value
|
|
8
|
-
* should be set to TRUE to turn this on.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const { join, resolve } = require('path');
|
|
12
|
-
const { env } = require('process');
|
|
13
|
-
const { safeLoad } = require('js-yaml');
|
|
14
|
-
const { readFileSync } = require('fs');
|
|
15
|
-
|
|
16
|
-
function removeOuterSlashes(string) {
|
|
17
|
-
return string.replace(/^\/*/, '').replace(/\/*$/, '');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function formatPublicPath(settings) {
|
|
21
|
-
if (settings.dev_server) {
|
|
22
|
-
const { host } = settings.dev_server;
|
|
23
|
-
const { port } = settings.dev_server;
|
|
24
|
-
const path = settings.public_output_path;
|
|
25
|
-
const hostWithHttp = `http://${host}:${port}`;
|
|
26
|
-
|
|
27
|
-
let formattedHost = removeOuterSlashes(hostWithHttp);
|
|
28
|
-
if (formattedHost && !/^http/i.test(formattedHost)) {
|
|
29
|
-
formattedHost = `//${formattedHost}`;
|
|
30
|
-
}
|
|
31
|
-
const formattedPath = removeOuterSlashes(path);
|
|
32
|
-
return `${formattedHost}/${formattedPath}/`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const publicOuterPathWithoutOutsideSlashes = removeOuterSlashes(settings.public_output_path);
|
|
36
|
-
return `//${publicOuterPathWithoutOutsideSlashes}/`;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @param configPath, location where webpacker.yml will be found
|
|
41
|
-
* Return values are consistent with Webpacker's js helpers
|
|
42
|
-
* For example, you might define:
|
|
43
|
-
* const isHMR = settings.dev_server && settings.dev_server.hmr
|
|
44
|
-
* @returns {{
|
|
45
|
-
settings,
|
|
46
|
-
resolvedModules,
|
|
47
|
-
output: { path, publicPath, publicPathWithHost }
|
|
48
|
-
}}
|
|
49
|
-
*/
|
|
50
|
-
const configLoader = (configPath) => {
|
|
51
|
-
// Some test environments might not have the NODE_ENV set, so we'll have fallbacks.
|
|
52
|
-
const configEnv = env.NODE_ENV || env.RAILS_ENV || 'development';
|
|
53
|
-
const ymlConfigPath = join(configPath, 'webpacker.yml');
|
|
54
|
-
const settings = safeLoad(readFileSync(ymlConfigPath, 'utf8'))[configEnv];
|
|
55
|
-
|
|
56
|
-
// NOTE: Rails path is hard coded to `/public`
|
|
57
|
-
const output = {
|
|
58
|
-
// Next line differs from the webpacker definition as we use the configPath to create
|
|
59
|
-
// the relative path.
|
|
60
|
-
path: resolve(configPath, '..', 'public', settings.public_output_path),
|
|
61
|
-
publicPath: `/${settings.public_output_path}/`.replace(/([^:]\/)\/+/g, '$1'),
|
|
62
|
-
publicPathWithHost: formatPublicPath(settings),
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
settings,
|
|
67
|
-
output,
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
module.exports = configLoader;
|