@shuvi/router-react 1.0.0-rc.1 → 1.0.0-rc.12
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/Router.js +7 -14
- package/esm/contexts.d.ts +0 -3
- package/esm/hooks.d.ts +0 -3
- package/lib/Router.js +7 -14
- package/lib/contexts.d.ts +0 -3
- package/lib/hooks.d.ts +0 -3
- package/package.json +19 -17
package/esm/Router.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useRef, useReducer } from 'react';
|
|
3
2
|
import * as PropTypes from 'prop-types';
|
|
4
3
|
import invariant from '@shuvi/utils/lib/invariant';
|
|
4
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
5
5
|
import { RouterContext, RouteContext } from './contexts';
|
|
6
6
|
import { useInRouterContext } from './hooks';
|
|
7
7
|
import { __DEV__ } from './constants';
|
|
8
|
-
import { useIsomorphicEffect } from './utils';
|
|
9
8
|
/**
|
|
10
9
|
* Provides location context for the rest of the app.
|
|
11
10
|
*
|
|
@@ -22,19 +21,13 @@ export function Router({ children = null, static: staticProp = false, router })
|
|
|
22
21
|
router: router
|
|
23
22
|
};
|
|
24
23
|
}, [staticProp, router]);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (unmount.current) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
forceupdate();
|
|
34
|
-
});
|
|
35
|
-
}, [router]);
|
|
24
|
+
const { subscribe, getSnapshot } = React.useMemo(() => ({
|
|
25
|
+
subscribe: (fn) => router.listen(fn),
|
|
26
|
+
getSnapshot: () => router.current
|
|
27
|
+
}), [router]);
|
|
28
|
+
const current = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
36
29
|
return (React.createElement(RouterContext.Provider, { value: contextVal },
|
|
37
|
-
React.createElement(RouteContext.Provider, { children: children, value:
|
|
30
|
+
React.createElement(RouteContext.Provider, { children: children, value: current })));
|
|
38
31
|
}
|
|
39
32
|
if (__DEV__) {
|
|
40
33
|
Router.displayName = 'Router';
|
package/esm/contexts.d.ts
CHANGED
|
@@ -10,8 +10,5 @@ export declare const RouteContext: React.Context<IRoute<{
|
|
|
10
10
|
props?: import("@shuvi/router").IRouteComponentProps | undefined;
|
|
11
11
|
path: string;
|
|
12
12
|
filepath?: string | undefined;
|
|
13
|
-
id?: string | undefined;
|
|
14
|
-
__componentSourceWithAffix__?: string | undefined;
|
|
15
|
-
__resolveWeak__?: (() => any) | undefined;
|
|
16
13
|
}>>;
|
|
17
14
|
export declare const MatchedRouteContext: React.Context<IRouteContextObject<{}>>;
|
package/esm/hooks.d.ts
CHANGED
|
@@ -11,9 +11,6 @@ export declare function useCurrentRoute(): import("@shuvi/router").IRoute<{
|
|
|
11
11
|
props?: import("@shuvi/router").IRouteComponentProps | undefined;
|
|
12
12
|
path: string;
|
|
13
13
|
filepath?: string | undefined;
|
|
14
|
-
id?: string | undefined;
|
|
15
|
-
__componentSourceWithAffix__?: string | undefined;
|
|
16
|
-
__resolveWeak__?: (() => any) | undefined;
|
|
17
14
|
}>;
|
|
18
15
|
/**
|
|
19
16
|
* Blocks all navigation attempts. This is useful for preventing the page from
|
package/lib/Router.js
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Router = void 0;
|
|
4
4
|
const React = require("react");
|
|
5
|
-
const react_1 = require("react");
|
|
6
5
|
const PropTypes = require("prop-types");
|
|
7
6
|
const invariant_1 = require("@shuvi/utils/lib/invariant");
|
|
7
|
+
const shim_1 = require("use-sync-external-store/shim");
|
|
8
8
|
const contexts_1 = require("./contexts");
|
|
9
9
|
const hooks_1 = require("./hooks");
|
|
10
10
|
const constants_1 = require("./constants");
|
|
11
|
-
const utils_1 = require("./utils");
|
|
12
11
|
/**
|
|
13
12
|
* Provides location context for the rest of the app.
|
|
14
13
|
*
|
|
@@ -25,19 +24,13 @@ function Router({ children = null, static: staticProp = false, router }) {
|
|
|
25
24
|
router: router
|
|
26
25
|
};
|
|
27
26
|
}, [staticProp, router]);
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (unmount.current) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
forceupdate();
|
|
37
|
-
});
|
|
38
|
-
}, [router]);
|
|
27
|
+
const { subscribe, getSnapshot } = React.useMemo(() => ({
|
|
28
|
+
subscribe: (fn) => router.listen(fn),
|
|
29
|
+
getSnapshot: () => router.current
|
|
30
|
+
}), [router]);
|
|
31
|
+
const current = (0, shim_1.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
39
32
|
return (React.createElement(contexts_1.RouterContext.Provider, { value: contextVal },
|
|
40
|
-
React.createElement(contexts_1.RouteContext.Provider, { children: children, value:
|
|
33
|
+
React.createElement(contexts_1.RouteContext.Provider, { children: children, value: current })));
|
|
41
34
|
}
|
|
42
35
|
exports.Router = Router;
|
|
43
36
|
if (constants_1.__DEV__) {
|
package/lib/contexts.d.ts
CHANGED
|
@@ -10,8 +10,5 @@ export declare const RouteContext: React.Context<IRoute<{
|
|
|
10
10
|
props?: import("@shuvi/router").IRouteComponentProps | undefined;
|
|
11
11
|
path: string;
|
|
12
12
|
filepath?: string | undefined;
|
|
13
|
-
id?: string | undefined;
|
|
14
|
-
__componentSourceWithAffix__?: string | undefined;
|
|
15
|
-
__resolveWeak__?: (() => any) | undefined;
|
|
16
13
|
}>>;
|
|
17
14
|
export declare const MatchedRouteContext: React.Context<IRouteContextObject<{}>>;
|
package/lib/hooks.d.ts
CHANGED
|
@@ -11,9 +11,6 @@ export declare function useCurrentRoute(): import("@shuvi/router").IRoute<{
|
|
|
11
11
|
props?: import("@shuvi/router").IRouteComponentProps | undefined;
|
|
12
12
|
path: string;
|
|
13
13
|
filepath?: string | undefined;
|
|
14
|
-
id?: string | undefined;
|
|
15
|
-
__componentSourceWithAffix__?: string | undefined;
|
|
16
|
-
__resolveWeak__?: (() => any) | undefined;
|
|
17
14
|
}>;
|
|
18
15
|
/**
|
|
19
16
|
* Blocks all navigation attempts. This is useful for preventing the page from
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/router-react",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.12",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -15,33 +15,35 @@
|
|
|
15
15
|
"lib",
|
|
16
16
|
"esm"
|
|
17
17
|
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "run-p watch:*",
|
|
20
|
+
"watch:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm -w",
|
|
21
|
+
"watch:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib -w",
|
|
22
|
+
"prebuild": "rimraf lib esm",
|
|
23
|
+
"build": "run-p build:*",
|
|
24
|
+
"build:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm",
|
|
25
|
+
"build:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib"
|
|
26
|
+
},
|
|
18
27
|
"engines": {
|
|
19
28
|
"node": ">= 12.0.0"
|
|
20
29
|
},
|
|
21
30
|
"dependencies": {
|
|
22
|
-
"@shuvi/router": "1.0.0-rc.
|
|
23
|
-
"@shuvi/platform-shared": "1.0.0-rc.
|
|
24
|
-
"@shuvi/utils": "1.0.0-rc.
|
|
25
|
-
"prop-types": "^15.8.1"
|
|
31
|
+
"@shuvi/router": "1.0.0-rc.12",
|
|
32
|
+
"@shuvi/platform-shared": "1.0.0-rc.12",
|
|
33
|
+
"@shuvi/utils": "1.0.0-rc.12",
|
|
34
|
+
"prop-types": "^15.8.1",
|
|
35
|
+
"use-sync-external-store": "1.1.0"
|
|
26
36
|
},
|
|
27
37
|
"devDependencies": {
|
|
28
38
|
"@types/prop-types": "^15.7.5",
|
|
29
|
-
"@types/react": "
|
|
30
|
-
"@types/react-test-renderer": "
|
|
39
|
+
"@types/react": "18.0.9",
|
|
40
|
+
"@types/react-test-renderer": "18.0.0",
|
|
41
|
+
"@types/use-sync-external-store": "0.0.3",
|
|
31
42
|
"react-test-renderer": "^18.1.0",
|
|
32
43
|
"react": "18.1.0",
|
|
33
44
|
"react-dom": "18.1.0"
|
|
34
45
|
},
|
|
35
46
|
"peerDependencies": {
|
|
36
47
|
"react": ">=16.8.0"
|
|
37
|
-
},
|
|
38
|
-
"scripts": {
|
|
39
|
-
"dev": "run-p watch:*",
|
|
40
|
-
"watch:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm -w",
|
|
41
|
-
"watch:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib -w",
|
|
42
|
-
"prebuild": "rimraf lib esm",
|
|
43
|
-
"build": "run-p build:*",
|
|
44
|
-
"build:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm",
|
|
45
|
-
"build:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib"
|
|
46
48
|
}
|
|
47
|
-
}
|
|
49
|
+
}
|