@appigram/react-code-split-ssr 1.2.16 → 1.3.1

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 CHANGED
@@ -1,114 +1,130 @@
1
1
  # React Code Split SSR
2
+
2
3
  React code splitting with server side rendering
3
4
 
4
5
  ## How it works
5
6
 
6
- - Based on React Router 6
7
+ - React 19
8
+ - Based on React Router 7
7
9
  - Server side: Load all components synchronously, then render to string.
8
10
  - Client side: Load the initial component before rendering, render the entire screen synchronously, then load the rest of routes asynchronously.
9
11
 
10
12
  #### Note: This packages is only tested in Meteor projects, but technically it can be used in any Nodejs projects. Here is an [example](https://github.com/lhz516/react-code-split-ssr-example) with Meteor
11
13
 
12
14
  ## Usage
15
+
13
16
  ```
14
17
  $ npm i react-code-split-ssr --save
15
18
  ```
19
+
16
20
  Client/server shared:
21
+
17
22
  ```js
18
- import { Bundle } from 'react-code-split-ssr'
19
- import React from 'react'
23
+ import { Bundle } from 'react-code-split-ssr';
24
+ import React from 'react';
20
25
 
21
- const Home = () => <Bundle mod={import('/imports/modules/home')} />
22
- const Posts = () => <Bundle mod={import('/imports/modules/posts')} />
26
+ const Home = () => <Bundle mod={import('/imports/modules/home')} />;
27
+ const Posts = () => <Bundle mod={import('/imports/modules/posts')} />;
23
28
 
24
29
  export const routes = [
25
- { exact: true, path: '/', component: Home },
26
- { exact: true, path: '/posts', component: Posts },
27
- ]
28
-
30
+ { exact: true, path: '/', component: Home },
31
+ { exact: true, path: '/posts', component: Posts },
32
+ ];
29
33
  ```
34
+
30
35
  Client:
36
+
31
37
  ```js
32
- import React from 'react'
33
- import { render } from 'react-dom'
34
- import { matchPath } from 'react-router'
35
- import { BrowserRouter, Route, Switch } from 'react-router-dom'
36
- import { generateRoutes } from 'react-code-split-ssr'
37
- import { routes, redirects } from '/imports/routes'
38
+ import React from 'react';
39
+ import { render } from 'react-dom';
40
+ import { matchPath } from 'react-router';
41
+ import { BrowserRouter, Route, Switch } from 'react-router-dom';
42
+ import { generateRoutes } from 'react-code-split-ssr';
43
+ import { routes, redirects } from '/imports/routes';
38
44
  // import some components...
39
45
 
40
46
  /* In an async function */
41
47
  const Routes = await generateRoutes({
42
- routes,
43
- redirects,
44
- notFoundComp: NotFound,
45
- pathname: window.location.pathname,
46
- })
48
+ routes,
49
+ redirects,
50
+ notFoundComp: NotFound,
51
+ pathname: window.location.pathname,
52
+ });
47
53
  render(
48
- <BrowserRouter>
49
- <Layout>
50
- <Routes />
51
- </Layout>
52
- </BrowserRouter>,
53
- document.getElementById('app'),
54
- )
54
+ <BrowserRouter>
55
+ <Layout>
56
+ <Routes />
57
+ </Layout>
58
+ </BrowserRouter>,
59
+ document.getElementById('app')
60
+ );
55
61
  ```
62
+
56
63
  Server:
64
+
57
65
  ```js
58
- import { Route, StaticRouter, Switch } from 'react-router'
59
- import React from 'react'
60
- import { renderToString } from 'react-dom/server'
61
- import { generateRoutes } from 'react-code-split-ssr'
62
- import { routes, redirects } from '/imports/routes'
66
+ import { Route, StaticRouter, Switch } from 'react-router';
67
+ import React from 'react';
68
+ import { renderToString } from 'react-dom/server';
69
+ import { generateRoutes } from 'react-code-split-ssr';
70
+ import { routes, redirects } from '/imports/routes';
63
71
  // import some components...
64
72
 
65
73
  /* In an async server router */
66
74
  const Routes = await generateRoutes({
67
- routes,
68
- redirects,
69
- notFoundComp: NotFound,
70
- pathname: req.url
71
- })
72
-
73
- const ServerRoutes = ({url, context = {}}) => (
74
- <StaticRouter
75
- location={url.pathname}
76
- context={context}
77
- >
78
- <Layout>
79
- <Routes />
80
- </Layout>
81
- </StaticRouter>
82
- )
83
- const bodyHtmlString = renderToString(<ServerRoutes url={sink.request.url} />)
75
+ routes,
76
+ redirects,
77
+ notFoundComp: NotFound,
78
+ pathname: req.url,
79
+ });
80
+
81
+ const ServerRoutes = ({ url, context = {} }) => (
82
+ <StaticRouter location={url.pathname} context={context}>
83
+ <Layout>
84
+ <Routes />
85
+ </Layout>
86
+ </StaticRouter>
87
+ );
88
+ const bodyHtmlString = renderToString(<ServerRoutes url={sink.request.url} />);
84
89
  // Use bodyHtmlString to where you need
85
90
  ```
86
91
 
87
92
  ## API
88
93
 
89
94
  ### Bundle - React Component \<Bundle\>
95
+
90
96
  #### Props
91
- - mod {Promise<Component>} ***Required*** - A `Promise` object which can be resolved to React Component
97
+
98
+ - mod {Promise<Component>} **_Required_** - A `Promise` object which can be resolved to React Component
92
99
  - loading {Component} - A React Component
93
100
 
94
101
  ### generateRoutes - Func (object: Options)
102
+
95
103
  A function that returns a `Promise` object which can be resolved to React Router routes wrapped in `<Switch>`
96
104
 
97
105
  #### Options
98
- - pathname {string} ***Required*** - Pathname for initial loading
99
- - routes {objects}[] ***Required*** - An array of `<Route>` props object
106
+
107
+ - pathname {string} **_Required_** - Pathname for initial loading
108
+ - routes {objects}[] **_Required_** - An array of `<Route>` props object
100
109
  - `component` field only accepts `() => <Bundle/>`
101
110
  - `location`, `render` fields are currently not supported
102
- - redirects {objects}[] - An array of `<Redirect>` props object
111
+ - redirects {objects}[] - An array of `<Redirect>` props object
103
112
  - notFoundComp {Component} - A React component for 404 Not Found, only accepts `() => <Bundle/>`
104
113
 
114
+ ## v1.3.0
115
+
116
+ - [x] Upgrade to React-Router 7 and React 19
117
+
105
118
  ## v1.2.0
119
+
106
120
  - [x] Remove redirects, Fix React-Router v6 specific rendering
107
121
 
108
122
  ## v1.1.0
123
+
109
124
  - [x] Upgrade to React-Router v6
110
125
 
111
126
  ## v1.0.0
127
+
112
128
  - [ ] SSR correctly for redirected routes
113
- - [X] Change `notFoundComp` to `() => <Bundle />`
129
+ - [x] Change `notFoundComp` to `() => <Bundle />`
114
130
  - [ ] Add more argument validations
package/lib/bundle.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export interface IProps {
3
2
  mod: Promise<any>;
4
3
  loading?: React.FC;
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
- import { matchPath, Route, Routes } from "react-router-dom";
11
+ import { matchPath, Route, Routes } from "react-router";
12
12
  const generateRoutes = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (options = {
13
13
  pathname: "/",
14
14
  routes: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appigram/react-code-split-ssr",
3
- "version": "1.2.16",
3
+ "version": "1.3.1",
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": "^18.3.1",
25
+ "@types/react": "^19.0.10",
26
26
  "@types/react-router-dom": "^5.3.3",
27
27
  "tslint": "^6.1.3",
28
28
  "tslint-react": "^5.0.0",
29
- "typescript": "^5.4.5"
29
+ "typescript": "^5.7.3"
30
30
  },
31
31
  "dependencies": {
32
- "react": "^18.3.1",
33
- "react-dom": "^18.3.1",
34
- "react-router-dom": "^6.23.0"
32
+ "react": "^19.0.0",
33
+ "react-dom": "^19.0.0",
34
+ "react-router": "^7.2.0"
35
35
  }
36
36
  }
@@ -1,5 +1,5 @@
1
1
  import React, { ReactElement } from "react";
2
- import { matchPath, Route, Routes } from "react-router-dom";
2
+ import { matchPath, Route, Routes } from "react-router";
3
3
 
4
4
  export interface IJSXModule {
5
5
  default: React.FC | React.ComponentClass;