@appigram/react-code-split-ssr 1.2.1 → 1.2.2

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.
@@ -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, jsxs as _jsxs } from "react/jsx-runtime";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { matchPath, Route, Routes } from "react-router-dom";
12
12
  const generateRoutes = (options = {
13
13
  pathname: "/",
@@ -23,14 +23,12 @@ const generateRoutes = (options = {
23
23
  const renderElement = (path, bundle) => {
24
24
  if (!preloadedComp)
25
25
  return bundle;
26
- const isSSR = (preload && preload.path === path) || (!preload && !path);
27
- const Element = isSSR ? preloadedComp.default : bundle;
28
- return _jsx(Element, {}, void 0);
29
- };
30
- return () => {
31
- return (_jsxs(Routes, { children: [options.routes.map((props, i) => {
32
- return (_jsx(Route, { path: props.path, element: renderElement(props.path, props.element()) }, i));
33
- }), _jsx(Route, { element: renderElement(null, options.notFoundComp()) }, void 0)] }, void 0));
26
+ const isRouteMatched = (preload && preload.path === path) || (!preload && !path);
27
+ const Element = isRouteMatched ? preloadedComp.default : bundle;
28
+ return isRouteMatched ? _jsx(Element, {}, void 0) : Element;
34
29
  };
30
+ return (_jsx(Routes, { children: options.routes.map((props, i) => {
31
+ return (_jsx(Route, { path: props.path, element: renderElement(props.path, props.element) }, i));
32
+ }) }, void 0));
35
33
  });
36
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.1",
3
+ "version": "1.2.2",
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": "^17.0.34",
25
+ "@types/react": "^17.0.37",
26
26
  "@types/react-router-dom": "^5.3.2",
27
27
  "tslint": "^6.1.3",
28
28
  "tslint-react": "^5.0.0",
29
- "typescript": "^4.4.4"
29
+ "typescript": "^4.5.4"
30
30
  },
31
- "peerDependencies": {
31
+ "dependencies": {
32
32
  "react": "^17.0.2",
33
33
  "react-dom": "^17.0.2",
34
- "react-router-dom": "^6.0.2"
34
+ "react-router-dom": "^6.1.1"
35
35
  }
36
36
  }
@@ -8,7 +8,7 @@ export interface IJSXModule {
8
8
  export interface ISSRRoute {
9
9
  caseSensitive?: boolean;
10
10
  children?: React.ReactNode;
11
- element?: () => React.FunctionComponentElement<{ mod: Promise<IJSXModule> }>;
11
+ element?: any; // () => React.FunctionComponentElement<{ mod: Promise<IJSXModule> }>;
12
12
  index?: boolean;
13
13
  path?: string;
14
14
  }
@@ -24,7 +24,7 @@ const generateRoutes = async (
24
24
  pathname: "/",
25
25
  routes: [],
26
26
  }
27
- ): Promise<React.FC> => {
27
+ ) => {
28
28
  if (!Array.isArray(options.routes) || options.routes.length === 0) {
29
29
  throw new Error("options.routes must be an non-empty array");
30
30
  }
@@ -40,27 +40,24 @@ const generateRoutes = async (
40
40
 
41
41
  const renderElement = (path: string, bundle: ReactElement) => {
42
42
  if (!preloadedComp) return bundle;
43
- const isSSR = (preload && preload.path === path) || (!preload && !path);
44
- const Element = isSSR ? preloadedComp.default : bundle;
45
- return <Element />;
43
+ const isRouteMatched = (preload && preload.path === path) || (!preload && !path);
44
+ const Element = isRouteMatched ? preloadedComp.default : bundle;
45
+ return isRouteMatched ? <Element /> : Element
46
46
  };
47
47
 
48
- return () => {
49
- return (
50
- <Routes>
51
- {options.routes.map((props, i) => {
52
- return (
53
- <Route
54
- key={i}
55
- path={props.path}
56
- element={renderElement(props.path, props.element())}
57
- />
58
- );
59
- })}
60
- <Route element={renderElement(null, options.notFoundComp())} />
61
- </Routes>
62
- );
63
- };
48
+ return (
49
+ <Routes>
50
+ {options.routes.map((props, i) => {
51
+ return (
52
+ <Route
53
+ key={i}
54
+ path={props.path}
55
+ element={renderElement(props.path, props.element)}
56
+ />
57
+ );
58
+ })}
59
+ </Routes>
60
+ );
64
61
  };
65
62
 
66
63
  export default generateRoutes;