@tramvai/react 1.55.2 → 1.56.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.
- package/lib/error/UniversalErrorBoundary.d.ts +39 -0
- package/lib/error/component.d.ts +3 -0
- package/lib/error/hoc.d.ts +3 -0
- package/lib/error/tokens.d.ts +5 -0
- package/lib/react.d.ts +1 -0
- package/lib/react.es.js +54 -1
- package/lib/react.js +55 -0
- package/package.json +3 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import type { Url } from '@tinkoff/url';
|
|
3
|
+
import type { ERROR_BOUNDARY_TOKEN } from './tokens';
|
|
4
|
+
declare type AnyError = Error & {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
export interface UniversalErrorBoundaryFallbackProps {
|
|
8
|
+
url: Url;
|
|
9
|
+
error: AnyError;
|
|
10
|
+
}
|
|
11
|
+
export interface UniversalErrorBoundaryProps {
|
|
12
|
+
url: Url;
|
|
13
|
+
error?: AnyError | null;
|
|
14
|
+
fallback?: React.ComponentType<UniversalErrorBoundaryFallbackProps>;
|
|
15
|
+
errorHandlers?: typeof ERROR_BOUNDARY_TOKEN | null;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated
|
|
18
|
+
*/
|
|
19
|
+
fallbackFromDi?: React.ReactElement | null;
|
|
20
|
+
}
|
|
21
|
+
interface State {
|
|
22
|
+
error: AnyError | null;
|
|
23
|
+
url: Url;
|
|
24
|
+
}
|
|
25
|
+
declare type Props = UniversalErrorBoundaryProps;
|
|
26
|
+
export declare class UniversalErrorBoundary extends Component<Props, State> {
|
|
27
|
+
constructor(props: Props);
|
|
28
|
+
static displayName: string;
|
|
29
|
+
static getDerivedStateFromProps(props: Props, state: State): {
|
|
30
|
+
error: AnyError | null;
|
|
31
|
+
url: Url;
|
|
32
|
+
};
|
|
33
|
+
static getDerivedStateFromError(error: AnyError): {
|
|
34
|
+
error: AnyError;
|
|
35
|
+
};
|
|
36
|
+
componentDidCatch(error: AnyError, errorInfo: React.ErrorInfo): void;
|
|
37
|
+
render(): React.ReactNode;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
package/lib/error/component.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ interface Props {
|
|
|
8
8
|
interface State {
|
|
9
9
|
hasError: boolean;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use UniversalErrorBoundary component
|
|
13
|
+
*/
|
|
11
14
|
export declare class ErrorBoundary extends Component<Props, State> {
|
|
12
15
|
constructor(props: Props);
|
|
13
16
|
static displayName: string;
|
package/lib/error/hoc.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use UniversalErrorBoundary component
|
|
4
|
+
*/
|
|
2
5
|
export declare const withError: ({ fallbackComponent, }?: {
|
|
3
6
|
fallbackComponent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined;
|
|
4
7
|
}) => <T extends React.ComponentType<any>>(WrappedComponent: T) => T;
|
package/lib/error/tokens.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
+
import type { UniversalErrorBoundaryFallbackProps } from './UniversalErrorBoundary';
|
|
2
3
|
declare type ErrorBoundaryHandler = (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
3
4
|
export declare const ERROR_BOUNDARY_TOKEN: ErrorBoundaryHandler[];
|
|
5
|
+
export declare const ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN: React.ComponentType<UniversalErrorBoundaryFallbackProps>;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated
|
|
8
|
+
*/
|
|
4
9
|
export declare const ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN: React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
5
10
|
export {};
|
package/lib/react.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { DIContext } from './di/context';
|
|
2
2
|
export { withDi } from './di/hoc';
|
|
3
3
|
export { useDi, useDiContainer } from './di/hooks';
|
|
4
|
+
export { UniversalErrorBoundary, UniversalErrorBoundaryProps, UniversalErrorBoundaryFallbackProps, } from './error/UniversalErrorBoundary';
|
|
4
5
|
export { ErrorBoundary } from './error/component';
|
|
5
6
|
export { FallbackError } from './error/fallback';
|
|
6
7
|
export { withError } from './error/hoc';
|
package/lib/react.es.js
CHANGED
|
@@ -69,11 +69,61 @@ const FallbackError = () => {
|
|
|
69
69
|
FallbackError.displayName = 'FallbackError';
|
|
70
70
|
/* eslint-enable jsx-a11y/anchor-is-valid */
|
|
71
71
|
|
|
72
|
+
class UniversalErrorBoundary extends Component {
|
|
73
|
+
constructor(props) {
|
|
74
|
+
super(props);
|
|
75
|
+
this.state = {
|
|
76
|
+
error: props.error || null,
|
|
77
|
+
url: props.url,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// Reference and explanation here - https://github.com/remix-run/remix/blob/main/packages/remix-react/errorBoundaries.tsx#L35
|
|
81
|
+
static getDerivedStateFromProps(props, state) {
|
|
82
|
+
if (props.url !== state.url) {
|
|
83
|
+
return { error: props.error || null, url: props.url };
|
|
84
|
+
}
|
|
85
|
+
return { error: props.error || state.error, url: state.url };
|
|
86
|
+
}
|
|
87
|
+
static getDerivedStateFromError(error) {
|
|
88
|
+
return { error };
|
|
89
|
+
}
|
|
90
|
+
componentDidCatch(error, errorInfo) {
|
|
91
|
+
const { errorHandlers } = this.props;
|
|
92
|
+
if (errorHandlers) {
|
|
93
|
+
errorHandlers.forEach((handler) => {
|
|
94
|
+
handler(error, errorInfo);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
render() {
|
|
99
|
+
const { children, fallback: Fallback, fallbackFromDi } = this.props;
|
|
100
|
+
const { url, error } = this.state;
|
|
101
|
+
if (!error) {
|
|
102
|
+
return children;
|
|
103
|
+
}
|
|
104
|
+
if (Fallback) {
|
|
105
|
+
return React.createElement(Fallback, { url: url, error: error });
|
|
106
|
+
}
|
|
107
|
+
if (fallbackFromDi) {
|
|
108
|
+
return fallbackFromDi;
|
|
109
|
+
}
|
|
110
|
+
return React.createElement(FallbackError, null);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
UniversalErrorBoundary.displayName = 'UniversalErrorBoundary';
|
|
114
|
+
|
|
72
115
|
const ERROR_BOUNDARY_TOKEN = createToken('reactErrorBoundaryHandlers', {
|
|
73
116
|
multi: true,
|
|
74
117
|
});
|
|
118
|
+
const ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN = createToken('rootErrorBoundaryComponent');
|
|
119
|
+
/**
|
|
120
|
+
* @deprecated
|
|
121
|
+
*/
|
|
75
122
|
const ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN = createToken('errorBoundaryFallbackComponent');
|
|
76
123
|
|
|
124
|
+
/**
|
|
125
|
+
* @deprecated Use UniversalErrorBoundary component
|
|
126
|
+
*/
|
|
77
127
|
let ErrorBoundary = class ErrorBoundary extends Component {
|
|
78
128
|
constructor(props) {
|
|
79
129
|
super(props);
|
|
@@ -109,6 +159,9 @@ ErrorBoundary = __decorate([
|
|
|
109
159
|
})
|
|
110
160
|
], ErrorBoundary);
|
|
111
161
|
|
|
162
|
+
/**
|
|
163
|
+
* @deprecated Use UniversalErrorBoundary component
|
|
164
|
+
*/
|
|
112
165
|
const withError = ({ fallbackComponent, } = {}) => (WrappedComponent) => {
|
|
113
166
|
function WrapperWithError(props) {
|
|
114
167
|
return (React.createElement(ErrorBoundary, { fallbackComponent: fallbackComponent },
|
|
@@ -131,4 +184,4 @@ the first argument should be transformed into a special object, but the current
|
|
|
131
184
|
});
|
|
132
185
|
};
|
|
133
186
|
|
|
134
|
-
export { DIContext, ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN, ERROR_BOUNDARY_TOKEN, ErrorBoundary, FallbackError, lazy, useDi, useDiContainer, withDi, withError };
|
|
187
|
+
export { DIContext, ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN, ERROR_BOUNDARY_TOKEN, ErrorBoundary, FallbackError, ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN, UniversalErrorBoundary, lazy, useDi, useDiContainer, withDi, withError };
|
package/lib/react.js
CHANGED
|
@@ -80,11 +80,61 @@ const FallbackError = () => {
|
|
|
80
80
|
FallbackError.displayName = 'FallbackError';
|
|
81
81
|
/* eslint-enable jsx-a11y/anchor-is-valid */
|
|
82
82
|
|
|
83
|
+
class UniversalErrorBoundary extends React.Component {
|
|
84
|
+
constructor(props) {
|
|
85
|
+
super(props);
|
|
86
|
+
this.state = {
|
|
87
|
+
error: props.error || null,
|
|
88
|
+
url: props.url,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Reference and explanation here - https://github.com/remix-run/remix/blob/main/packages/remix-react/errorBoundaries.tsx#L35
|
|
92
|
+
static getDerivedStateFromProps(props, state) {
|
|
93
|
+
if (props.url !== state.url) {
|
|
94
|
+
return { error: props.error || null, url: props.url };
|
|
95
|
+
}
|
|
96
|
+
return { error: props.error || state.error, url: state.url };
|
|
97
|
+
}
|
|
98
|
+
static getDerivedStateFromError(error) {
|
|
99
|
+
return { error };
|
|
100
|
+
}
|
|
101
|
+
componentDidCatch(error, errorInfo) {
|
|
102
|
+
const { errorHandlers } = this.props;
|
|
103
|
+
if (errorHandlers) {
|
|
104
|
+
errorHandlers.forEach((handler) => {
|
|
105
|
+
handler(error, errorInfo);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
render() {
|
|
110
|
+
const { children, fallback: Fallback, fallbackFromDi } = this.props;
|
|
111
|
+
const { url, error } = this.state;
|
|
112
|
+
if (!error) {
|
|
113
|
+
return children;
|
|
114
|
+
}
|
|
115
|
+
if (Fallback) {
|
|
116
|
+
return React__default["default"].createElement(Fallback, { url: url, error: error });
|
|
117
|
+
}
|
|
118
|
+
if (fallbackFromDi) {
|
|
119
|
+
return fallbackFromDi;
|
|
120
|
+
}
|
|
121
|
+
return React__default["default"].createElement(FallbackError, null);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
UniversalErrorBoundary.displayName = 'UniversalErrorBoundary';
|
|
125
|
+
|
|
83
126
|
const ERROR_BOUNDARY_TOKEN = dippy.createToken('reactErrorBoundaryHandlers', {
|
|
84
127
|
multi: true,
|
|
85
128
|
});
|
|
129
|
+
const ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN = dippy.createToken('rootErrorBoundaryComponent');
|
|
130
|
+
/**
|
|
131
|
+
* @deprecated
|
|
132
|
+
*/
|
|
86
133
|
const ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN = dippy.createToken('errorBoundaryFallbackComponent');
|
|
87
134
|
|
|
135
|
+
/**
|
|
136
|
+
* @deprecated Use UniversalErrorBoundary component
|
|
137
|
+
*/
|
|
88
138
|
exports.ErrorBoundary = class ErrorBoundary extends React.Component {
|
|
89
139
|
constructor(props) {
|
|
90
140
|
super(props);
|
|
@@ -120,6 +170,9 @@ exports.ErrorBoundary = tslib.__decorate([
|
|
|
120
170
|
})
|
|
121
171
|
], exports.ErrorBoundary);
|
|
122
172
|
|
|
173
|
+
/**
|
|
174
|
+
* @deprecated Use UniversalErrorBoundary component
|
|
175
|
+
*/
|
|
123
176
|
const withError = ({ fallbackComponent, } = {}) => (WrappedComponent) => {
|
|
124
177
|
function WrapperWithError(props) {
|
|
125
178
|
return (React__default["default"].createElement(exports.ErrorBoundary, { fallbackComponent: fallbackComponent },
|
|
@@ -146,6 +199,8 @@ exports.DIContext = DIContext;
|
|
|
146
199
|
exports.ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN = ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN;
|
|
147
200
|
exports.ERROR_BOUNDARY_TOKEN = ERROR_BOUNDARY_TOKEN;
|
|
148
201
|
exports.FallbackError = FallbackError;
|
|
202
|
+
exports.ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN = ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN;
|
|
203
|
+
exports.UniversalErrorBoundary = UniversalErrorBoundary;
|
|
149
204
|
exports.lazy = lazy;
|
|
150
205
|
exports.useDi = useDi;
|
|
151
206
|
exports.useDiContainer = useDiContainer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.56.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/react.js",
|
|
6
6
|
"typings": "lib/react.d.ts",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@tinkoff/dippy": "0.7.38",
|
|
27
27
|
"@tinkoff/utils": "^2.1.2",
|
|
28
|
-
"@
|
|
28
|
+
"@tinkoff/url": "0.7.37",
|
|
29
|
+
"@tramvai/core": "1.56.0",
|
|
29
30
|
"react": ">=16.8.0",
|
|
30
31
|
"react-dom": ">=16.8.0",
|
|
31
32
|
"tslib": "^2.0.3"
|