@dr.pogodin/react-utils 1.35.3 → 1.35.5
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/bin/build.js +7 -6
- package/build/development/client/getInj.js +3 -10
- package/build/development/client/getInj.js.map +1 -1
- package/build/development/client/index.js +2 -9
- package/build/development/client/index.js.map +1 -1
- package/build/development/index.js +1 -9
- package/build/development/index.js.map +1 -1
- package/build/development/shared/components/selectors/common.js.map +1 -1
- package/build/development/shared/utils/globalState.js.map +1 -1
- package/build/development/shared/utils/splitComponent.js +10 -16
- package/build/development/shared/utils/splitComponent.js.map +1 -1
- package/build/development/web.bundle.js +4 -4
- package/build/production/client/getInj.js +3 -7
- package/build/production/client/getInj.js.map +1 -1
- package/build/production/client/index.js +1 -1
- package/build/production/client/index.js.map +1 -1
- package/build/production/index.js +1 -4
- package/build/production/index.js.map +1 -1
- package/build/production/shared/components/selectors/common.js.map +1 -1
- package/build/production/shared/utils/globalState.js.map +1 -1
- package/build/production/shared/utils/splitComponent.js +7 -9
- package/build/production/shared/utils/splitComponent.js.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/build/types-code/client/getInj.d.ts +0 -6
- package/build/types-code/client/index.d.ts +1 -2
- package/build/types-code/index.d.ts +1 -1
- package/build/types-code/shared/components/selectors/common.d.ts +1 -1
- package/build/types-code/shared/utils/globalState.d.ts +5 -0
- package/package.json +15 -15
- package/src/client/getInj.ts +3 -9
- package/src/client/index.tsx +1 -3
- package/src/index.ts +1 -9
- package/src/shared/components/selectors/common.ts +1 -1
- package/src/shared/utils/globalState.ts +6 -0
- package/src/shared/utils/splitComponent.tsx +10 -18
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import 'node-forge/lib/aes';
|
|
2
2
|
import type { InjT } from '../shared/utils/globalState';
|
|
3
3
|
export default function getInj(): InjT;
|
|
4
|
-
/**
|
|
5
|
-
* Allows to set a custom injection object instance,
|
|
6
|
-
* for server-less scenarios, for example, where it is not auto-injected
|
|
7
|
-
* into generated pages from the server side.
|
|
8
|
-
*/
|
|
9
|
-
export declare function setInj(value: InjT): void;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { type ComponentType } from 'react';
|
|
2
|
-
import { setInj } from './getInj';
|
|
3
2
|
type OptionsT = {
|
|
4
3
|
dontHydrate?: boolean;
|
|
5
4
|
initialState?: any;
|
|
6
5
|
};
|
|
7
|
-
export { setInj };
|
|
8
6
|
/**
|
|
9
7
|
* Prepares and launches the app at client side.
|
|
10
8
|
* @param Application Root application component
|
|
11
9
|
* @param [options={}] Optional. Additional settings.
|
|
12
10
|
*/
|
|
13
11
|
export default function Launch(Application: ComponentType, options?: OptionsT): void;
|
|
12
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'styles/global.scss';
|
|
2
2
|
import type ServerT from './server';
|
|
3
3
|
declare const server: typeof ServerT | null;
|
|
4
|
-
declare
|
|
4
|
+
declare const client: any;
|
|
5
5
|
export { default as api } from 'axios';
|
|
6
6
|
export * as PT from 'prop-types';
|
|
7
7
|
export { type AsyncCollectionLoaderT, type AsyncDataEnvelopeT, type AsyncDataLoaderT, type ForceT, type UseAsyncDataOptionsT, type UseAsyncDataResT, type UseGlobalStateResT, type ValueOrInitializerT, getGlobalState, GlobalStateProvider, newAsyncDataEnvelope, useAsyncCollection, useAsyncData, useGlobalState, withGlobalStateType, } from '@dr.pogodin/react-global-state';
|
|
@@ -8,7 +8,7 @@ export type OptionT<NameT> = {
|
|
|
8
8
|
name?: NameT | null;
|
|
9
9
|
value: ValueT;
|
|
10
10
|
};
|
|
11
|
-
export type OptionsT<NameT> = Array<OptionT<NameT> | ValueT
|
|
11
|
+
export type OptionsT<NameT> = Readonly<Array<OptionT<NameT> | ValueT>>;
|
|
12
12
|
export type PropsT<NameT, OnChangeT = React.ChangeEventHandler<HTMLSelectElement>> = {
|
|
13
13
|
filter?: (item: OptionT<NameT> | ValueT) => boolean;
|
|
14
14
|
label?: React.ReactNode;
|
|
@@ -11,6 +11,11 @@ export type InjT = {
|
|
|
11
11
|
};
|
|
12
12
|
ISTATE?: unknown;
|
|
13
13
|
};
|
|
14
|
+
declare global {
|
|
15
|
+
interface Window {
|
|
16
|
+
REACT_UTILS_INJECTION?: InjT;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
14
19
|
export interface SsrContextT<StateT> extends SsrContext<StateT> {
|
|
15
20
|
chunkGroups: ChunkGroupsT;
|
|
16
21
|
chunks: string[];
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.35.
|
|
2
|
+
"version": "1.35.5",
|
|
3
3
|
"bin": {
|
|
4
4
|
"react-utils-build": "bin/build.js",
|
|
5
5
|
"react-utils-setup": "bin/setup.js"
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"url": "https://github.com/birdofpreyru/react-utils/issues"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@babel/runtime": "^7.24.
|
|
12
|
-
"@dr.pogodin/babel-plugin-react-css-modules": "^6.13.
|
|
11
|
+
"@babel/runtime": "^7.24.7",
|
|
12
|
+
"@dr.pogodin/babel-plugin-react-css-modules": "^6.13.2",
|
|
13
13
|
"@dr.pogodin/csurf": "^1.13.0",
|
|
14
14
|
"@dr.pogodin/js-utils": "^0.0.12",
|
|
15
15
|
"@dr.pogodin/react-global-state": "^0.14.2",
|
|
@@ -42,20 +42,20 @@
|
|
|
42
42
|
"serialize-javascript": "^6.0.2",
|
|
43
43
|
"serve-favicon": "^2.5.0",
|
|
44
44
|
"source-map-support": "^0.5.21",
|
|
45
|
-
"uuid": "^
|
|
45
|
+
"uuid": "^10.0.0",
|
|
46
46
|
"winston": "^3.13.0"
|
|
47
47
|
},
|
|
48
48
|
"description": "Collection of generic ReactJS components and utils",
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@babel/cli": "^7.24.
|
|
51
|
-
"@babel/core": "^7.24.
|
|
52
|
-
"@babel/eslint-parser": "^7.24.
|
|
53
|
-
"@babel/eslint-plugin": "^7.24.
|
|
54
|
-
"@babel/node": "^7.24.
|
|
55
|
-
"@babel/plugin-transform-runtime": "^7.24.
|
|
56
|
-
"@babel/preset-env": "^7.24.
|
|
57
|
-
"@babel/preset-react": "^7.24.
|
|
58
|
-
"@babel/preset-typescript": "^7.24.
|
|
50
|
+
"@babel/cli": "^7.24.7",
|
|
51
|
+
"@babel/core": "^7.24.7",
|
|
52
|
+
"@babel/eslint-parser": "^7.24.7",
|
|
53
|
+
"@babel/eslint-plugin": "^7.24.7",
|
|
54
|
+
"@babel/node": "^7.24.7",
|
|
55
|
+
"@babel/plugin-transform-runtime": "^7.24.7",
|
|
56
|
+
"@babel/preset-env": "^7.24.7",
|
|
57
|
+
"@babel/preset-react": "^7.24.7",
|
|
58
|
+
"@babel/preset-typescript": "^7.24.7",
|
|
59
59
|
"@babel/register": "^7.24.6",
|
|
60
60
|
"@dr.pogodin/babel-plugin-transform-assets": "^1.2.2",
|
|
61
61
|
"@dr.pogodin/babel-preset-svgr": "^1.8.0",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@types/csurf": "^1.11.5",
|
|
72
72
|
"@types/express": "^4.17.21",
|
|
73
73
|
"@types/jest": "^29.5.12",
|
|
74
|
-
"@types/lodash": "^4.17.
|
|
74
|
+
"@types/lodash": "^4.17.5",
|
|
75
75
|
"@types/morgan": "^1.9.9",
|
|
76
76
|
"@types/node-forge": "^1.3.11",
|
|
77
77
|
"@types/pretty": "^2.0.3",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
97
97
|
"eslint-import-resolver-babel-module": "^5.3.2",
|
|
98
98
|
"eslint-plugin-import": "^2.29.1",
|
|
99
|
-
"eslint-plugin-jest": "^28.
|
|
99
|
+
"eslint-plugin-jest": "^28.6.0",
|
|
100
100
|
"eslint-plugin-jsx-a11y": "^6.8.0",
|
|
101
101
|
"eslint-plugin-react": "^7.34.2",
|
|
102
102
|
"eslint-plugin-react-hooks": "^4.6.2",
|
package/src/client/getInj.ts
CHANGED
|
@@ -31,6 +31,9 @@ if (metaElement) {
|
|
|
31
31
|
|
|
32
32
|
data = forge.util.decodeUtf8(d.output.data);
|
|
33
33
|
inj = eval(`(${data})`); // eslint-disable-line no-eval
|
|
34
|
+
} else if (typeof window !== 'undefined' && window.REACT_UTILS_INJECTION) {
|
|
35
|
+
inj = window.REACT_UTILS_INJECTION;
|
|
36
|
+
delete window.REACT_UTILS_INJECTION;
|
|
34
37
|
} else {
|
|
35
38
|
// Otherwise, a bunch of dependent stuff will easily fail in non-standard
|
|
36
39
|
// environments, where no client-side initialization is performed. Like tests,
|
|
@@ -41,12 +44,3 @@ if (metaElement) {
|
|
|
41
44
|
export default function getInj(): InjT {
|
|
42
45
|
return inj;
|
|
43
46
|
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Allows to set a custom injection object instance,
|
|
47
|
-
* for server-less scenarios, for example, where it is not auto-injected
|
|
48
|
-
* into generated pages from the server side.
|
|
49
|
-
*/
|
|
50
|
-
export function setInj(value: InjT) {
|
|
51
|
-
inj = value;
|
|
52
|
-
}
|
package/src/client/index.tsx
CHANGED
|
@@ -8,15 +8,13 @@ import { GlobalStateProvider } from '@dr.pogodin/react-global-state';
|
|
|
8
8
|
import { createRoot, hydrateRoot } from 'react-dom/client';
|
|
9
9
|
import { BrowserRouter } from 'react-router-dom';
|
|
10
10
|
|
|
11
|
-
import getInj
|
|
11
|
+
import getInj from './getInj';
|
|
12
12
|
|
|
13
13
|
type OptionsT = {
|
|
14
14
|
dontHydrate?: boolean;
|
|
15
15
|
initialState?: any;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export { setInj };
|
|
19
|
-
|
|
20
18
|
/**
|
|
21
19
|
* Prepares and launches the app at client side.
|
|
22
20
|
* @param Application Root application component
|
package/src/index.ts
CHANGED
|
@@ -6,15 +6,7 @@ import type ServerT from './server';
|
|
|
6
6
|
|
|
7
7
|
const server = webpack.requireWeak('./server', __dirname) as (typeof ServerT) | null;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
// for this scenario.
|
|
11
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
12
|
-
let client = server ? undefined : require('./client');
|
|
13
|
-
|
|
14
|
-
if (client) {
|
|
15
|
-
client.default.setInj = client.setInj;
|
|
16
|
-
client = client.default;
|
|
17
|
-
}
|
|
9
|
+
const client = server ? undefined : require('./client').default;
|
|
18
10
|
|
|
19
11
|
export { default as api } from 'axios';
|
|
20
12
|
export * as PT from 'prop-types';
|
|
@@ -13,6 +13,12 @@ export type InjT = {
|
|
|
13
13
|
ISTATE?: unknown;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
declare global {
|
|
17
|
+
interface Window {
|
|
18
|
+
REACT_UTILS_INJECTION?: InjT;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
export interface SsrContextT<StateT> extends SsrContext<StateT> {
|
|
17
23
|
chunkGroups: ChunkGroupsT;
|
|
18
24
|
chunks: string[];
|
|
@@ -22,23 +22,15 @@ import {
|
|
|
22
22
|
getBuildInfo,
|
|
23
23
|
} from './isomorphy';
|
|
24
24
|
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
// alongside custom chunk info injection in server-less scenario);
|
|
28
|
-
// at the server-side we only can get them within React render flow.
|
|
25
|
+
// Note: At the client side we can get chunk groups immediately when loading
|
|
26
|
+
// the module; at the server-side we only can get them within React render flow.
|
|
29
27
|
// Thus, we set and use the following variable at the client-side, and then when
|
|
30
28
|
// needed on the server side, we'll fetch it differently.
|
|
31
|
-
let
|
|
29
|
+
let clientChunkGroups: ChunkGroupsT;
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
cachedClientChunkGroups = require('client/getInj').default().CHUNK_GROUPS || {};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!cachedClientChunkGroups) throw Error('Internal error');
|
|
40
|
-
|
|
41
|
-
return cachedClientChunkGroups;
|
|
31
|
+
if (IS_CLIENT_SIDE) {
|
|
32
|
+
// eslint-disable-next-line global-require
|
|
33
|
+
clientChunkGroups = require('client/getInj').default().CHUNK_GROUPS || {};
|
|
42
34
|
}
|
|
43
35
|
|
|
44
36
|
const refCounts: { [path: string]: number } = {};
|
|
@@ -193,7 +185,7 @@ export default function splitComponent<
|
|
|
193
185
|
placeholder?: ReactNode,
|
|
194
186
|
}) {
|
|
195
187
|
// On the client side we can check right away if the chunk name is known.
|
|
196
|
-
if (IS_CLIENT_SIDE) assertChunkName(chunkName,
|
|
188
|
+
if (IS_CLIENT_SIDE) assertChunkName(chunkName, clientChunkGroups);
|
|
197
189
|
|
|
198
190
|
// The correct usage of splitComponent() assumes a single call per chunk.
|
|
199
191
|
if (usedChunkNames.has(chunkName)) {
|
|
@@ -208,7 +200,7 @@ export default function splitComponent<
|
|
|
208
200
|
// the component (the lazy load function is executed by React one at
|
|
209
201
|
// the frist mount).
|
|
210
202
|
if (IS_CLIENT_SIDE) {
|
|
211
|
-
await bookStyleSheets(chunkName,
|
|
203
|
+
await bookStyleSheets(chunkName, clientChunkGroups, false);
|
|
212
204
|
}
|
|
213
205
|
|
|
214
206
|
const Wrapper = forwardRef((
|
|
@@ -226,8 +218,8 @@ export default function splitComponent<
|
|
|
226
218
|
// This takes care about stylesheets management every time an instance of
|
|
227
219
|
// this component is mounted / unmounted.
|
|
228
220
|
useInsertionEffect(() => {
|
|
229
|
-
bookStyleSheets(chunkName,
|
|
230
|
-
return () => freeStyleSheets(chunkName,
|
|
221
|
+
bookStyleSheets(chunkName, clientChunkGroups, true);
|
|
222
|
+
return () => freeStyleSheets(chunkName, clientChunkGroups);
|
|
231
223
|
}, []);
|
|
232
224
|
|
|
233
225
|
return (
|