@dr.pogodin/react-utils 1.35.3 → 1.36.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.
Files changed (185) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin/build.js +7 -6
  3. package/build/development/client/getInj.js +3 -10
  4. package/build/development/client/getInj.js.map +1 -1
  5. package/build/development/client/index.js +2 -9
  6. package/build/development/client/index.js.map +1 -1
  7. package/build/development/index.js +1 -15
  8. package/build/development/index.js.map +1 -1
  9. package/build/development/server/Cache.js +19 -19
  10. package/build/development/server/Cache.js.map +1 -1
  11. package/build/development/server/renderer.js +7 -4
  12. package/build/development/server/renderer.js.map +1 -1
  13. package/build/development/server/server.js +4 -1
  14. package/build/development/server/server.js.map +1 -1
  15. package/build/development/shared/components/Button/index.js +1 -16
  16. package/build/development/shared/components/Button/index.js.map +1 -1
  17. package/build/development/shared/components/Checkbox/index.js +1 -29
  18. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  19. package/build/development/shared/components/GenericLink/index.js +0 -15
  20. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  21. package/build/development/shared/components/Input/index.js +1 -8
  22. package/build/development/shared/components/Input/index.js.map +1 -1
  23. package/build/development/shared/components/MetaTags.js +0 -12
  24. package/build/development/shared/components/MetaTags.js.map +1 -1
  25. package/build/development/shared/components/Modal/index.js +2 -13
  26. package/build/development/shared/components/Modal/index.js.map +1 -1
  27. package/build/development/shared/components/PageLayout/index.js +1 -10
  28. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  29. package/build/development/shared/components/TextArea/index.js +1 -12
  30. package/build/development/shared/components/TextArea/index.js.map +1 -1
  31. package/build/development/shared/components/Throbber/index.js +1 -6
  32. package/build/development/shared/components/Throbber/index.js.map +1 -1
  33. package/build/development/shared/components/WithTooltip/Tooltip.js +1 -8
  34. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  35. package/build/development/shared/components/WithTooltip/index.js +1 -9
  36. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  37. package/build/development/shared/components/YouTubeVideo/index.js +2 -11
  38. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  39. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js +1 -16
  40. package/build/development/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  41. package/build/development/shared/components/selectors/CustomDropdown/index.js +2 -12
  42. package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  43. package/build/development/shared/components/selectors/NativeDropdown/index.js +2 -12
  44. package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  45. package/build/development/shared/components/selectors/Switch/index.js +21 -28
  46. package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
  47. package/build/development/shared/components/selectors/common.js +0 -19
  48. package/build/development/shared/components/selectors/common.js.map +1 -1
  49. package/build/development/shared/components/selectors/index.js +0 -13
  50. package/build/development/shared/components/selectors/index.js.map +1 -1
  51. package/build/development/shared/utils/globalState.js.map +1 -1
  52. package/build/development/shared/utils/jest/index.js +4 -2
  53. package/build/development/shared/utils/jest/index.js.map +1 -1
  54. package/build/development/shared/utils/splitComponent.js +21 -28
  55. package/build/development/shared/utils/splitComponent.js.map +1 -1
  56. package/build/development/web.bundle.js +28 -38
  57. package/build/production/client/getInj.js +3 -7
  58. package/build/production/client/getInj.js.map +1 -1
  59. package/build/production/client/index.js +1 -1
  60. package/build/production/client/index.js.map +1 -1
  61. package/build/production/index.js +1 -4
  62. package/build/production/index.js.map +1 -1
  63. package/build/production/server/Cache.js +3 -3
  64. package/build/production/server/Cache.js.map +1 -1
  65. package/build/production/server/renderer.js +2 -2
  66. package/build/production/server/renderer.js.map +1 -1
  67. package/build/production/server/server.js +1 -1
  68. package/build/production/server/server.js.map +1 -1
  69. package/build/production/shared/components/Button/index.js +3 -3
  70. package/build/production/shared/components/Button/index.js.map +1 -1
  71. package/build/production/shared/components/Checkbox/index.js +1 -16
  72. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  73. package/build/production/shared/components/GenericLink/index.js +2 -2
  74. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  75. package/build/production/shared/components/Input/index.js +2 -2
  76. package/build/production/shared/components/Input/index.js.map +1 -1
  77. package/build/production/shared/components/MetaTags.js +2 -2
  78. package/build/production/shared/components/MetaTags.js.map +1 -1
  79. package/build/production/shared/components/Modal/index.js +2 -2
  80. package/build/production/shared/components/Modal/index.js.map +1 -1
  81. package/build/production/shared/components/PageLayout/index.js +2 -2
  82. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  83. package/build/production/shared/components/TextArea/index.js +2 -2
  84. package/build/production/shared/components/TextArea/index.js.map +1 -1
  85. package/build/production/shared/components/Throbber/index.js +2 -2
  86. package/build/production/shared/components/Throbber/index.js.map +1 -1
  87. package/build/production/shared/components/WithTooltip/Tooltip.js +3 -3
  88. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  89. package/build/production/shared/components/WithTooltip/index.js +2 -2
  90. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  91. package/build/production/shared/components/YouTubeVideo/index.js +3 -3
  92. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  93. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js +2 -2
  94. package/build/production/shared/components/selectors/CustomDropdown/Options/index.js.map +1 -1
  95. package/build/production/shared/components/selectors/CustomDropdown/index.js +2 -2
  96. package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
  97. package/build/production/shared/components/selectors/NativeDropdown/index.js +3 -3
  98. package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
  99. package/build/production/shared/components/selectors/Switch/index.js +1 -1
  100. package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
  101. package/build/production/shared/components/selectors/common.js +2 -4
  102. package/build/production/shared/components/selectors/common.js.map +1 -1
  103. package/build/production/shared/components/selectors/index.js +1 -1
  104. package/build/production/shared/components/selectors/index.js.map +1 -1
  105. package/build/production/shared/utils/globalState.js.map +1 -1
  106. package/build/production/shared/utils/jest/index.js +1 -1
  107. package/build/production/shared/utils/jest/index.js.map +1 -1
  108. package/build/production/shared/utils/splitComponent.js +10 -12
  109. package/build/production/shared/utils/splitComponent.js.map +1 -1
  110. package/build/production/web.bundle.js +1 -1
  111. package/build/production/web.bundle.js.map +1 -1
  112. package/build/types-code/client/getInj.d.ts +0 -6
  113. package/build/types-code/client/index.d.ts +1 -2
  114. package/build/types-code/index.d.ts +2 -3
  115. package/build/types-code/server/Cache.d.ts +3 -11
  116. package/build/types-code/server/index.d.ts +0 -2
  117. package/build/types-code/server/renderer.d.ts +0 -1
  118. package/build/types-code/server/server.d.ts +0 -1
  119. package/build/types-code/shared/components/Button/index.d.ts +3 -4
  120. package/build/types-code/shared/components/Checkbox/index.d.ts +3 -12
  121. package/build/types-code/shared/components/Input/index.d.ts +4 -5
  122. package/build/types-code/shared/components/Link.d.ts +0 -1
  123. package/build/types-code/shared/components/Modal/index.d.ts +3 -4
  124. package/build/types-code/shared/components/NavLink.d.ts +0 -1
  125. package/build/types-code/shared/components/PageLayout/index.d.ts +4 -4
  126. package/build/types-code/shared/components/TextArea/index.d.ts +4 -5
  127. package/build/types-code/shared/components/Throbber/index.d.ts +4 -4
  128. package/build/types-code/shared/components/WithTooltip/Tooltip.d.ts +1 -1
  129. package/build/types-code/shared/components/WithTooltip/index.d.ts +2 -3
  130. package/build/types-code/shared/components/YouTubeVideo/index.d.ts +3 -4
  131. package/build/types-code/shared/components/selectors/CustomDropdown/Options/index.d.ts +1 -2
  132. package/build/types-code/shared/components/selectors/CustomDropdown/index.d.ts +2 -3
  133. package/build/types-code/shared/components/selectors/NativeDropdown/index.d.ts +2 -2
  134. package/build/types-code/shared/components/selectors/Switch/index.d.ts +4 -5
  135. package/build/types-code/shared/components/selectors/common.d.ts +5 -11
  136. package/build/types-code/shared/components/selectors/index.d.ts +1 -1
  137. package/build/types-code/shared/utils/globalState.d.ts +6 -2
  138. package/build/types-code/shared/utils/jest/index.d.ts +4 -1
  139. package/build/types-code/shared/utils/splitComponent.d.ts +0 -1
  140. package/build/types-code/shared/utils/webpack.d.ts +0 -1
  141. package/config/babel/node-ssr.js +1 -1
  142. package/config/babel/webpack.js +1 -1
  143. package/config/eslint/default.json +1 -0
  144. package/config/eslint/jest.json +1 -0
  145. package/config/eslint/typescript.js +7 -0
  146. package/config/typescript/base.json +9 -0
  147. package/config/webpack/app-base.d.ts +0 -1
  148. package/config/webpack/app-base.js +1 -1
  149. package/config/webpack/app-development.js +1 -1
  150. package/config/webpack/app-production.js +1 -1
  151. package/config/webpack/lib-base.js +1 -2
  152. package/config/webpack/lib-development.js +1 -1
  153. package/config/webpack/lib-production.js +1 -1
  154. package/package.json +28 -27
  155. package/src/client/getInj.ts +3 -9
  156. package/src/client/index.tsx +1 -3
  157. package/src/index.ts +1 -10
  158. package/src/server/Cache.ts +31 -30
  159. package/src/server/renderer.tsx +8 -5
  160. package/src/server/server.ts +6 -1
  161. package/src/shared/components/Button/index.tsx +2 -20
  162. package/src/shared/components/Checkbox/index.tsx +2 -37
  163. package/src/shared/components/GenericLink/index.tsx +0 -15
  164. package/src/shared/components/Input/index.tsx +6 -15
  165. package/src/shared/components/MetaTags.tsx +0 -12
  166. package/src/shared/components/Modal/index.tsx +3 -22
  167. package/src/shared/components/PageLayout/index.tsx +8 -24
  168. package/src/shared/components/TextArea/index.tsx +6 -24
  169. package/src/shared/components/Throbber/index.tsx +6 -18
  170. package/src/shared/components/WithTooltip/Tooltip.tsx +6 -14
  171. package/src/shared/components/WithTooltip/index.tsx +3 -24
  172. package/src/shared/components/YouTubeVideo/index.tsx +3 -20
  173. package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +2 -20
  174. package/src/shared/components/selectors/CustomDropdown/index.tsx +3 -27
  175. package/src/shared/components/selectors/NativeDropdown/index.tsx +3 -27
  176. package/src/shared/components/selectors/Switch/index.tsx +34 -50
  177. package/src/shared/components/selectors/common.ts +13 -45
  178. package/src/shared/components/selectors/index.ts +0 -2
  179. package/src/shared/utils/globalState.ts +6 -0
  180. package/src/shared/utils/jest/index.tsx +13 -2
  181. package/src/shared/utils/splitComponent.tsx +24 -29
  182. package/tsconfig.configs.json +7 -3
  183. package/tsconfig.json +3 -10
  184. package/tsconfig.types.json +1 -7
  185. package/tstyche.config.json +6 -0
@@ -1,8 +1,6 @@
1
1
  /* eslint-disable react/jsx-props-no-spreading */
2
2
  /* global document */
3
3
 
4
- import PT from 'prop-types';
5
-
6
4
  import {
7
5
  type ComponentType,
8
6
  type ReactNode,
@@ -22,23 +20,15 @@ import {
22
20
  getBuildInfo,
23
21
  } from './isomorphy';
24
22
 
25
- // NOTE: At the client-side we get chunk groups the first time they are needed
26
- // (we used to get them eagerly when this module loaded, but it did not work well
27
- // alongside custom chunk info injection in server-less scenario);
28
- // at the server-side we only can get them within React render flow.
23
+ // Note: At the client side we can get chunk groups immediately when loading
24
+ // the module; at the server-side we only can get them within React render flow.
29
25
  // Thus, we set and use the following variable at the client-side, and then when
30
26
  // needed on the server side, we'll fetch it differently.
31
- let cachedClientChunkGroups: ChunkGroupsT | undefined;
32
-
33
- function getClientChunkGroups(): ChunkGroupsT {
34
- if (IS_CLIENT_SIDE && !cachedClientChunkGroups) {
35
- // eslint-disable-next-line global-require
36
- cachedClientChunkGroups = require('client/getInj').default().CHUNK_GROUPS || {};
37
- }
38
-
39
- if (!cachedClientChunkGroups) throw Error('Internal error');
27
+ let clientChunkGroups: ChunkGroupsT;
40
28
 
41
- return cachedClientChunkGroups;
29
+ if (IS_CLIENT_SIDE) {
30
+ // eslint-disable-next-line global-require
31
+ clientChunkGroups = require('client/getInj').default().CHUNK_GROUPS || {};
42
32
  }
43
33
 
44
34
  const refCounts: { [path: string]: number } = {};
@@ -96,7 +86,7 @@ function getLoadedStyleSheets(): Set<string> {
96
86
  const res = new Set<string>();
97
87
  const { styleSheets } = document;
98
88
  for (let i = 0; i < styleSheets.length; ++i) {
99
- const { href } = styleSheets[i];
89
+ const href = styleSheets[i]?.href;
100
90
  if (href) res.add(href);
101
91
  }
102
92
  return res;
@@ -126,11 +116,13 @@ export function bookStyleSheets(
126
116
  ): Promise<void> {
127
117
  const promises = [];
128
118
  const assets = chunkGroups[chunkName];
119
+ if (!assets) return Promise.resolve();
120
+
129
121
  const loadedSheets = getLoadedStyleSheets();
130
122
 
131
123
  for (let i = 0; i < assets.length; ++i) {
132
124
  const asset = assets[i];
133
- if (asset.endsWith('.css')) {
125
+ if (asset?.endsWith('.css')) {
134
126
  const promise = bookStyleSheet(asset, loadedSheets, refCount);
135
127
  if (promise) promises.push(promise);
136
128
  }
@@ -153,12 +145,19 @@ export function freeStyleSheets(
153
145
  chunkGroups: ChunkGroupsT,
154
146
  ) {
155
147
  const assets = chunkGroups[chunkName];
148
+ if (!assets) return;
149
+
156
150
  for (let i = 0; i < assets.length; ++i) {
157
151
  const asset = assets[i];
158
- if (asset.endsWith('.css')) {
152
+ if (asset?.endsWith('.css')) {
159
153
  const path = `${getPublicPath()}/${asset}`;
160
- if (--refCounts[path] <= 0) {
161
- document.head.querySelector(`link[href="${path}"]`)!.remove();
154
+
155
+ const pathRefCount = refCounts[path];
156
+ if (pathRefCount) {
157
+ if (pathRefCount <= 1) {
158
+ document.head.querySelector(`link[href="${path}"]`)!.remove();
159
+ delete refCounts[path];
160
+ } else refCounts[path] = pathRefCount - 1;
162
161
  }
163
162
  }
164
163
  }
@@ -193,7 +192,7 @@ export default function splitComponent<
193
192
  placeholder?: ReactNode,
194
193
  }) {
195
194
  // On the client side we can check right away if the chunk name is known.
196
- if (IS_CLIENT_SIDE) assertChunkName(chunkName, getClientChunkGroups());
195
+ if (IS_CLIENT_SIDE) assertChunkName(chunkName, clientChunkGroups);
197
196
 
198
197
  // The correct usage of splitComponent() assumes a single call per chunk.
199
198
  if (usedChunkNames.has(chunkName)) {
@@ -208,7 +207,7 @@ export default function splitComponent<
208
207
  // the component (the lazy load function is executed by React one at
209
208
  // the frist mount).
210
209
  if (IS_CLIENT_SIDE) {
211
- await bookStyleSheets(chunkName, getClientChunkGroups(), false);
210
+ await bookStyleSheets(chunkName, clientChunkGroups, false);
212
211
  }
213
212
 
214
213
  const Wrapper = forwardRef((
@@ -226,8 +225,8 @@ export default function splitComponent<
226
225
  // This takes care about stylesheets management every time an instance of
227
226
  // this component is mounted / unmounted.
228
227
  useInsertionEffect(() => {
229
- bookStyleSheets(chunkName, getClientChunkGroups(), true);
230
- return () => freeStyleSheets(chunkName, getClientChunkGroups());
228
+ bookStyleSheets(chunkName, clientChunkGroups, true);
229
+ return () => freeStyleSheets(chunkName, clientChunkGroups);
231
230
  }, []);
232
231
 
233
232
  return (
@@ -251,9 +250,5 @@ export default function splitComponent<
251
250
  </Suspense>
252
251
  );
253
252
 
254
- CodeSplit.propTypes = {
255
- children: PT.node,
256
- } as PT.WeakValidationMap<ComponentPropsT>;
257
-
258
253
  return CodeSplit;
259
254
  }
@@ -1,18 +1,22 @@
1
1
  // TS configuration for configs pre-building from TS sources.
2
2
 
3
3
  {
4
- "extends": "@tsconfig/recommended",
4
+ "extends": "./config/typescript/base.json",
5
5
  "include": [
6
6
  "config-ts-src",
7
7
  ],
8
8
  "compilerOptions": {
9
9
  "declaration": true,
10
- "jsx": "react-jsx",
11
10
  "rootDir": "config-ts-src",
12
11
  "outDir": "config",
13
12
  "paths": {
14
13
  "*": ["./src/shared/*", "./src/*", "./*"]
15
14
  },
16
- "strict": true
15
+
16
+ // TODO: Overriding the base config as configs are compiled into CommonJS
17
+ // modules, and this flag leads to the following error in that case, if set:
18
+ // ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled.
19
+ // Perhaps, there is a better workaround?
20
+ "verbatimModuleSyntax": false
17
21
  }
18
22
  }
package/tsconfig.json CHANGED
@@ -1,13 +1,11 @@
1
1
  // TS config for ESLint, editor plugins, and other tools that look-up and use
2
2
  // the default tsconfig.json file.
3
3
  {
4
- // Note: Full relative paths, as some tools don't support Node module
5
- // resolution mechanics.
6
- "extends": "./node_modules/@tsconfig/recommended/tsconfig.json",
4
+ // Relative path, as some tools relying on this config do not support Node's
5
+ // module resolution mechanics.
6
+ "extends": "./config/typescript/base.json",
7
7
 
8
8
  "compilerOptions": {
9
- "jsx": "react-jsx",
10
-
11
9
  // BEWARE: Different settings are likely to transform dynamic import()
12
10
  // statements in the code, thus breaking Webpack's code splitting.
13
11
  // See: https://davidea.st/articles/webpack-typescript-code-split-wont-work
@@ -18,10 +16,5 @@
18
16
  "*": ["./src/shared/*", "./src/*", "./*"]
19
17
  },
20
18
  "rootDirs": [".", "build/types-scss"],
21
- "strict": true,
22
-
23
- // This ensures TypeScript does not remove unused imports, which may cause
24
- // troubles when we rely on some side-effects from imported modules.
25
- "verbatimModuleSyntax": true,
26
19
  }
27
20
  }
@@ -1,7 +1,7 @@
1
1
  // TS config for ESLint, editor plugins, and other tools that look-up and use
2
2
  // the default tsconfig.json file.
3
3
  {
4
- "extends": "@tsconfig/recommended",
4
+ "extends": "./config/typescript/base.json",
5
5
 
6
6
  // Keep these in case any mocks / tests are declared within "src" code tree.
7
7
  "exclude": [
@@ -16,7 +16,6 @@
16
16
  "compilerOptions": {
17
17
  "declaration": true,
18
18
  "emitDeclarationOnly": true,
19
- "jsx": "react-jsx",
20
19
 
21
20
  // BEWARE: Different settings are likely to transform dynamic import()
22
21
  // statements in the code, thus breaking Webpack's code splitting.
@@ -42,10 +41,5 @@
42
41
  "utils/*": ["./src/shared/utils/*"],
43
42
  },
44
43
  "rootDirs": [".", "build/types-scss"],
45
- "strict": true,
46
-
47
- // This ensures TypeScript does not remove unused imports, which may cause
48
- // troubles when we rely on some side-effects from imported modules.
49
- "verbatimModuleSyntax": true,
50
44
  },
51
45
  }
@@ -0,0 +1,6 @@
1
+ {
2
+ "testFileMatch": [
3
+ "__tests__/ts/**/*.ts",
4
+ "__tests__/ts/**/*.tsx"
5
+ ]
6
+ }