@dr.pogodin/react-utils 1.15.7 → 1.16.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/build/development/client/index.js +11 -5
- package/build/development/client/index.js.map +1 -1
- package/build/development/server/renderer.js +78 -36
- package/build/development/server/renderer.js.map +1 -1
- package/build/development/shared/components/CodeSplit/index.js +108 -9
- package/build/development/shared/components/CodeSplit/index.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +2 -3
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/utils/jest.js +14 -77
- package/build/development/shared/utils/jest.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +12 -13
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/shared/utils/time.js +11 -22
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/web.bundle.js +21 -41
- package/build/production/client/index.js +3 -2
- package/build/production/client/index.js.map +1 -1
- package/build/production/server/renderer.js +26 -13
- package/build/production/server/renderer.js.map +1 -1
- package/build/production/shared/components/CodeSplit/index.js +8 -5
- package/build/production/shared/components/CodeSplit/index.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +2 -3
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/utils/jest.js +6 -28
- package/build/production/shared/utils/jest.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +6 -7
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/shared/utils/time.js +6 -20
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.LICENSE.txt +2 -7
- package/build/production/web.bundle.js.map +1 -1
- package/package.json +25 -25
- package/build/development/shared/components/CodeSplit/ClientSide.js +0 -155
- package/build/development/shared/components/CodeSplit/ClientSide.js.map +0 -1
- package/build/development/shared/components/CodeSplit/ServerSide.js +0 -111
- package/build/development/shared/components/CodeSplit/ServerSide.js.map +0 -1
- package/build/production/shared/components/CodeSplit/ClientSide.js +0 -21
- package/build/production/shared/components/CodeSplit/ClientSide.js.map +0 -1
- package/build/production/shared/components/CodeSplit/ServerSide.js +0 -18
- package/build/production/shared/components/CodeSplit/ServerSide.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.16.2",
|
|
3
3
|
"bin": {
|
|
4
4
|
"react-utils-build": "bin/build.js",
|
|
5
5
|
"react-utils-setup": "bin/setup.js"
|
|
@@ -8,43 +8,43 @@
|
|
|
8
8
|
"url": "https://github.com/birdofpreyru/react-utils/issues"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@babel/runtime": "^7.17.
|
|
11
|
+
"@babel/runtime": "^7.17.9",
|
|
12
12
|
"@dr.pogodin/babel-plugin-react-css-modules": "^6.8.0",
|
|
13
|
-
"@dr.pogodin/react-global-state": "^0.
|
|
14
|
-
"@dr.pogodin/react-themes": "^1.4.
|
|
13
|
+
"@dr.pogodin/react-global-state": "^0.8.1",
|
|
14
|
+
"@dr.pogodin/react-themes": "^1.4.2",
|
|
15
15
|
"axios": "^0.26.1",
|
|
16
16
|
"commander": "^9.0.0",
|
|
17
17
|
"compression": "^1.7.4",
|
|
18
18
|
"config": "^3.3.7",
|
|
19
19
|
"cookie-parser": "^1.4.6",
|
|
20
20
|
"cross-env": "^7.0.3",
|
|
21
|
-
"dayjs": "^1.11.
|
|
21
|
+
"dayjs": "^1.11.1",
|
|
22
22
|
"express": "^4.17.3",
|
|
23
23
|
"helmet": "^5.0.2",
|
|
24
24
|
"http-status-codes": "^2.2.0",
|
|
25
25
|
"joi": "^17.6.0",
|
|
26
26
|
"lodash": "^4.17.21",
|
|
27
27
|
"morgan": "^1.10.0",
|
|
28
|
-
"node-forge": "^1.3.
|
|
28
|
+
"node-forge": "^1.3.1",
|
|
29
29
|
"prop-types": "^15.8.1",
|
|
30
30
|
"qs": "^6.10.1",
|
|
31
31
|
"raf": "^3.4.1",
|
|
32
|
-
"react": "^
|
|
33
|
-
"react-dom": "^
|
|
32
|
+
"react": "^18.0.0",
|
|
33
|
+
"react-dom": "^18.0.0",
|
|
34
34
|
"react-helmet": "^6.1.0",
|
|
35
|
-
"react-router-dom": "^6.
|
|
35
|
+
"react-router-dom": "^6.3.0",
|
|
36
36
|
"request-ip": "^2.1.3",
|
|
37
37
|
"rimraf": "^3.0.2",
|
|
38
38
|
"serialize-javascript": "^6.0.0",
|
|
39
39
|
"serve-favicon": "^2.5.0",
|
|
40
40
|
"source-map-support": "^0.5.21",
|
|
41
41
|
"uuid": "^8.3.2",
|
|
42
|
-
"winston": "^3.
|
|
42
|
+
"winston": "^3.7.2"
|
|
43
43
|
},
|
|
44
44
|
"description": "Collection of generic ReactJS components and utils",
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@babel/cli": "^7.17.6",
|
|
47
|
-
"@babel/core": "^7.17.
|
|
47
|
+
"@babel/core": "^7.17.9",
|
|
48
48
|
"@babel/eslint-parser": "^7.17.0",
|
|
49
49
|
"@babel/eslint-plugin": "^7.17.7",
|
|
50
50
|
"@babel/node": "^7.16.8",
|
|
@@ -53,22 +53,22 @@
|
|
|
53
53
|
"@babel/preset-react": "^7.16.7",
|
|
54
54
|
"@dr.pogodin/babel-plugin-transform-assets": "^1.1.1",
|
|
55
55
|
"@dr.pogodin/babel-preset-svgr": "^1.4.0",
|
|
56
|
-
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.
|
|
56
|
+
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
|
|
57
57
|
"autoprefixer": "^10.4.4",
|
|
58
58
|
"babel-jest": "^27.5.1",
|
|
59
59
|
"babel-loader": "^8.2.4",
|
|
60
60
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
61
|
-
"core-js": "^3.
|
|
61
|
+
"core-js": "^3.22.0",
|
|
62
62
|
"css-loader": "^6.7.1",
|
|
63
63
|
"css-minimizer-webpack-plugin": "^3.4.1",
|
|
64
|
-
"eslint": "^8.
|
|
64
|
+
"eslint": "^8.13.0",
|
|
65
65
|
"eslint-config-airbnb": "^19.0.4",
|
|
66
66
|
"eslint-import-resolver-babel-module": "^5.3.1",
|
|
67
|
-
"eslint-plugin-import": "^2.
|
|
68
|
-
"eslint-plugin-jest": "^26.1.
|
|
67
|
+
"eslint-plugin-import": "^2.26.0",
|
|
68
|
+
"eslint-plugin-jest": "^26.1.4",
|
|
69
69
|
"eslint-plugin-jsx-a11y": "^6.5.1",
|
|
70
70
|
"eslint-plugin-react": "^7.29.4",
|
|
71
|
-
"eslint-plugin-react-hooks": "^4.
|
|
71
|
+
"eslint-plugin-react-hooks": "^4.4.0",
|
|
72
72
|
"identity-obj-proxy": "^3.0.0",
|
|
73
73
|
"jest": "^27.5.1",
|
|
74
74
|
"mini-css-extract-plugin": "^2.6.0",
|
|
@@ -78,23 +78,23 @@
|
|
|
78
78
|
"postcss-loader": "^6.2.1",
|
|
79
79
|
"postcss-scss": "^4.0.3",
|
|
80
80
|
"pretty": "^2.0.0",
|
|
81
|
-
"react-refresh": "^0.
|
|
82
|
-
"react-test-renderer": "^
|
|
81
|
+
"react-refresh": "^0.12.0",
|
|
82
|
+
"react-test-renderer": "^18.0.0",
|
|
83
83
|
"regenerator-runtime": "^0.13.9",
|
|
84
84
|
"resolve-url-loader": "^5.0.0",
|
|
85
|
-
"sass": "^1.
|
|
85
|
+
"sass": "^1.50.0",
|
|
86
86
|
"sass-loader": "^12.6.0",
|
|
87
87
|
"sitemap": "^7.1.1",
|
|
88
|
-
"stylelint": "^14.
|
|
88
|
+
"stylelint": "^14.7.1",
|
|
89
89
|
"stylelint-config-standard-scss": "^3.0.0",
|
|
90
90
|
"supertest": "^6.2.2",
|
|
91
|
-
"webpack": "^5.
|
|
91
|
+
"webpack": "^5.72.0",
|
|
92
92
|
"webpack-dev-middleware": "^5.3.1",
|
|
93
93
|
"webpack-hot-middleware": "^2.25.1",
|
|
94
94
|
"webpack-merge": "^5.8.0",
|
|
95
|
-
"workbox-core": "^6.5.
|
|
96
|
-
"workbox-precaching": "^6.5.
|
|
97
|
-
"workbox-webpack-plugin": "^6.5.
|
|
95
|
+
"workbox-core": "^6.5.3",
|
|
96
|
+
"workbox-precaching": "^6.5.3",
|
|
97
|
+
"workbox-webpack-plugin": "^6.5.3"
|
|
98
98
|
},
|
|
99
99
|
"engines": {
|
|
100
100
|
"node": ">=14.x",
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = ClientSide;
|
|
9
|
-
|
|
10
|
-
var _react = require("react");
|
|
11
|
-
|
|
12
|
-
var _reactGlobalState = require("@dr.pogodin/react-global-state");
|
|
13
|
-
|
|
14
|
-
var _Barrier = require("../../utils/Barrier");
|
|
15
|
-
|
|
16
|
-
var _isomorphy = require("../../utils/isomorphy");
|
|
17
|
-
|
|
18
|
-
var _time = _interopRequireDefault(require("../../utils/time"));
|
|
19
|
-
|
|
20
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Client-side implementation of a split code chunk.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/* global document, window */
|
|
27
|
-
|
|
28
|
-
/* eslint-disable react/jsx-props-no-spreading */
|
|
29
|
-
function ClientSide({
|
|
30
|
-
chunkName,
|
|
31
|
-
children,
|
|
32
|
-
getClientSide,
|
|
33
|
-
placeholder,
|
|
34
|
-
// Not used in <ClientSide>, but should not go into "...rest" either.
|
|
35
|
-
serverSide,
|
|
36
|
-
...rest
|
|
37
|
-
}) {
|
|
38
|
-
const {
|
|
39
|
-
current: heap
|
|
40
|
-
} = (0, _react.useRef)({
|
|
41
|
-
mounted: false,
|
|
42
|
-
pendingStyles: [],
|
|
43
|
-
renderInitialized: false
|
|
44
|
-
}); // publicPath from buildInfo does not have a trailing slash at the end.
|
|
45
|
-
|
|
46
|
-
const {
|
|
47
|
-
publicPath
|
|
48
|
-
} = (0, _isomorphy.getBuildInfo)(); // This code block initiates style loading as soon as possible, even prior to
|
|
49
|
-
// the component loading, and it collects all style load / failure promises
|
|
50
|
-
// into heap.pendingStyles array, allowing us to wait and thus avoid flash of
|
|
51
|
-
// unstyled content issue (that's why we don't rely on mini-css-extract-plugin
|
|
52
|
-
// to handle CSS chunk mounting and unmounting, which it is able to do).
|
|
53
|
-
|
|
54
|
-
if (!heap.mounted) {
|
|
55
|
-
heap.mounted = true;
|
|
56
|
-
window.CHUNK_GROUPS[chunkName].forEach(asset => {
|
|
57
|
-
if (!asset.endsWith('.css')) return;
|
|
58
|
-
const path = `${publicPath}/${asset}`;
|
|
59
|
-
let link = document.querySelector(`link[href="${path}"]`);
|
|
60
|
-
|
|
61
|
-
if (!link) {
|
|
62
|
-
link = document.createElement('link');
|
|
63
|
-
link.setAttribute('href', path);
|
|
64
|
-
link.setAttribute('rel', 'stylesheet');
|
|
65
|
-
const barrier = (0, _Barrier.newBarrier)();
|
|
66
|
-
link.onload = barrier.resolve; // Even if the style load failed, still allow to mount the component,
|
|
67
|
-
// abeit with broken styling.
|
|
68
|
-
|
|
69
|
-
link.onerror = barrier.resolve;
|
|
70
|
-
heap.pendingStyles.push(barrier);
|
|
71
|
-
const head = document.querySelector('head');
|
|
72
|
-
head.appendChild(link);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
window.STYLESHEET_USAGE_COUNTERS ||= {};
|
|
76
|
-
window.STYLESHEET_USAGE_COUNTERS[path] ||= 0;
|
|
77
|
-
++window.STYLESHEET_USAGE_COUNTERS[path];
|
|
78
|
-
});
|
|
79
|
-
} // Async loading of React component necessary to render the chunk.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const {
|
|
83
|
-
data
|
|
84
|
-
} = (0, _reactGlobalState.useAsyncData)(`dr_pogodin_react_utils___split_components.${chunkName}`, getClientSide, {
|
|
85
|
-
maxage: _time.default.YEAR_MS
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const createRender = () => {
|
|
89
|
-
const Scene = data.default || data;
|
|
90
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
91
|
-
"data-chunk-name": chunkName,
|
|
92
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Scene, { ...rest,
|
|
93
|
-
children: children
|
|
94
|
-
})
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const [render, setRender] = (0, _react.useState)(() => {
|
|
99
|
-
// No need to await anything, we can render the final component right away.
|
|
100
|
-
if (data && !heap.pendingStyles.length) {
|
|
101
|
-
heap.renderInitialized = true;
|
|
102
|
-
return createRender();
|
|
103
|
-
} // Try to reuse the markup rendered during SSR.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const node = document.querySelector(`[data-chunk-name=${chunkName}]`);
|
|
107
|
-
|
|
108
|
-
if (node) {
|
|
109
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
110
|
-
/* eslint-disable react/no-danger */
|
|
111
|
-
dangerouslySetInnerHTML: {
|
|
112
|
-
__html: node.innerHTML || ''
|
|
113
|
-
}
|
|
114
|
-
/* eslint-disable react/no-danger */
|
|
115
|
-
,
|
|
116
|
-
"data-chunk-name": chunkName
|
|
117
|
-
});
|
|
118
|
-
} // Else render placeholder, or empty div.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const Scene = placeholder || (() => null);
|
|
122
|
-
|
|
123
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
124
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Scene, { ...rest,
|
|
125
|
-
children: children
|
|
126
|
-
})
|
|
127
|
-
});
|
|
128
|
-
}); // At this point, if we have data, the absense of heap.renderInitialized flag
|
|
129
|
-
// means we have to await styles loading; once it is done, and if we are still
|
|
130
|
-
// mounted, we can set the final render.
|
|
131
|
-
|
|
132
|
-
if (data && !heap.renderInitialized) {
|
|
133
|
-
heap.renderInitialized = true;
|
|
134
|
-
Promise.all(heap.pendingStyles).then(() => {
|
|
135
|
-
if (heap.mounted) setRender(createRender());
|
|
136
|
-
});
|
|
137
|
-
} // This effectively fires only once, just before the component unmounts.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
(0, _react.useEffect)(() => () => {
|
|
141
|
-
heap.mounted = false;
|
|
142
|
-
window.CHUNK_GROUPS[chunkName].forEach(item => {
|
|
143
|
-
if (!item.endsWith('.css')) return;
|
|
144
|
-
const path = `${publicPath}/${item}`;
|
|
145
|
-
|
|
146
|
-
if (--window.STYLESHEET_USAGE_COUNTERS[path] <= 0) {
|
|
147
|
-
const link = document.querySelector(`link[href="${path}"]`);
|
|
148
|
-
const head = document.querySelector('head');
|
|
149
|
-
head.removeChild(link);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}, [chunkName, heap, publicPath]);
|
|
153
|
-
return render;
|
|
154
|
-
}
|
|
155
|
-
//# sourceMappingURL=ClientSide.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/shared/components/CodeSplit/ClientSide.jsx"],"names":["ClientSide","chunkName","children","getClientSide","placeholder","serverSide","rest","current","heap","mounted","pendingStyles","renderInitialized","publicPath","window","CHUNK_GROUPS","forEach","asset","endsWith","path","link","document","querySelector","createElement","setAttribute","barrier","onload","resolve","onerror","push","head","appendChild","STYLESHEET_USAGE_COUNTERS","data","maxage","time","YEAR_MS","createRender","Scene","default","render","setRender","length","node","__html","innerHTML","Promise","all","then","item","removeChild"],"mappings":";;;;;;;;;AAMA;;AAEA;;AAEA;;AACA;;AACA;;;;AAZA;AACA;AACA;;AACA;;AACA;AAUe,SAASA,UAAT,CAAoB;AACjCC,EAAAA,SADiC;AAEjCC,EAAAA,QAFiC;AAGj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AAD,OAAWE,IAAX;AAAA,kBAAkBJ;AAAlB;AAAL,MAAP;AACD,GAvB2B,CAA5B,CA9DC,CAuFD;AACA;AACA;;AACA,MAAI8B,IAAI,IAAI,CAACxB,IAAI,CAACG,iBAAlB,EAAqC;AACnCH,IAAAA,IAAI,CAACG,iBAAL,GAAyB,IAAzB;AACAkC,IAAAA,OAAO,CAACC,GAAR,CAAYtC,IAAI,CAACE,aAAjB,EAAgCqC,IAAhC,CAAqC,MAAM;AACzC,UAAIvC,IAAI,CAACC,OAAT,EAAkB+B,SAAS,CAACJ,YAAY,EAAb,CAAT;AACnB,KAFD;AAGD,GA/FA,CAiGD;;;AACA,wBAAU,MAAM,MAAM;AACpB5B,IAAAA,IAAI,CAACC,OAAL,GAAe,KAAf;AACAI,IAAAA,MAAM,CAACC,YAAP,CAAoBb,SAApB,EAA+Bc,OAA/B,CAAwCiC,IAAD,IAAU;AAC/C,UAAI,CAACA,IAAI,CAAC/B,QAAL,CAAc,MAAd,CAAL,EAA4B;AAC5B,YAAMC,IAAI,GAAI,GAAEN,UAAW,IAAGoC,IAAK,EAAnC;;AACA,UAAI,EAAEnC,MAAM,CAACkB,yBAAP,CAAiCb,IAAjC,CAAF,IAA4C,CAAhD,EAAmD;AACjD,cAAMC,IAAI,GAAGC,QAAQ,CAACC,aAAT,CAAwB,cAAaH,IAAK,IAA1C,CAAb;AACA,cAAMW,IAAI,GAAGT,QAAQ,CAACC,aAAT,CAAuB,MAAvB,CAAb;AACAQ,QAAAA,IAAI,CAACoB,WAAL,CAAiB9B,IAAjB;AACD;AACF,KARD;AASD,GAXD,EAWG,CAAClB,SAAD,EAAYO,IAAZ,EAAkBI,UAAlB,CAXH;AAaA,SAAO2B,MAAP;AACD","sourcesContent":["/**\n * Client-side implementation of a split code chunk.\n */\n/* global document, window */\n/* eslint-disable react/jsx-props-no-spreading */\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport { useAsyncData } from '@dr.pogodin/react-global-state';\n\nimport { newBarrier } from 'utils/Barrier';\nimport { getBuildInfo } from 'utils/isomorphy';\nimport time from 'utils/time';\n\nexport default function ClientSide({\n chunkName,\n children,\n getClientSide,\n placeholder,\n\n // Not used in <ClientSide>, but should not go into \"...rest\" either.\n serverSide,\n\n ...rest\n}) {\n const { current: heap } = useRef({\n mounted: false,\n pendingStyles: [],\n renderInitialized: false,\n });\n\n // publicPath from buildInfo does not have a trailing slash at the end.\n const { publicPath } = getBuildInfo();\n\n // This code block initiates style loading as soon as possible, even prior to\n // the component loading, and it collects all style load / failure promises\n // into heap.pendingStyles array, allowing us to wait and thus avoid flash of\n // unstyled content issue (that's why we don't rely on mini-css-extract-plugin\n // to handle CSS chunk mounting and unmounting, which it is able to do).\n if (!heap.mounted) {\n heap.mounted = true;\n window.CHUNK_GROUPS[chunkName].forEach((asset) => {\n if (!asset.endsWith('.css')) return;\n const path = `${publicPath}/${asset}`;\n let link = document.querySelector(`link[href=\"${path}\"]`);\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('href', path);\n link.setAttribute('rel', 'stylesheet');\n\n const barrier = newBarrier();\n link.onload = barrier.resolve;\n\n // Even if the style load failed, still allow to mount the component,\n // abeit with broken styling.\n link.onerror = barrier.resolve;\n\n heap.pendingStyles.push(barrier);\n\n const head = document.querySelector('head');\n head.appendChild(link);\n }\n window.STYLESHEET_USAGE_COUNTERS ||= {};\n window.STYLESHEET_USAGE_COUNTERS[path] ||= 0;\n ++window.STYLESHEET_USAGE_COUNTERS[path];\n });\n }\n\n // Async loading of React component necessary to render the chunk.\n const { data } = useAsyncData(\n `dr_pogodin_react_utils___split_components.${chunkName}`,\n getClientSide,\n { maxage: time.YEAR_MS },\n );\n\n const createRender = () => {\n const Scene = data.default || data;\n return (\n <div data-chunk-name={chunkName}>\n <Scene {...rest}>\n {children}\n </Scene>\n </div>\n );\n };\n\n const [render, setRender] = useState(() => {\n // No need to await anything, we can render the final component right away.\n if (data && !heap.pendingStyles.length) {\n heap.renderInitialized = true;\n return createRender();\n }\n\n // Try to reuse the markup rendered during SSR.\n const node = document.querySelector(`[data-chunk-name=${chunkName}]`);\n if (node) {\n return (\n <div\n /* eslint-disable react/no-danger */\n dangerouslySetInnerHTML={{ __html: node.innerHTML || '' }}\n /* eslint-disable react/no-danger */\n data-chunk-name={chunkName}\n />\n );\n }\n\n // Else render placeholder, or empty div.\n const Scene = placeholder || (() => null);\n return <div><Scene {...rest}>{children}</Scene></div>;\n });\n\n // At this point, if we have data, the absense of heap.renderInitialized flag\n // means we have to await styles loading; once it is done, and if we are still\n // mounted, we can set the final render.\n if (data && !heap.renderInitialized) {\n heap.renderInitialized = true;\n Promise.all(heap.pendingStyles).then(() => {\n if (heap.mounted) setRender(createRender());\n });\n }\n\n // This effectively fires only once, just before the component unmounts.\n useEffect(() => () => {\n heap.mounted = false;\n window.CHUNK_GROUPS[chunkName].forEach((item) => {\n if (!item.endsWith('.css')) return;\n const path = `${publicPath}/${item}`;\n if (--window.STYLESHEET_USAGE_COUNTERS[path] <= 0) {\n const link = document.querySelector(`link[href=\"${path}\"]`);\n const head = document.querySelector('head');\n head.removeChild(link);\n }\n });\n }, [chunkName, heap, publicPath]);\n\n return render;\n}\n"],"file":"ClientSide.js"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = ServerSide;
|
|
9
|
-
|
|
10
|
-
var _server = _interopRequireDefault(require("react-dom/server"));
|
|
11
|
-
|
|
12
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
|
|
14
|
-
var _reactGlobalState = require("@dr.pogodin/react-global-state");
|
|
15
|
-
|
|
16
|
-
var _reactRouterDom = require("react-router-dom");
|
|
17
|
-
|
|
18
|
-
var _server2 = require("react-router-dom/server");
|
|
19
|
-
|
|
20
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Server-side implementation.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/* eslint-disable react/jsx-props-no-spreading */
|
|
27
|
-
function ServerSide({
|
|
28
|
-
chunkName,
|
|
29
|
-
getClientSide,
|
|
30
|
-
serverSide,
|
|
31
|
-
placeholder,
|
|
32
|
-
children,
|
|
33
|
-
...rest
|
|
34
|
-
}) {
|
|
35
|
-
/* 1. The component, or its placeholder is rendered into HTML string.
|
|
36
|
-
* The component is wrapped into <GlobalStateProvider>, and <StaticRouter>
|
|
37
|
-
* to ensure that global state, and react router will work inside
|
|
38
|
-
* the component, if present there. Also, if no server-side (sync) way
|
|
39
|
-
* to load the component is provider, `useAsyncData(..)` is used to
|
|
40
|
-
* attempt to load and use the component via SSR mechanics. */
|
|
41
|
-
let Scene;
|
|
42
|
-
if (serverSide) Scene = serverSide;else {
|
|
43
|
-
// In this case we are sure the condition won't change during the rendering
|
|
44
|
-
// loop, thus we can ignore the rule.
|
|
45
|
-
|
|
46
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
47
|
-
const {
|
|
48
|
-
data
|
|
49
|
-
} = (0, _reactGlobalState.useAsyncData)(`dr_pogodin_react_utils___split_components.${chunkName}`, getClientSide);
|
|
50
|
-
Scene = data ? data.default || data : placeholder || (() => null);
|
|
51
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
52
|
-
}
|
|
53
|
-
const globalState = (0, _reactGlobalState.getGlobalState)();
|
|
54
|
-
const {
|
|
55
|
-
pathname
|
|
56
|
-
} = (0, _reactRouterDom.useResolvedPath)('');
|
|
57
|
-
|
|
58
|
-
const html = _server.default.renderToString( /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactGlobalState.GlobalStateProvider, {
|
|
59
|
-
stateProxy: globalState,
|
|
60
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_server2.StaticRouter, {
|
|
61
|
-
basename: pathname,
|
|
62
|
-
location: globalState.ssrContext.req.url,
|
|
63
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Scene, { ...rest,
|
|
64
|
-
children: children
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
}));
|
|
68
|
-
/* 2. `chunks` array is used to record CSS chunks to inject. */
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const {
|
|
72
|
-
chunks
|
|
73
|
-
} = globalState.ssrContext;
|
|
74
|
-
|
|
75
|
-
if (chunks.includes(chunkName)) {
|
|
76
|
-
throw new Error(`CodeSplit: chunk name clash for (${chunkName})`);
|
|
77
|
-
} else chunks.push(chunkName);
|
|
78
|
-
/* The result is rendered using the container with `dangerouslySetInnerHTML`
|
|
79
|
-
* to allow reproduce the same rendering result at the client side, even prior
|
|
80
|
-
* to the async loading of the split code. */
|
|
81
|
-
|
|
82
|
-
/* eslint-disable react/no-danger */
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
86
|
-
dangerouslySetInnerHTML: {
|
|
87
|
-
__html: html
|
|
88
|
-
},
|
|
89
|
-
"data-chunk-name": chunkName
|
|
90
|
-
});
|
|
91
|
-
/* eslint-enable react/no-danger */
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
ServerSide.propTypes = {
|
|
95
|
-
children: _propTypes.default.node,
|
|
96
|
-
chunkName: _propTypes.default.string.isRequired,
|
|
97
|
-
// Note: it is not strictly required by <ServerSide> component per se,
|
|
98
|
-
// as it is expected that in most cases "serverSide" prop should be provided,
|
|
99
|
-
// however "getClientSide" prop is still used as a fallback at the server side
|
|
100
|
-
// and also it is required by the parent splitComponent() function, so no harm
|
|
101
|
-
// to declare it as required here.
|
|
102
|
-
getClientSide: _propTypes.default.func.isRequired,
|
|
103
|
-
placeholder: _propTypes.default.elementType,
|
|
104
|
-
serverSide: _propTypes.default.elementType
|
|
105
|
-
};
|
|
106
|
-
ServerSide.defaultProps = {
|
|
107
|
-
children: undefined,
|
|
108
|
-
placeholder: null,
|
|
109
|
-
serverSide: undefined
|
|
110
|
-
};
|
|
111
|
-
//# sourceMappingURL=ServerSide.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/shared/components/CodeSplit/ServerSide.jsx"],"names":["ServerSide","chunkName","getClientSide","serverSide","placeholder","children","rest","Scene","data","default","globalState","pathname","html","ReactDom","renderToString","ssrContext","req","url","chunks","includes","Error","push","__html","propTypes","PT","node","string","isRequired","func","elementType","defaultProps","undefined"],"mappings":";;;;;;;;;AAKA;;AACA;;AAEA;;AAMA;;AACA;;;;AAfA;AACA;AACA;;AACA;AAce,SAASA,UAAT,CAAoB;AACjCC,EAAAA,SADiC;AAEjCC,EAAAA,aAFiC;AAGjCC,EAAAA,UAHiC;AAIjCC,EAAAA,WAJiC;AAKjCC,EAAAA,QALiC;AAMjC,KAAGC;AAN8B,CAApB,EAOZ;AACD;AACF;AACA;AACA;AACA;AACA;AACE,MAAIC,KAAJ;AACA,MAAIJ,UAAJ,EAAgBI,KAAK,GAAGJ,UAAR,CAAhB,KACK;AACH;AACA;;AACA;AACA,UAAM;AAAEK,MAAAA;AAAF,QAAW,oCACd,6CAA4CP,SAAU,EADxC,EAEfC,aAFe,CAAjB;AAIAK,IAAAA,KAAK,GAAGC,IAAI,GAAIA,IAAI,CAACC,OAAL,IAAgBD,IAApB,GAA6BJ,WAAW,KAAK,MAAM,IAAX,CAApD;AACA;AACD;AAED,QAAMM,WAAW,GAAG,uCAApB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAe,qCAAgB,EAAhB,CAArB;;AACA,QAAMC,IAAI,GAAGC,gBAASC,cAAT,eACX,qBAAC,qCAAD;AAAqB,IAAA,UAAU,EAAEJ,WAAjC;AAAA,2BACE,qBAAC,qBAAD;AACE,MAAA,QAAQ,EAAEC,QADZ;AAEE,MAAA,QAAQ,EAAED,WAAW,CAACK,UAAZ,CAAuBC,GAAvB,CAA2BC,GAFvC;AAAA,6BAIE,qBAAC,KAAD,OAAWX,IAAX;AAAA,kBACGD;AADH;AAJF;AADF,IADW,CAAb;AAaA;;;AACA,QAAM;AAAEa,IAAAA;AAAF,MAAaR,WAAW,CAACK,UAA/B;;AACA,MAAIG,MAAM,CAACC,QAAP,CAAgBlB,SAAhB,CAAJ,EAAgC;AAC9B,UAAM,IAAImB,KAAJ,CAAW,oCAAmCnB,SAAU,GAAxD,CAAN;AACD,GAFD,MAEOiB,MAAM,CAACG,IAAP,CAAYpB,SAAZ;AAEP;AACF;AACA;;AACE;;;AACA,sBACE;AACE,IAAA,uBAAuB,EAAE;AAAEqB,MAAAA,MAAM,EAAEV;AAAV,KAD3B;AAEE,uBAAiBX;AAFnB,IADF;AAMA;AACD;;AAEDD,UAAU,CAACuB,SAAX,GAAuB;AACrBlB,EAAAA,QAAQ,EAAEmB,mBAAGC,IADQ;AAErBxB,EAAAA,SAAS,EAAEuB,mBAAGE,MAAH,CAAUC,UAFA;AAIrB;AACA;AACA;AACA;AACA;AACAzB,EAAAA,aAAa,EAAEsB,mBAAGI,IAAH,CAAQD,UATF;AAWrBvB,EAAAA,WAAW,EAAEoB,mBAAGK,WAXK;AAYrB1B,EAAAA,UAAU,EAAEqB,mBAAGK;AAZM,CAAvB;AAeA7B,UAAU,CAAC8B,YAAX,GAA0B;AACxBzB,EAAAA,QAAQ,EAAE0B,SADc;AAExB3B,EAAAA,WAAW,EAAE,IAFW;AAGxBD,EAAAA,UAAU,EAAE4B;AAHY,CAA1B","sourcesContent":["/**\n * Server-side implementation.\n */\n/* eslint-disable react/jsx-props-no-spreading */\n\nimport ReactDom from 'react-dom/server';\nimport PT from 'prop-types';\n\nimport {\n getGlobalState,\n GlobalStateProvider,\n useAsyncData,\n} from '@dr.pogodin/react-global-state';\n\nimport { useResolvedPath } from 'react-router-dom';\nimport { StaticRouter } from 'react-router-dom/server';\n\nexport default function ServerSide({\n chunkName,\n getClientSide,\n serverSide,\n placeholder,\n children,\n ...rest\n}) {\n /* 1. The component, or its placeholder is rendered into HTML string.\n * The component is wrapped into <GlobalStateProvider>, and <StaticRouter>\n * to ensure that global state, and react router will work inside\n * the component, if present there. Also, if no server-side (sync) way\n * to load the component is provider, `useAsyncData(..)` is used to\n * attempt to load and use the component via SSR mechanics. */\n let Scene;\n if (serverSide) Scene = serverSide;\n else {\n // In this case we are sure the condition won't change during the rendering\n // loop, thus we can ignore the rule.\n /* eslint-disable react-hooks/rules-of-hooks */\n const { data } = useAsyncData(\n `dr_pogodin_react_utils___split_components.${chunkName}`,\n getClientSide,\n );\n Scene = data ? (data.default || data) : (placeholder || (() => null));\n /* eslint-enable react-hooks/rules-of-hooks */\n }\n\n const globalState = getGlobalState();\n const { pathname } = useResolvedPath('');\n const html = ReactDom.renderToString((\n <GlobalStateProvider stateProxy={globalState}>\n <StaticRouter\n basename={pathname}\n location={globalState.ssrContext.req.url}\n >\n <Scene {...rest}>\n {children}\n </Scene>\n </StaticRouter>\n </GlobalStateProvider>\n ));\n\n /* 2. `chunks` array is used to record CSS chunks to inject. */\n const { chunks } = globalState.ssrContext;\n if (chunks.includes(chunkName)) {\n throw new Error(`CodeSplit: chunk name clash for (${chunkName})`);\n } else chunks.push(chunkName);\n\n /* The result is rendered using the container with `dangerouslySetInnerHTML`\n * to allow reproduce the same rendering result at the client side, even prior\n * to the async loading of the split code. */\n /* eslint-disable react/no-danger */\n return (\n <div\n dangerouslySetInnerHTML={{ __html: html }}\n data-chunk-name={chunkName}\n />\n );\n /* eslint-enable react/no-danger */\n}\n\nServerSide.propTypes = {\n children: PT.node,\n chunkName: PT.string.isRequired,\n\n // Note: it is not strictly required by <ServerSide> component per se,\n // as it is expected that in most cases \"serverSide\" prop should be provided,\n // however \"getClientSide\" prop is still used as a fallback at the server side\n // and also it is required by the parent splitComponent() function, so no harm\n // to declare it as required here.\n getClientSide: PT.func.isRequired,\n\n placeholder: PT.elementType,\n serverSide: PT.elementType,\n};\n\nServerSide.defaultProps = {\n children: undefined,\n placeholder: null,\n serverSide: undefined,\n};\n"],"file":"ServerSide.js"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=ClientSide;var _react=require("react");var _reactGlobalState=require("@dr.pogodin/react-global-state");var _Barrier=require("../../utils/Barrier");var _isomorphy=require("../../utils/isomorphy");var _time=_interopRequireDefault(require("../../utils/time"));var _jsxRuntime=require("react/jsx-runtime");/**
|
|
2
|
-
* Client-side implementation of a split code chunk.
|
|
3
|
-
*/ /* global document, window */ /* eslint-disable react/jsx-props-no-spreading */function ClientSide({chunkName,children,getClientSide,placeholder,// Not used in <ClientSide>, but should not go into "...rest" either.
|
|
4
|
-
serverSide,...rest}){const{current:heap}=(0,_react.useRef)({mounted:false,pendingStyles:[],renderInitialized:false});// publicPath from buildInfo does not have a trailing slash at the end.
|
|
5
|
-
const{publicPath}=(0,_isomorphy.getBuildInfo)();// This code block initiates style loading as soon as possible, even prior to
|
|
6
|
-
// the component loading, and it collects all style load / failure promises
|
|
7
|
-
// into heap.pendingStyles array, allowing us to wait and thus avoid flash of
|
|
8
|
-
// unstyled content issue (that's why we don't rely on mini-css-extract-plugin
|
|
9
|
-
// to handle CSS chunk mounting and unmounting, which it is able to do).
|
|
10
|
-
if(!heap.mounted){heap.mounted=true;window.CHUNK_GROUPS[chunkName].forEach(asset=>{if(!asset.endsWith(".css"))return;const path=`${publicPath}/${asset}`;let link=document.querySelector(`link[href="${path}"]`);if(!link){link=document.createElement("link");link.setAttribute("href",path);link.setAttribute("rel","stylesheet");const barrier=(0,_Barrier.newBarrier)();link.onload=barrier.resolve;// Even if the style load failed, still allow to mount the component,
|
|
11
|
-
// abeit with broken styling.
|
|
12
|
-
link.onerror=barrier.resolve;heap.pendingStyles.push(barrier);const head=document.querySelector("head");head.appendChild(link)}window.STYLESHEET_USAGE_COUNTERS||={};window.STYLESHEET_USAGE_COUNTERS[path]||=0;++window.STYLESHEET_USAGE_COUNTERS[path]})}// Async loading of React component necessary to render the chunk.
|
|
13
|
-
const{data}=(0,_reactGlobalState.useAsyncData)(`dr_pogodin_react_utils___split_components.${chunkName}`,getClientSide,{maxage:_time.default.YEAR_MS});const createRender=()=>{const Scene=data.default||data;return/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{"data-chunk-name":chunkName,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(Scene,{...rest,children:children})})};const[render,setRender]=(0,_react.useState)(()=>{// No need to await anything, we can render the final component right away.
|
|
14
|
-
if(data&&!heap.pendingStyles.length){heap.renderInitialized=true;return createRender()}// Try to reuse the markup rendered during SSR.
|
|
15
|
-
const node=document.querySelector(`[data-chunk-name=${chunkName}]`);if(node){return/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{/* eslint-disable react/no-danger */dangerouslySetInnerHTML:{__html:node.innerHTML||""}/* eslint-disable react/no-danger */,"data-chunk-name":chunkName})}// Else render placeholder, or empty div.
|
|
16
|
-
const Scene=placeholder||(()=>null);return/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{children:/*#__PURE__*/(0,_jsxRuntime.jsx)(Scene,{...rest,children:children})})});// At this point, if we have data, the absense of heap.renderInitialized flag
|
|
17
|
-
// means we have to await styles loading; once it is done, and if we are still
|
|
18
|
-
// mounted, we can set the final render.
|
|
19
|
-
if(data&&!heap.renderInitialized){heap.renderInitialized=true;Promise.all(heap.pendingStyles).then(()=>{if(heap.mounted)setRender(createRender())})}// This effectively fires only once, just before the component unmounts.
|
|
20
|
-
(0,_react.useEffect)(()=>()=>{heap.mounted=false;window.CHUNK_GROUPS[chunkName].forEach(item=>{if(!item.endsWith(".css"))return;const path=`${publicPath}/${item}`;if(--window.STYLESHEET_USAGE_COUNTERS[path]<=0){const link=document.querySelector(`link[href="${path}"]`);const head=document.querySelector("head");head.removeChild(link)}})},[chunkName,heap,publicPath]);return render}
|
|
21
|
-
//# sourceMappingURL=ClientSide.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/shared/components/CodeSplit/ClientSide.jsx"],"names":["ClientSide","chunkName","children","getClientSide","placeholder","serverSide","rest","current","heap","mounted","pendingStyles","renderInitialized","publicPath","window","CHUNK_GROUPS","forEach","asset","endsWith","path","link","document","querySelector","createElement","setAttribute","barrier","onload","resolve","onerror","push","head","appendChild","STYLESHEET_USAGE_COUNTERS","data","maxage","time","YEAR_MS","createRender","Scene","default","render","setRender","length","node","__html","innerHTML","Promise","all","then","item","removeChild"],"mappings":"oLAMA,4BAEA,gEAEA,4CACA,gDACA,8D,6CAZA;AACA;AACA,G,CACA,6B,CACA,iDAUe,QAASA,CAAAA,UAAT,CAAoB,CACjCC,SADiC,CAEjCC,QAFiC,CAGjCC,aAHiC,CAIjCC,WAJiC,CAMjC;AACAC,UAPiC,CASjC,GAAGC,IAT8B,CAApB,CAUZ,CACD,KAAM,CAAEC,OAAO,CAAEC,IAAX,EAAoB,kBAAO,CAC/BC,OAAO,CAAE,KADsB,CAE/BC,aAAa,CAAE,EAFgB,CAG/BC,iBAAiB,CAAE,KAHY,CAAP,CAA1B,CAMA;AACA,KAAM,CAAEC,UAAF,EAAiB,6BAAvB,CAEA;AACA;AACA;AACA;AACA;AACA,GAAI,CAACJ,IAAI,CAACC,OAAV,CAAmB,CACjBD,IAAI,CAACC,OAAL,CAAe,IAAf,CACAI,MAAM,CAACC,YAAP,CAAoBb,SAApB,EAA+Bc,OAA/B,CAAwCC,KAAD,EAAW,CAChD,GAAI,CAACA,KAAK,CAACC,QAAN,CAAe,MAAf,CAAL,CAA6B,OAC7B,KAAMC,CAAAA,IAAI,CAAI,GAAEN,UAAW,IAAGI,KAAM,EAApC,CACA,GAAIG,CAAAA,IAAI,CAAGC,QAAQ,CAACC,aAAT,CAAwB,cAAaH,IAAK,IAA1C,CAAX,CACA,GAAI,CAACC,IAAL,CAAW,CACTA,IAAI,CAAGC,QAAQ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D,CAXD,CAWG,CAAClB,SAAD,CAAYO,IAAZ,CAAkBI,UAAlB,CAXH,EAaA,MAAO2B,CAAAA,MACR","sourcesContent":["/**\n * Client-side implementation of a split code chunk.\n */\n/* global document, window */\n/* eslint-disable react/jsx-props-no-spreading */\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport { useAsyncData } from '@dr.pogodin/react-global-state';\n\nimport { newBarrier } from 'utils/Barrier';\nimport { getBuildInfo } from 'utils/isomorphy';\nimport time from 'utils/time';\n\nexport default function ClientSide({\n chunkName,\n children,\n getClientSide,\n placeholder,\n\n // Not used in <ClientSide>, but should not go into \"...rest\" either.\n serverSide,\n\n ...rest\n}) {\n const { current: heap } = useRef({\n mounted: false,\n pendingStyles: [],\n renderInitialized: false,\n });\n\n // publicPath from buildInfo does not have a trailing slash at the end.\n const { publicPath } = getBuildInfo();\n\n // This code block initiates style loading as soon as possible, even prior to\n // the component loading, and it collects all style load / failure promises\n // into heap.pendingStyles array, allowing us to wait and thus avoid flash of\n // unstyled content issue (that's why we don't rely on mini-css-extract-plugin\n // to handle CSS chunk mounting and unmounting, which it is able to do).\n if (!heap.mounted) {\n heap.mounted = true;\n window.CHUNK_GROUPS[chunkName].forEach((asset) => {\n if (!asset.endsWith('.css')) return;\n const path = `${publicPath}/${asset}`;\n let link = document.querySelector(`link[href=\"${path}\"]`);\n if (!link) {\n link = document.createElement('link');\n link.setAttribute('href', path);\n link.setAttribute('rel', 'stylesheet');\n\n const barrier = newBarrier();\n link.onload = barrier.resolve;\n\n // Even if the style load failed, still allow to mount the component,\n // abeit with broken styling.\n link.onerror = barrier.resolve;\n\n heap.pendingStyles.push(barrier);\n\n const head = document.querySelector('head');\n head.appendChild(link);\n }\n window.STYLESHEET_USAGE_COUNTERS ||= {};\n window.STYLESHEET_USAGE_COUNTERS[path] ||= 0;\n ++window.STYLESHEET_USAGE_COUNTERS[path];\n });\n }\n\n // Async loading of React component necessary to render the chunk.\n const { data } = useAsyncData(\n `dr_pogodin_react_utils___split_components.${chunkName}`,\n getClientSide,\n { maxage: time.YEAR_MS },\n );\n\n const createRender = () => {\n const Scene = data.default || data;\n return (\n <div data-chunk-name={chunkName}>\n <Scene {...rest}>\n {children}\n </Scene>\n </div>\n );\n };\n\n const [render, setRender] = useState(() => {\n // No need to await anything, we can render the final component right away.\n if (data && !heap.pendingStyles.length) {\n heap.renderInitialized = true;\n return createRender();\n }\n\n // Try to reuse the markup rendered during SSR.\n const node = document.querySelector(`[data-chunk-name=${chunkName}]`);\n if (node) {\n return (\n <div\n /* eslint-disable react/no-danger */\n dangerouslySetInnerHTML={{ __html: node.innerHTML || '' }}\n /* eslint-disable react/no-danger */\n data-chunk-name={chunkName}\n />\n );\n }\n\n // Else render placeholder, or empty div.\n const Scene = placeholder || (() => null);\n return <div><Scene {...rest}>{children}</Scene></div>;\n });\n\n // At this point, if we have data, the absense of heap.renderInitialized flag\n // means we have to await styles loading; once it is done, and if we are still\n // mounted, we can set the final render.\n if (data && !heap.renderInitialized) {\n heap.renderInitialized = true;\n Promise.all(heap.pendingStyles).then(() => {\n if (heap.mounted) setRender(createRender());\n });\n }\n\n // This effectively fires only once, just before the component unmounts.\n useEffect(() => () => {\n heap.mounted = false;\n window.CHUNK_GROUPS[chunkName].forEach((item) => {\n if (!item.endsWith('.css')) return;\n const path = `${publicPath}/${item}`;\n if (--window.STYLESHEET_USAGE_COUNTERS[path] <= 0) {\n const link = document.querySelector(`link[href=\"${path}\"]`);\n const head = document.querySelector('head');\n head.removeChild(link);\n }\n });\n }, [chunkName, heap, publicPath]);\n\n return render;\n}\n"],"file":"ClientSide.js"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=ServerSide;var _server=_interopRequireDefault(require("react-dom/server"));var _propTypes=_interopRequireDefault(require("prop-types"));var _reactGlobalState=require("@dr.pogodin/react-global-state");var _reactRouterDom=require("react-router-dom");var _server2=require("react-router-dom/server");var _jsxRuntime=require("react/jsx-runtime");/**
|
|
2
|
-
* Server-side implementation.
|
|
3
|
-
*/ /* eslint-disable react/jsx-props-no-spreading */function ServerSide({chunkName,getClientSide,serverSide,placeholder,children,...rest}){/* 1. The component, or its placeholder is rendered into HTML string.
|
|
4
|
-
* The component is wrapped into <GlobalStateProvider>, and <StaticRouter>
|
|
5
|
-
* to ensure that global state, and react router will work inside
|
|
6
|
-
* the component, if present there. Also, if no server-side (sync) way
|
|
7
|
-
* to load the component is provider, `useAsyncData(..)` is used to
|
|
8
|
-
* attempt to load and use the component via SSR mechanics. */let Scene;if(serverSide)Scene=serverSide;else{// In this case we are sure the condition won't change during the rendering
|
|
9
|
-
// loop, thus we can ignore the rule.
|
|
10
|
-
/* eslint-disable react-hooks/rules-of-hooks */const{data}=(0,_reactGlobalState.useAsyncData)(`dr_pogodin_react_utils___split_components.${chunkName}`,getClientSide);Scene=data?data.default||data:placeholder||(()=>null);/* eslint-enable react-hooks/rules-of-hooks */}const globalState=(0,_reactGlobalState.getGlobalState)();const{pathname}=(0,_reactRouterDom.useResolvedPath)("");const html=_server.default.renderToString(/*#__PURE__*/(0,_jsxRuntime.jsx)(_reactGlobalState.GlobalStateProvider,{stateProxy:globalState,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(_server2.StaticRouter,{basename:pathname,location:globalState.ssrContext.req.url,children:/*#__PURE__*/(0,_jsxRuntime.jsx)(Scene,{...rest,children:children})})}));/* 2. `chunks` array is used to record CSS chunks to inject. */const{chunks}=globalState.ssrContext;if(chunks.includes(chunkName)){throw new Error(`CodeSplit: chunk name clash for (${chunkName})`)}else chunks.push(chunkName);/* The result is rendered using the container with `dangerouslySetInnerHTML`
|
|
11
|
-
* to allow reproduce the same rendering result at the client side, even prior
|
|
12
|
-
* to the async loading of the split code. */ /* eslint-disable react/no-danger */return/*#__PURE__*/(0,_jsxRuntime.jsx)("div",{dangerouslySetInnerHTML:{__html:html},"data-chunk-name":chunkName});/* eslint-enable react/no-danger */}ServerSide.propTypes={children:_propTypes.default.node,chunkName:_propTypes.default.string.isRequired,// Note: it is not strictly required by <ServerSide> component per se,
|
|
13
|
-
// as it is expected that in most cases "serverSide" prop should be provided,
|
|
14
|
-
// however "getClientSide" prop is still used as a fallback at the server side
|
|
15
|
-
// and also it is required by the parent splitComponent() function, so no harm
|
|
16
|
-
// to declare it as required here.
|
|
17
|
-
getClientSide:_propTypes.default.func.isRequired,placeholder:_propTypes.default.elementType,serverSide:_propTypes.default.elementType};ServerSide.defaultProps={children:undefined,placeholder:null,serverSide:undefined};
|
|
18
|
-
//# sourceMappingURL=ServerSide.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/shared/components/CodeSplit/ServerSide.jsx"],"names":["ServerSide","chunkName","getClientSide","serverSide","placeholder","children","rest","Scene","data","default","globalState","pathname","html","ReactDom","renderToString","ssrContext","req","url","chunks","includes","Error","push","__html","propTypes","PT","node","string","isRequired","func","elementType","defaultProps","undefined"],"mappings":"oLAKA,gEACA,6DAEA,gEAMA,gDACA,gD,6CAfA;AACA;AACA,G,CACA,iDAce,QAASA,CAAAA,UAAT,CAAoB,CACjCC,SADiC,CAEjCC,aAFiC,CAGjCC,UAHiC,CAIjCC,WAJiC,CAKjCC,QALiC,CAMjC,GAAGC,IAN8B,CAApB,CAOZ,CACD;AACF;AACA;AACA;AACA;AACA,mEACE,GAAIC,CAAAA,KAAJ,CACA,GAAIJ,UAAJ,CAAgBI,KAAK,CAAGJ,UAAR,CAAhB,IACK,CACH;AACA;AACA,+CACA,KAAM,CAAEK,IAAF,EAAW,mCACd,6CAA4CP,SAAU,EADxC,CAEfC,aAFe,CAAjB,CAIAK,KAAK,CAAGC,IAAI,CAAIA,IAAI,CAACC,OAAL,EAAgBD,IAApB,CAA6BJ,WAAW,GAAK,IAAM,IAAX,CAApD,CACA,8CACD,CAED,KAAMM,CAAAA,WAAW,CAAG,sCAApB,CACA,KAAM,CAAEC,QAAF,EAAe,oCAAgB,EAAhB,CAArB,CACA,KAAMC,CAAAA,IAAI,CAAGC,gBAASC,cAAT,cACX,oBAAC,qCAAD,EAAqB,UAAU,CAAEJ,WAAjC,uBACE,oBAAC,qBAAD,EACE,QAAQ,CAAEC,QADZ,CAEE,QAAQ,CAAED,WAAW,CAACK,UAAZ,CAAuBC,GAAvB,CAA2BC,GAFvC,uBAIE,oBAAC,KAAD,KAAWX,IAAX,UACGD,QADH,EAJF,EADF,EADW,CAAb,CAaA,+DACA,KAAM,CAAEa,MAAF,EAAaR,WAAW,CAACK,UAA/B,CACA,GAAIG,MAAM,CAACC,QAAP,CAAgBlB,SAAhB,CAAJ,CAAgC,CAC9B,KAAM,IAAImB,CAAAA,KAAJ,CAAW,oCAAmCnB,SAAU,GAAxD,CACP,CAFD,IAEOiB,CAAAA,MAAM,CAACG,IAAP,CAAYpB,SAAZ,EAEP;AACF;AACA,+CA5CG,CA6CD,oCACA,mBACE,2BACE,uBAAuB,CAAE,CAAEqB,MAAM,CAAEV,IAAV,CAD3B,CAEE,kBAAiBX,SAFnB,EADF,CAMA,mCACD,CAEDD,UAAU,CAACuB,SAAX,CAAuB,CACrBlB,QAAQ,CAAEmB,mBAAGC,IADQ,CAErBxB,SAAS,CAAEuB,mBAAGE,MAAH,CAAUC,UAFA,CAIrB;AACA;AACA;AACA;AACA;AACAzB,aAAa,CAAEsB,mBAAGI,IAAH,CAAQD,UATF,CAWrBvB,WAAW,CAAEoB,mBAAGK,WAXK,CAYrB1B,UAAU,CAAEqB,mBAAGK,WAZM,CAAvB,CAeA7B,UAAU,CAAC8B,YAAX,CAA0B,CACxBzB,QAAQ,CAAE0B,SADc,CAExB3B,WAAW,CAAE,IAFW,CAGxBD,UAAU,CAAE4B,SAHY,CAA1B","sourcesContent":["/**\n * Server-side implementation.\n */\n/* eslint-disable react/jsx-props-no-spreading */\n\nimport ReactDom from 'react-dom/server';\nimport PT from 'prop-types';\n\nimport {\n getGlobalState,\n GlobalStateProvider,\n useAsyncData,\n} from '@dr.pogodin/react-global-state';\n\nimport { useResolvedPath } from 'react-router-dom';\nimport { StaticRouter } from 'react-router-dom/server';\n\nexport default function ServerSide({\n chunkName,\n getClientSide,\n serverSide,\n placeholder,\n children,\n ...rest\n}) {\n /* 1. The component, or its placeholder is rendered into HTML string.\n * The component is wrapped into <GlobalStateProvider>, and <StaticRouter>\n * to ensure that global state, and react router will work inside\n * the component, if present there. Also, if no server-side (sync) way\n * to load the component is provider, `useAsyncData(..)` is used to\n * attempt to load and use the component via SSR mechanics. */\n let Scene;\n if (serverSide) Scene = serverSide;\n else {\n // In this case we are sure the condition won't change during the rendering\n // loop, thus we can ignore the rule.\n /* eslint-disable react-hooks/rules-of-hooks */\n const { data } = useAsyncData(\n `dr_pogodin_react_utils___split_components.${chunkName}`,\n getClientSide,\n );\n Scene = data ? (data.default || data) : (placeholder || (() => null));\n /* eslint-enable react-hooks/rules-of-hooks */\n }\n\n const globalState = getGlobalState();\n const { pathname } = useResolvedPath('');\n const html = ReactDom.renderToString((\n <GlobalStateProvider stateProxy={globalState}>\n <StaticRouter\n basename={pathname}\n location={globalState.ssrContext.req.url}\n >\n <Scene {...rest}>\n {children}\n </Scene>\n </StaticRouter>\n </GlobalStateProvider>\n ));\n\n /* 2. `chunks` array is used to record CSS chunks to inject. */\n const { chunks } = globalState.ssrContext;\n if (chunks.includes(chunkName)) {\n throw new Error(`CodeSplit: chunk name clash for (${chunkName})`);\n } else chunks.push(chunkName);\n\n /* The result is rendered using the container with `dangerouslySetInnerHTML`\n * to allow reproduce the same rendering result at the client side, even prior\n * to the async loading of the split code. */\n /* eslint-disable react/no-danger */\n return (\n <div\n dangerouslySetInnerHTML={{ __html: html }}\n data-chunk-name={chunkName}\n />\n );\n /* eslint-enable react/no-danger */\n}\n\nServerSide.propTypes = {\n children: PT.node,\n chunkName: PT.string.isRequired,\n\n // Note: it is not strictly required by <ServerSide> component per se,\n // as it is expected that in most cases \"serverSide\" prop should be provided,\n // however \"getClientSide\" prop is still used as a fallback at the server side\n // and also it is required by the parent splitComponent() function, so no harm\n // to declare it as required here.\n getClientSide: PT.func.isRequired,\n\n placeholder: PT.elementType,\n serverSide: PT.elementType,\n};\n\nServerSide.defaultProps = {\n children: undefined,\n placeholder: null,\n serverSide: undefined,\n};\n"],"file":"ServerSide.js"}
|