@tramvai/react 1.99.1 → 1.101.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/lib/lazy/lazy.d.ts +5 -0
- package/lib/react.d.ts +1 -1
- package/lib/react.es.js +27 -1
- package/lib/react.js +27 -0
- package/package.json +2 -2
package/lib/lazy/lazy.d.ts
CHANGED
|
@@ -2,5 +2,10 @@ import type { LoadableComponent, DefaultComponent } from '@loadable/component';
|
|
|
2
2
|
interface Options {
|
|
3
3
|
loading?: JSX.Element;
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* @private Only for internal usage!
|
|
7
|
+
* The method is intended to make it possible to wait for retries to synchronously load unsuccessful CSS assets
|
|
8
|
+
*/
|
|
9
|
+
export declare const __lazyErrorHandler: (error: any, load: () => Promise<any>) => Promise<any>;
|
|
5
10
|
export declare const lazy: <Props, Component>(load: (props?: Props | undefined) => Promise<DefaultComponent<Props>>, options?: Options) => LoadableComponent<Props>;
|
|
6
11
|
export {};
|
package/lib/react.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export { ErrorBoundary } from './error/component';
|
|
|
6
6
|
export { FallbackError } from './error/fallback';
|
|
7
7
|
export { withError } from './error/hoc';
|
|
8
8
|
export * from './error/tokens';
|
|
9
|
-
export { lazy } from './lazy/lazy';
|
|
9
|
+
export { lazy, __lazyErrorHandler } from './lazy/lazy';
|
package/lib/react.es.js
CHANGED
|
@@ -164,6 +164,27 @@ const withError = ({ fallbackComponent, } = {}) => (WrappedComponent) => {
|
|
|
164
164
|
return hoistStatics(WrapperWithError, WrappedComponent);
|
|
165
165
|
};
|
|
166
166
|
|
|
167
|
+
/**
|
|
168
|
+
* @private Only for internal usage!
|
|
169
|
+
* The method is intended to make it possible to wait for retries to synchronously load unsuccessful CSS assets
|
|
170
|
+
*/
|
|
171
|
+
const __lazyErrorHandler = (error, load) => {
|
|
172
|
+
// This error from `mini-css-extract-plugin` fired, when a file loading initiated by this plugin failed.
|
|
173
|
+
// By default, this error will cancel the loading of the component via `loadable`.
|
|
174
|
+
// Now, we can add `__lazyErrorHandler` to catch block of any dynamic import,
|
|
175
|
+
// and if failed assets was loaded again, `loadable` will not fail
|
|
176
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === 'CSS_CHUNK_LOAD_FAILED') {
|
|
177
|
+
const failedLinkUrl = error.request;
|
|
178
|
+
// `mini-css-extract-plugin` instantly removes failed link tags,
|
|
179
|
+
// so we can expect only link tag from our recovery mechanism
|
|
180
|
+
const fallbackLinkTag = document.querySelector(`link[href="${failedLinkUrl}"]`) ||
|
|
181
|
+
document.querySelector(`link[data-href="${failedLinkUrl}"]`);
|
|
182
|
+
if (fallbackLinkTag) {
|
|
183
|
+
return load();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
throw error;
|
|
187
|
+
};
|
|
167
188
|
const lazy = (load, options = {}) => {
|
|
168
189
|
if (process.env.NODE_ENV === 'development') {
|
|
169
190
|
if (!('requireAsync' in load)) {
|
|
@@ -173,9 +194,14 @@ the first argument should be transformed into a special object, but the current
|
|
|
173
194
|
"${load.toString()}"`);
|
|
174
195
|
}
|
|
175
196
|
}
|
|
197
|
+
// @ts-expect-error
|
|
198
|
+
const originalImportAsync = load.importAsync;
|
|
199
|
+
// @ts-expect-error
|
|
200
|
+
// eslint-disable-next-line no-param-reassign
|
|
201
|
+
load.importAsync = () => originalImportAsync().catch((e) => __lazyErrorHandler(e, originalImportAsync));
|
|
176
202
|
return loadable(load, {
|
|
177
203
|
fallback: options.loading,
|
|
178
204
|
});
|
|
179
205
|
};
|
|
180
206
|
|
|
181
|
-
export { DIContext, ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN, ERROR_BOUNDARY_TOKEN, ErrorBoundary, FallbackError, ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN, UniversalErrorBoundary, lazy, useDi, useDiContainer, withDi, withError };
|
|
207
|
+
export { DIContext, ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN, ERROR_BOUNDARY_TOKEN, ErrorBoundary, FallbackError, ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN, UniversalErrorBoundary, __lazyErrorHandler, lazy, useDi, useDiContainer, withDi, withError };
|
package/lib/react.js
CHANGED
|
@@ -174,6 +174,27 @@ const withError = ({ fallbackComponent, } = {}) => (WrappedComponent) => {
|
|
|
174
174
|
return hoistStatics__default["default"](WrapperWithError, WrappedComponent);
|
|
175
175
|
};
|
|
176
176
|
|
|
177
|
+
/**
|
|
178
|
+
* @private Only for internal usage!
|
|
179
|
+
* The method is intended to make it possible to wait for retries to synchronously load unsuccessful CSS assets
|
|
180
|
+
*/
|
|
181
|
+
const __lazyErrorHandler = (error, load) => {
|
|
182
|
+
// This error from `mini-css-extract-plugin` fired, when a file loading initiated by this plugin failed.
|
|
183
|
+
// By default, this error will cancel the loading of the component via `loadable`.
|
|
184
|
+
// Now, we can add `__lazyErrorHandler` to catch block of any dynamic import,
|
|
185
|
+
// and if failed assets was loaded again, `loadable` will not fail
|
|
186
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === 'CSS_CHUNK_LOAD_FAILED') {
|
|
187
|
+
const failedLinkUrl = error.request;
|
|
188
|
+
// `mini-css-extract-plugin` instantly removes failed link tags,
|
|
189
|
+
// so we can expect only link tag from our recovery mechanism
|
|
190
|
+
const fallbackLinkTag = document.querySelector(`link[href="${failedLinkUrl}"]`) ||
|
|
191
|
+
document.querySelector(`link[data-href="${failedLinkUrl}"]`);
|
|
192
|
+
if (fallbackLinkTag) {
|
|
193
|
+
return load();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
throw error;
|
|
197
|
+
};
|
|
177
198
|
const lazy = (load, options = {}) => {
|
|
178
199
|
if (process.env.NODE_ENV === 'development') {
|
|
179
200
|
if (!('requireAsync' in load)) {
|
|
@@ -183,6 +204,11 @@ the first argument should be transformed into a special object, but the current
|
|
|
183
204
|
"${load.toString()}"`);
|
|
184
205
|
}
|
|
185
206
|
}
|
|
207
|
+
// @ts-expect-error
|
|
208
|
+
const originalImportAsync = load.importAsync;
|
|
209
|
+
// @ts-expect-error
|
|
210
|
+
// eslint-disable-next-line no-param-reassign
|
|
211
|
+
load.importAsync = () => originalImportAsync().catch((e) => __lazyErrorHandler(e, originalImportAsync));
|
|
186
212
|
return loadable__default["default"](load, {
|
|
187
213
|
fallback: options.loading,
|
|
188
214
|
});
|
|
@@ -194,6 +220,7 @@ exports.ERROR_BOUNDARY_TOKEN = ERROR_BOUNDARY_TOKEN;
|
|
|
194
220
|
exports.FallbackError = FallbackError;
|
|
195
221
|
exports.ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN = ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN;
|
|
196
222
|
exports.UniversalErrorBoundary = UniversalErrorBoundary;
|
|
223
|
+
exports.__lazyErrorHandler = __lazyErrorHandler;
|
|
197
224
|
exports.lazy = lazy;
|
|
198
225
|
exports.useDi = useDi;
|
|
199
226
|
exports.useDiContainer = useDiContainer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.101.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/react.js",
|
|
6
6
|
"typings": "lib/react.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@tinkoff/dippy": "0.7.39",
|
|
27
27
|
"@tinkoff/utils": "^2.1.2",
|
|
28
28
|
"@tinkoff/url": "0.7.37",
|
|
29
|
-
"@tramvai/core": "1.
|
|
29
|
+
"@tramvai/core": "1.101.2",
|
|
30
30
|
"react": ">=16.8.0",
|
|
31
31
|
"react-dom": ">=16.8.0",
|
|
32
32
|
"tslib": "^2.0.3"
|