@sequencemedia/react-router-redux-render 2.4.57 → 2.5.0
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/babel.config.cjs +3 -1
- package/eslint.config.mjs +147 -0
- package/index.d.mts +13 -0
- package/package.json +18 -5
- package/src/index.d.cts +5 -0
- package/src/index.d.mts +5 -0
- package/src/index.mjs +25 -19
- package/src/react-dom-server.cjs +3 -1
- package/src/react-dom-server.d.cts +4 -0
- package/src/react-dom-server.d.mts +10 -0
- package/src/react-dom-server.jsx +31 -19
- package/tsconfig.json +25 -0
package/babel.config.cjs
CHANGED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import globals from 'globals'
|
|
2
|
+
import standard from '@sequencemedia/eslint-config-standard/configs/recommended/merge'
|
|
3
|
+
import typescript from '@sequencemedia/eslint-config-typescript/configs/recommended/merge'
|
|
4
|
+
import babelParser from '@babel/eslint-parser'
|
|
5
|
+
import typescriptParser from '@typescript-eslint/parser'
|
|
6
|
+
import reactPlugin from 'eslint-plugin-react'
|
|
7
|
+
|
|
8
|
+
const reactParserOptions = {
|
|
9
|
+
ecmaFeatures: {
|
|
10
|
+
jsx: true
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const reactPlugins = {
|
|
15
|
+
react: reactPlugin
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const reactRules = {
|
|
19
|
+
'no-unused-vars': [
|
|
20
|
+
'error',
|
|
21
|
+
{
|
|
22
|
+
varsIgnorePattern: 'React'
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
quotes: [
|
|
26
|
+
'error',
|
|
27
|
+
'single'
|
|
28
|
+
],
|
|
29
|
+
'jsx-quotes': [
|
|
30
|
+
'error',
|
|
31
|
+
'prefer-single'
|
|
32
|
+
],
|
|
33
|
+
'react/jsx-indent': [
|
|
34
|
+
'error',
|
|
35
|
+
2,
|
|
36
|
+
{
|
|
37
|
+
checkAttributes: true,
|
|
38
|
+
indentLogicalExpressions: true
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const reactSettings = {
|
|
44
|
+
react: {
|
|
45
|
+
version: 'detect'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default [
|
|
50
|
+
{
|
|
51
|
+
ignores: [
|
|
52
|
+
'coverage'
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* React config for all `jsx` files
|
|
57
|
+
*/
|
|
58
|
+
{
|
|
59
|
+
...reactPlugin.configs.flat.recommended,
|
|
60
|
+
settings: {
|
|
61
|
+
...reactSettings
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
/**
|
|
65
|
+
* Standard config
|
|
66
|
+
*/
|
|
67
|
+
standard({
|
|
68
|
+
files: [
|
|
69
|
+
'**/*.{mjs,cjs,mts,cts}'
|
|
70
|
+
],
|
|
71
|
+
ignores: [
|
|
72
|
+
'src',
|
|
73
|
+
'test'
|
|
74
|
+
],
|
|
75
|
+
languageOptions: {
|
|
76
|
+
globals: {
|
|
77
|
+
...globals.node
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
standard({
|
|
82
|
+
files: [
|
|
83
|
+
'src/**/*.{mjs,cjs,mts,cts}'
|
|
84
|
+
],
|
|
85
|
+
languageOptions: {
|
|
86
|
+
globals: {
|
|
87
|
+
...globals.node
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}),
|
|
91
|
+
standard({
|
|
92
|
+
files: [
|
|
93
|
+
'test/**/*.{mjs,cjs,mts,cts}'
|
|
94
|
+
],
|
|
95
|
+
languageOptions: {
|
|
96
|
+
globals: {
|
|
97
|
+
...globals.mocha
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
/**
|
|
102
|
+
* Standard config for all `jsx` files
|
|
103
|
+
*/
|
|
104
|
+
standard({
|
|
105
|
+
files: [
|
|
106
|
+
'src/**/*.jsx'
|
|
107
|
+
],
|
|
108
|
+
languageOptions: {
|
|
109
|
+
parser: babelParser,
|
|
110
|
+
parserOptions: {
|
|
111
|
+
...reactParserOptions,
|
|
112
|
+
project: null
|
|
113
|
+
},
|
|
114
|
+
globals: {
|
|
115
|
+
...globals.browser
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
plugins: {
|
|
119
|
+
...reactPlugins
|
|
120
|
+
}, // @ts-expect-error Storybook
|
|
121
|
+
rules: {
|
|
122
|
+
...reactRules
|
|
123
|
+
},
|
|
124
|
+
settings: {
|
|
125
|
+
...reactSettings
|
|
126
|
+
}
|
|
127
|
+
}),
|
|
128
|
+
/**
|
|
129
|
+
* TypeScript config
|
|
130
|
+
*/
|
|
131
|
+
typescript({
|
|
132
|
+
files: [
|
|
133
|
+
'**/*.{mts,cts}'
|
|
134
|
+
],
|
|
135
|
+
languageOptions: {
|
|
136
|
+
parser: typescriptParser,
|
|
137
|
+
parserOptions: {
|
|
138
|
+
projectService: true,
|
|
139
|
+
project: 'tsconfig.json'
|
|
140
|
+
},
|
|
141
|
+
globals: {
|
|
142
|
+
...globals.node,
|
|
143
|
+
ReactRouterReduxRenderTypes: 'readonly'
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
]
|
package/index.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type React from 'react'
|
|
2
|
+
import type {
|
|
3
|
+
StaticRouterProps
|
|
4
|
+
} from 'react-router'
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
namespace ReactRouterReduxRenderTypes {
|
|
8
|
+
export type RouterPropsType = StaticRouterProps
|
|
9
|
+
export type RoutesType = React.ReactNode
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequencemedia/react-router-redux-render",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Sync/async isomorphic render of React apps with React Router + Redux",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"React",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"main": "./src/index.mjs",
|
|
16
16
|
"type": "module",
|
|
17
|
+
"types": "./index.d.mts",
|
|
17
18
|
"author": {
|
|
18
19
|
"name": "Jonathan Perry for Sequence Media Limited",
|
|
19
20
|
"email": "jonathanperry@sequencemedia.net",
|
|
@@ -28,7 +29,7 @@
|
|
|
28
29
|
"url": "git://github.com/sequencemedia/react-router-redux-render.git"
|
|
29
30
|
},
|
|
30
31
|
"scripts": {
|
|
31
|
-
"lint": "eslint
|
|
32
|
+
"lint": "eslint",
|
|
32
33
|
"lint:fix": "npm run lint -- --fix",
|
|
33
34
|
"prepare": "husky",
|
|
34
35
|
"test": "NODE_ENV=test mocha test --recursive --verbose"
|
|
@@ -39,16 +40,28 @@
|
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@babel/core": "^7.26.9",
|
|
42
|
-
"@babel/eslint-parser": "^7.26.
|
|
43
|
+
"@babel/eslint-parser": "^7.26.10",
|
|
43
44
|
"@babel/preset-env": "^7.26.9",
|
|
44
45
|
"@babel/preset-react": "^7.26.3",
|
|
45
46
|
"@babel/register": "^7.25.9",
|
|
47
|
+
"@sequencemedia/eslint-config-standard": "^0.2.42",
|
|
48
|
+
"@sequencemedia/eslint-config-typescript": "^0.1.60",
|
|
46
49
|
"@sequencemedia/sinon-chai": "^0.0.131",
|
|
50
|
+
"@types/babel__register": "^7.17.3",
|
|
51
|
+
"@types/debug": "^4.1.12",
|
|
52
|
+
"@types/prop-types": "^15.7.14",
|
|
53
|
+
"@types/react": "^19.0.10",
|
|
54
|
+
"@types/react-dom": "^19.0.4",
|
|
55
|
+
"@types/react-redux": "^7.1.34",
|
|
56
|
+
"@types/react-router": "^5.1.20",
|
|
57
|
+
"@types/redux": "^3.6.31",
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^8.26.1",
|
|
59
|
+
"@typescript-eslint/parser": "^8.26.1",
|
|
47
60
|
"chai": "^5.2.0",
|
|
48
61
|
"core-js": "^3.41.0",
|
|
49
|
-
"eslint": "
|
|
50
|
-
"eslint-config-standard": "^17.1.0",
|
|
62
|
+
"eslint": "^9.22.0",
|
|
51
63
|
"eslint-plugin-react": "^7.37.4",
|
|
64
|
+
"globals": "^16.0.0",
|
|
52
65
|
"husky": "^9.1.7",
|
|
53
66
|
"mocha": "^11.1.0",
|
|
54
67
|
"prop-types": "^15.8.1",
|
package/src/index.d.cts
ADDED
package/src/index.d.mts
ADDED
package/src/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @typedef {import('redux').Store} Store
|
|
3
|
+
* @typedef {ReactRouterReduxRenderTypes.RouterPropsType} RouterPropsType
|
|
4
|
+
* @typedef {ReactRouterReduxRenderTypes.RoutesType} RoutesType
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
import debug from 'debug'
|
|
@@ -16,18 +18,22 @@ const log = debug('@sequencemedia/react-router-redux-render')
|
|
|
16
18
|
log('`react-router-redux-render` is awake')
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
+
* @param {RouterPropsType} data
|
|
22
|
+
* @returns A boom object
|
|
21
23
|
*/
|
|
22
|
-
|
|
24
|
+
function notFound (data) {
|
|
25
|
+
return (
|
|
26
|
+
Boom.notFound('Routing exception', data)
|
|
27
|
+
)
|
|
28
|
+
}
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
31
|
+
* @param {Store} store
|
|
32
|
+
* @param {RouterPropsType & { context?: Record<PropertyKey, unknown> }} routerProps
|
|
33
|
+
* @param {RoutesType} routes
|
|
34
|
+
* @returns {string}
|
|
29
35
|
*/
|
|
30
|
-
export function renderToString (store, { location, context = {}, ...router }
|
|
36
|
+
export function renderToString (store, { location, context = {}, ...router }, routes) {
|
|
31
37
|
const routerProps = { ...router, location, context }
|
|
32
38
|
const string = getReactDOMServerRenderToString(store, routerProps, routes)
|
|
33
39
|
if (string) return string
|
|
@@ -35,12 +41,12 @@ export function renderToString (store, { location, context = {}, ...router } = {
|
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
44
|
+
* @param {Store} store
|
|
45
|
+
* @param {RouterPropsType & { context?: Record<PropertyKey, unknown> }} routerProps
|
|
46
|
+
* @param {RoutesType} routes
|
|
47
|
+
* @returns {string}
|
|
42
48
|
*/
|
|
43
|
-
export function renderToStaticMarkup (store, { location, context = {}, ...router }
|
|
49
|
+
export function renderToStaticMarkup (store, { location, context = {}, ...router }, routes) {
|
|
44
50
|
const routerProps = { ...router, location, context }
|
|
45
51
|
const string = getReactDOMServerRenderToStaticMarkup(store, routerProps, routes)
|
|
46
52
|
if (string) return string
|
|
@@ -48,12 +54,12 @@ export function renderToStaticMarkup (store, { location, context = {}, ...router
|
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
57
|
+
* @param {Store} store
|
|
58
|
+
* @param {RouterPropsType & { context?: Record<PropertyKey, unknown> }} routerProps
|
|
59
|
+
* @param {RoutesType} routes
|
|
60
|
+
* @returns {string}
|
|
55
61
|
*/
|
|
56
|
-
export
|
|
62
|
+
export function render (store, { location, context = {}, ...router }, routes) {
|
|
57
63
|
const routerProps = { ...router, location, context }
|
|
58
64
|
const string = getReactDOMServerRenderToString(store, routerProps, routes)
|
|
59
65
|
if (string) return string
|
package/src/react-dom-server.cjs
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Store } from 'redux'
|
|
2
|
+
|
|
3
|
+
declare module '#react-router-redux-render/react-dom-server' {
|
|
4
|
+
type RouterPropsType = ReactRouterReduxRenderTypes.RouterPropsType
|
|
5
|
+
type RoutesType = ReactRouterReduxRenderTypes.RoutesType
|
|
6
|
+
|
|
7
|
+
export function getReactDOMServerRenderToString (store: Store, routerProps: RouterPropsType, routes: RoutesType): string
|
|
8
|
+
|
|
9
|
+
export function getReactDOMServerRenderToStaticMarkup (store: Store, routerProps: RouterPropsType, routes: RoutesType): string
|
|
10
|
+
}
|
package/src/react-dom-server.jsx
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @typedef {import('redux').Store} Store
|
|
3
|
+
* @typedef {ReactRouterReduxRenderTypes.RouterPropsType} RouterPropsType
|
|
4
|
+
* @typedef {ReactRouterReduxRenderTypes.RoutesType} RoutesType
|
|
5
|
+
*
|
|
6
|
+
* @typedef {{
|
|
7
|
+
* props: RouterPropsType
|
|
8
|
+
* }} RouterPropsException
|
|
9
|
+
*
|
|
10
|
+
* @typedef {{
|
|
11
|
+
* e: unknown
|
|
12
|
+
* }} Exception
|
|
3
13
|
*/
|
|
4
14
|
|
|
5
15
|
import debug from 'debug'
|
|
@@ -18,17 +28,21 @@ const log = debug('@sequencemedia/react-redux-render')
|
|
|
18
28
|
log('`react-redux-render` is awake')
|
|
19
29
|
|
|
20
30
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
31
|
+
* @param {Error} e
|
|
32
|
+
* @param {RouterPropsException | Exception} data
|
|
33
|
+
* @returns A boom object
|
|
24
34
|
*/
|
|
25
|
-
|
|
35
|
+
function badImplementation (e, data) {
|
|
36
|
+
return (
|
|
37
|
+
Boom.boomify(e, { statusCode: 500, message: 'Rendering exception', data })
|
|
38
|
+
)
|
|
39
|
+
}
|
|
26
40
|
|
|
27
41
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
42
|
+
* @param {Store} store
|
|
43
|
+
* @param {RouterPropsType} routerProps
|
|
44
|
+
* @param {RoutesType} routes
|
|
45
|
+
* @returns {string}
|
|
32
46
|
*/
|
|
33
47
|
export function getReactDOMServerRenderToString (store, routerProps, routes) {
|
|
34
48
|
try {
|
|
@@ -40,17 +54,16 @@ export function getReactDOMServerRenderToString (store, routerProps, routes) {
|
|
|
40
54
|
</Provider>
|
|
41
55
|
)
|
|
42
56
|
} catch (e) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
throw badImplementation(e, routerProps)
|
|
57
|
+
if (e instanceof Error) throw badImplementation(e, { props: routerProps })
|
|
58
|
+
throw badImplementation(new Error('Exception'), { e })
|
|
46
59
|
}
|
|
47
60
|
}
|
|
48
61
|
|
|
49
62
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
63
|
+
* @param {Store} store
|
|
64
|
+
* @param {RouterPropsType} routerProps
|
|
65
|
+
* @param {RoutesType} routes
|
|
66
|
+
* @returns {string}
|
|
54
67
|
*/
|
|
55
68
|
export function getReactDOMServerRenderToStaticMarkup (store, routerProps, routes) {
|
|
56
69
|
try {
|
|
@@ -62,8 +75,7 @@ export function getReactDOMServerRenderToStaticMarkup (store, routerProps, route
|
|
|
62
75
|
</Provider>
|
|
63
76
|
)
|
|
64
77
|
} catch (e) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
throw badImplementation(e, routerProps)
|
|
78
|
+
if (e instanceof Error) throw badImplementation(e, { props: routerProps })
|
|
79
|
+
throw badImplementation(new Error('Exception'), { e })
|
|
68
80
|
}
|
|
69
81
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "NodeNext",
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"checkJs": true,
|
|
7
|
+
"noEmit": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"jsx": "react",
|
|
10
|
+
"paths": {
|
|
11
|
+
"#react-router-redux-render": [
|
|
12
|
+
"./src/index.mjs"
|
|
13
|
+
],
|
|
14
|
+
"#react-router-redux-render/react-dom-server": [
|
|
15
|
+
"./src/react-dom-server.cjs"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"include": [
|
|
20
|
+
"."
|
|
21
|
+
],
|
|
22
|
+
"exclude": [
|
|
23
|
+
"test"
|
|
24
|
+
]
|
|
25
|
+
}
|