@appigram/react-code-split-ssr 1.2.2 → 1.2.5
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 +4 -4
- package/lib/bundle.js +2 -2
- package/lib/generate-routes.js +5 -5
- package/package.json +7 -7
- package/src/generate-routes.tsx +2 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ React code splitting with server side rendering
|
|
|
3
3
|
|
|
4
4
|
## How it works
|
|
5
5
|
|
|
6
|
-
- Based on React Router
|
|
6
|
+
- Based on React Router 6
|
|
7
7
|
- Server side: Load all components synchronously, then render to string.
|
|
8
8
|
- Client side: Load the initial component before rendering, render the entire screen synchronously, then load the rest of routes asynchronously.
|
|
9
9
|
|
|
@@ -26,9 +26,6 @@ export const routes = [
|
|
|
26
26
|
{ exact: true, path: '/posts', component: Posts },
|
|
27
27
|
]
|
|
28
28
|
|
|
29
|
-
export const redirects = [
|
|
30
|
-
{ from: '/test', to: '/posts' }
|
|
31
|
-
]
|
|
32
29
|
```
|
|
33
30
|
Client:
|
|
34
31
|
```js
|
|
@@ -105,6 +102,9 @@ A function that returns a `Promise` object which can be resolved to React Router
|
|
|
105
102
|
- redirects {objects}[] - An array of `<Redirect>` props object
|
|
106
103
|
- notFoundComp {Component} - A React component for 404 Not Found, only accepts `() => <Bundle/>`
|
|
107
104
|
|
|
105
|
+
## v1.2.0
|
|
106
|
+
- [x] Remove redirects, Fix React-Router v6 specific rendering
|
|
107
|
+
|
|
108
108
|
## v1.1.0
|
|
109
109
|
- [x] Upgrade to React-Router v6
|
|
110
110
|
|
package/lib/bundle.js
CHANGED
|
@@ -20,7 +20,7 @@ const Bundle = ({ mod, loading }) => {
|
|
|
20
20
|
})();
|
|
21
21
|
}, []);
|
|
22
22
|
const Mod = state.mod;
|
|
23
|
-
const Loading = loading || (() => _jsx("div", {}
|
|
24
|
-
return state.mod ? _jsx(Mod, {}
|
|
23
|
+
const Loading = loading || (() => _jsx("div", {}));
|
|
24
|
+
return state.mod ? _jsx(Mod, {}) : _jsx(Loading, {});
|
|
25
25
|
};
|
|
26
26
|
export default Bundle;
|
package/lib/generate-routes.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { matchPath, Route, Routes } from "react-router-dom";
|
|
12
12
|
const generateRoutes = (options = {
|
|
13
13
|
pathname: "/",
|
|
@@ -25,10 +25,10 @@ const generateRoutes = (options = {
|
|
|
25
25
|
return bundle;
|
|
26
26
|
const isRouteMatched = (preload && preload.path === path) || (!preload && !path);
|
|
27
27
|
const Element = isRouteMatched ? preloadedComp.default : bundle;
|
|
28
|
-
return isRouteMatched ? _jsx(Element, {}
|
|
28
|
+
return isRouteMatched ? _jsx(Element, {}) : Element;
|
|
29
29
|
};
|
|
30
|
-
return (
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
return (_jsxs(Routes, { children: [options.routes.map((props, i) => {
|
|
31
|
+
return (_jsx(Route, { path: props.path, element: renderElement(props.path, props.element) }, i));
|
|
32
|
+
}), _jsx(Route, { path: '*', element: renderElement(null, options.notFoundComp) }, 'nf')] }));
|
|
33
33
|
});
|
|
34
34
|
export default generateRoutes;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appigram/react-code-split-ssr",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "React code splitting with SSR",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"author": "Eugene Sysmanov",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/react": "^
|
|
26
|
-
"@types/react-router-dom": "^5.3.
|
|
25
|
+
"@types/react": "^18.0.8",
|
|
26
|
+
"@types/react-router-dom": "^5.3.3",
|
|
27
27
|
"tslint": "^6.1.3",
|
|
28
28
|
"tslint-react": "^5.0.0",
|
|
29
|
-
"typescript": "^4.
|
|
29
|
+
"typescript": "^4.6.4"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"react": "^
|
|
33
|
-
"react-dom": "^
|
|
34
|
-
"react-router-dom": "^6.
|
|
32
|
+
"react": "^18.1.0",
|
|
33
|
+
"react-dom": "^18.1.0",
|
|
34
|
+
"react-router-dom": "^6.3.0"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/generate-routes.tsx
CHANGED
|
@@ -16,7 +16,7 @@ export interface ISSRRoute {
|
|
|
16
16
|
export interface IOptions {
|
|
17
17
|
pathname: string;
|
|
18
18
|
routes: ISSRRoute[];
|
|
19
|
-
notFoundComp?: () => React.FunctionComponentElement<{ mod: Promise<IJSXModule> }>;
|
|
19
|
+
notFoundComp?: any; // () => React.FunctionComponentElement<{ mod: Promise<IJSXModule> }>;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const generateRoutes = async (
|
|
@@ -56,6 +56,7 @@ const generateRoutes = async (
|
|
|
56
56
|
/>
|
|
57
57
|
);
|
|
58
58
|
})}
|
|
59
|
+
<Route key='nf' path='*' element={renderElement(null, options.notFoundComp)} />
|
|
59
60
|
</Routes>
|
|
60
61
|
);
|
|
61
62
|
};
|