@tramvai/react 2.141.2 → 2.142.1
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 +22 -1
- package/lib/lazy/lazy.d.ts +1 -0
- package/lib/lazy/lazy.es.js +7 -1
- package/lib/lazy/lazy.js +6 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -126,8 +126,29 @@ const ComponentWrapper = () => {
|
|
|
126
126
|
return (
|
|
127
127
|
// feel free to use your own implementation
|
|
128
128
|
<UniversalErrorBoundary error={null} fallback={() => null}>
|
|
129
|
-
<
|
|
129
|
+
<Component />
|
|
130
130
|
</UniversalErrorBoundary>
|
|
131
131
|
);
|
|
132
132
|
};
|
|
133
133
|
```
|
|
134
|
+
|
|
135
|
+
### Using Suspense with lazy components
|
|
136
|
+
|
|
137
|
+
If you are using React 18, you can display fallback UI for lazy component while it is loading. To do so, you need to pass `suspense: true` to lazy method options:
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
import { Suspense } from 'react';
|
|
141
|
+
import { lazy } from '@tramvai/react';
|
|
142
|
+
|
|
143
|
+
const Component = lazy(() => import('./Component'), { suspense: true });
|
|
144
|
+
|
|
145
|
+
const ComponentWrapper = () => {
|
|
146
|
+
return (
|
|
147
|
+
<Suspense fallback={<h4>Loading...</h4>}>
|
|
148
|
+
<Component />
|
|
149
|
+
</Suspense>
|
|
150
|
+
);
|
|
151
|
+
};
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
See more in our [React 18 guide](https://tramvai.dev/docs/guides/react-18#error-handling)!
|
package/lib/lazy/lazy.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { TramvaiComponent, TramvaiComponentDecl } from '../typings/componen
|
|
|
3
3
|
export declare const resolveLazyComponent: (componentOrLoader?: TramvaiComponentDecl) => Promise<TramvaiComponent | undefined>;
|
|
4
4
|
interface Options {
|
|
5
5
|
loading?: JSX.Element;
|
|
6
|
+
suspense?: boolean;
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
9
|
* @private Only for internal usage!
|
package/lib/lazy/lazy.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import hoistStatics from 'hoist-non-react-statics';
|
|
2
|
-
import loadable from '@loadable/component';
|
|
2
|
+
import loadable, { lazy as lazy$1 } from '@loadable/component';
|
|
3
3
|
|
|
4
4
|
const resolveLazyComponent = async (componentOrLoader) => {
|
|
5
5
|
if (!componentOrLoader) {
|
|
@@ -56,6 +56,12 @@ the first argument should be transformed into a special object, but the current
|
|
|
56
56
|
// @ts-expect-error
|
|
57
57
|
// eslint-disable-next-line no-param-reassign
|
|
58
58
|
load.importAsync = () => originalImportAsync().catch((e) => __lazyErrorHandler(e, originalImportAsync));
|
|
59
|
+
// There is no typings for `suspense` param in the original `load`
|
|
60
|
+
// function signature, but it is using internally.
|
|
61
|
+
// https://github.com/gregberge/loadable-components/blob/09af82568fc6c0aa1c58501d1e6707561186b09b/packages/component/src/createLoadable.js#L361
|
|
62
|
+
if (options.suspense && process.env.__TRAMVAI_CONCURRENT_FEATURES) {
|
|
63
|
+
return lazy$1(load);
|
|
64
|
+
}
|
|
59
65
|
return loadable(load, {
|
|
60
66
|
fallback: options.loading,
|
|
61
67
|
});
|
package/lib/lazy/lazy.js
CHANGED
|
@@ -65,6 +65,12 @@ the first argument should be transformed into a special object, but the current
|
|
|
65
65
|
// @ts-expect-error
|
|
66
66
|
// eslint-disable-next-line no-param-reassign
|
|
67
67
|
load.importAsync = () => originalImportAsync().catch((e) => __lazyErrorHandler(e, originalImportAsync));
|
|
68
|
+
// There is no typings for `suspense` param in the original `load`
|
|
69
|
+
// function signature, but it is using internally.
|
|
70
|
+
// https://github.com/gregberge/loadable-components/blob/09af82568fc6c0aa1c58501d1e6707561186b09b/packages/component/src/createLoadable.js#L361
|
|
71
|
+
if (options.suspense && process.env.__TRAMVAI_CONCURRENT_FEATURES) {
|
|
72
|
+
return loadable.lazy(load);
|
|
73
|
+
}
|
|
68
74
|
return loadable__default["default"](load, {
|
|
69
75
|
fallback: options.loading,
|
|
70
76
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.142.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/react.js",
|
|
6
6
|
"typings": "lib/react.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@loadable/component": "^5.15.2",
|
|
21
21
|
"@types/loadable__component": "^5.13.4",
|
|
22
|
-
"@tramvai/types-actions-state-context": "2.
|
|
22
|
+
"@tramvai/types-actions-state-context": "2.142.1",
|
|
23
23
|
"hoist-non-react-statics": "^3.3.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|