@shuvi/router-react 1.0.59 → 1.0.60
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/esm/Link.d.ts +11 -23
- package/esm/Link.js +28 -1
- package/lib/Link.d.ts +11 -23
- package/lib/Link.js +28 -1
- package/package.json +4 -4
package/esm/Link.d.ts
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { State, PathRecord } from '@shuvi/router';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* <Link
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* search: "?sort=name",
|
|
16
|
-
* hash: "#the-hash",
|
|
17
|
-
* }}>About</Link>
|
|
18
|
-
* // props target '_self' | '_blank', default is '_self'
|
|
19
|
-
* <Link to="/about" target="_self">About</Link>
|
|
20
|
-
* // overrides default redirect mode by `replace`
|
|
21
|
-
* <Link to="/about" replace>About</Link>
|
|
22
|
-
* // if `onClick` function, run it first
|
|
23
|
-
* <Link to="/about" onClick={fn}>About</Link>
|
|
24
|
-
* // other props will be delivered to `<a>`
|
|
25
|
-
* <Link to="/about" a='a' b='b'>About</Link> => <{...rest} a>
|
|
26
|
-
* ```
|
|
4
|
+
* @NOTE Improve Page Stability by Handling Fatal Crashes 致命錯誤降級處理
|
|
5
|
+
*
|
|
6
|
+
* Development Mode:
|
|
7
|
+
* On fatal errors, immediately show the "Internal Application Error" page.
|
|
8
|
+
*
|
|
9
|
+
* Production Mode: Downgrade fatal error
|
|
10
|
+
* 1. console.error without causing an immediate page crash.
|
|
11
|
+
* 2. Only after user clicks <Link>, page re-render
|
|
12
|
+
* and display the "Internal Application Error" page.
|
|
13
|
+
*
|
|
14
|
+
* @issue https://github.com/shuvijs/shuvi/pull/596
|
|
27
15
|
*/
|
|
28
16
|
export declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
29
17
|
export interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
|
package/esm/Link.js
CHANGED
|
@@ -43,7 +43,7 @@ function isModifiedEvent(event) {
|
|
|
43
43
|
* <Link to="/about" a='a' b='b'>About</Link> => <{...rest} a>
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
|
-
|
|
46
|
+
const BaseLink = React.forwardRef(function BaseLinkWithRef(_a, ref) {
|
|
47
47
|
var { onClick, replace: replaceProp = false, state, target, to } = _a, rest = __rest(_a, ["onClick", "replace", "state", "target", "to"]);
|
|
48
48
|
let href = useHref(to);
|
|
49
49
|
let navigate = useNavigate();
|
|
@@ -69,6 +69,33 @@ export const Link = React.forwardRef(function LinkWithRef(_a, ref) {
|
|
|
69
69
|
// @ts-ignore
|
|
70
70
|
React.createElement("a", Object.assign({}, rest, { href: href, onClick: handleClick, ref: ref, target: target })));
|
|
71
71
|
});
|
|
72
|
+
/**
|
|
73
|
+
* @NOTE Improve Page Stability by Handling Fatal Crashes 致命錯誤降級處理
|
|
74
|
+
*
|
|
75
|
+
* Development Mode:
|
|
76
|
+
* On fatal errors, immediately show the "Internal Application Error" page.
|
|
77
|
+
*
|
|
78
|
+
* Production Mode: Downgrade fatal error
|
|
79
|
+
* 1. console.error without causing an immediate page crash.
|
|
80
|
+
* 2. Only after user clicks <Link>, page re-render
|
|
81
|
+
* and display the "Internal Application Error" page.
|
|
82
|
+
*
|
|
83
|
+
* @issue https://github.com/shuvijs/shuvi/pull/596
|
|
84
|
+
*/
|
|
85
|
+
export const Link = React.forwardRef(function LinkWithRef(props, ref) {
|
|
86
|
+
const invalidPropTo = typeof props.to === 'undefined';
|
|
87
|
+
if (invalidPropTo) {
|
|
88
|
+
console.error(`The prop 'to' is required in '<Link>', but its value is 'undefined'`, JSON.stringify({ props }));
|
|
89
|
+
}
|
|
90
|
+
const [downgradeError, setDowngradeError] = React.useState(process.env.NODE_ENV === 'production');
|
|
91
|
+
if (downgradeError && invalidPropTo) {
|
|
92
|
+
return (React.createElement("a", Object.assign({}, props, { onClick: e => {
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
setDowngradeError(false);
|
|
95
|
+
}, ref: ref })));
|
|
96
|
+
}
|
|
97
|
+
return React.createElement(BaseLink, Object.assign({}, props, { ref: ref }));
|
|
98
|
+
});
|
|
72
99
|
if (__DEV__) {
|
|
73
100
|
Link.displayName = 'Link';
|
|
74
101
|
Link.propTypes = {
|
package/lib/Link.d.ts
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { State, PathRecord } from '@shuvi/router';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* <Link
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* search: "?sort=name",
|
|
16
|
-
* hash: "#the-hash",
|
|
17
|
-
* }}>About</Link>
|
|
18
|
-
* // props target '_self' | '_blank', default is '_self'
|
|
19
|
-
* <Link to="/about" target="_self">About</Link>
|
|
20
|
-
* // overrides default redirect mode by `replace`
|
|
21
|
-
* <Link to="/about" replace>About</Link>
|
|
22
|
-
* // if `onClick` function, run it first
|
|
23
|
-
* <Link to="/about" onClick={fn}>About</Link>
|
|
24
|
-
* // other props will be delivered to `<a>`
|
|
25
|
-
* <Link to="/about" a='a' b='b'>About</Link> => <{...rest} a>
|
|
26
|
-
* ```
|
|
4
|
+
* @NOTE Improve Page Stability by Handling Fatal Crashes 致命錯誤降級處理
|
|
5
|
+
*
|
|
6
|
+
* Development Mode:
|
|
7
|
+
* On fatal errors, immediately show the "Internal Application Error" page.
|
|
8
|
+
*
|
|
9
|
+
* Production Mode: Downgrade fatal error
|
|
10
|
+
* 1. console.error without causing an immediate page crash.
|
|
11
|
+
* 2. Only after user clicks <Link>, page re-render
|
|
12
|
+
* and display the "Internal Application Error" page.
|
|
13
|
+
*
|
|
14
|
+
* @issue https://github.com/shuvijs/shuvi/pull/596
|
|
27
15
|
*/
|
|
28
16
|
export declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
29
17
|
export interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
|
package/lib/Link.js
CHANGED
|
@@ -69,7 +69,7 @@ function isModifiedEvent(event) {
|
|
|
69
69
|
* <Link to="/about" a='a' b='b'>About</Link> => <{...rest} a>
|
|
70
70
|
* ```
|
|
71
71
|
*/
|
|
72
|
-
|
|
72
|
+
const BaseLink = React.forwardRef(function BaseLinkWithRef(_a, ref) {
|
|
73
73
|
var { onClick, replace: replaceProp = false, state, target, to } = _a, rest = __rest(_a, ["onClick", "replace", "state", "target", "to"]);
|
|
74
74
|
let href = (0, _1.useHref)(to);
|
|
75
75
|
let navigate = (0, _1.useNavigate)();
|
|
@@ -95,6 +95,33 @@ exports.Link = React.forwardRef(function LinkWithRef(_a, ref) {
|
|
|
95
95
|
// @ts-ignore
|
|
96
96
|
React.createElement("a", Object.assign({}, rest, { href: href, onClick: handleClick, ref: ref, target: target })));
|
|
97
97
|
});
|
|
98
|
+
/**
|
|
99
|
+
* @NOTE Improve Page Stability by Handling Fatal Crashes 致命錯誤降級處理
|
|
100
|
+
*
|
|
101
|
+
* Development Mode:
|
|
102
|
+
* On fatal errors, immediately show the "Internal Application Error" page.
|
|
103
|
+
*
|
|
104
|
+
* Production Mode: Downgrade fatal error
|
|
105
|
+
* 1. console.error without causing an immediate page crash.
|
|
106
|
+
* 2. Only after user clicks <Link>, page re-render
|
|
107
|
+
* and display the "Internal Application Error" page.
|
|
108
|
+
*
|
|
109
|
+
* @issue https://github.com/shuvijs/shuvi/pull/596
|
|
110
|
+
*/
|
|
111
|
+
exports.Link = React.forwardRef(function LinkWithRef(props, ref) {
|
|
112
|
+
const invalidPropTo = typeof props.to === 'undefined';
|
|
113
|
+
if (invalidPropTo) {
|
|
114
|
+
console.error(`The prop 'to' is required in '<Link>', but its value is 'undefined'`, JSON.stringify({ props }));
|
|
115
|
+
}
|
|
116
|
+
const [downgradeError, setDowngradeError] = React.useState(process.env.NODE_ENV === 'production');
|
|
117
|
+
if (downgradeError && invalidPropTo) {
|
|
118
|
+
return (React.createElement("a", Object.assign({}, props, { onClick: e => {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
setDowngradeError(false);
|
|
121
|
+
}, ref: ref })));
|
|
122
|
+
}
|
|
123
|
+
return React.createElement(BaseLink, Object.assign({}, props, { ref: ref }));
|
|
124
|
+
});
|
|
98
125
|
if (constants_1.__DEV__) {
|
|
99
126
|
exports.Link.displayName = 'Link';
|
|
100
127
|
exports.Link.propTypes = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/router-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.60",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"node": ">= 16.0.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@shuvi/router": "1.0.
|
|
32
|
-
"@shuvi/platform-shared": "1.0.
|
|
33
|
-
"@shuvi/utils": "1.0.
|
|
31
|
+
"@shuvi/router": "1.0.60",
|
|
32
|
+
"@shuvi/platform-shared": "1.0.60",
|
|
33
|
+
"@shuvi/utils": "1.0.60",
|
|
34
34
|
"prop-types": "^15.8.1",
|
|
35
35
|
"use-sync-external-store": "1.2.0"
|
|
36
36
|
},
|