@nestjs-ssr/react 0.1.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/LICENSE +22 -0
- package/README.md +587 -0
- package/dist/index-Bptct1Q3.d.mts +419 -0
- package/dist/index-Bptct1Q3.d.ts +419 -0
- package/dist/index.d.mts +220 -0
- package/dist/index.d.ts +220 -0
- package/dist/index.js +8148 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +8113 -0
- package/dist/index.mjs.map +1 -0
- package/dist/render/index.d.mts +8 -0
- package/dist/render/index.d.ts +8 -0
- package/dist/render/index.js +1110 -0
- package/dist/render/index.js.map +1 -0
- package/dist/render/index.mjs +1102 -0
- package/dist/render/index.mjs.map +1 -0
- package/dist/templates/entry-client.tsx +20 -0
- package/dist/templates/entry-server.tsx +13 -0
- package/dist/templates/index.html +17 -0
- package/dist/vite/index.d.mts +11 -0
- package/dist/vite/index.d.ts +11 -0
- package/dist/vite/index.js +7022 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/index.mjs +6997 -0
- package/dist/vite/index.mjs.map +1 -0
- package/package.json +135 -0
- package/src/global.d.ts +32 -0
- package/src/templates/entry-client.tsx +20 -0
- package/src/templates/entry-server.tsx +13 -0
- package/src/templates/index.html +17 -0
package/package.json
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nestjs-ssr/react",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "React SSR for NestJS that respects Clean Architecture. Proper DI, SOLID principles, clear separation of concerns.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nestjs",
|
|
7
|
+
"nest",
|
|
8
|
+
"nestjs-react",
|
|
9
|
+
"nestjs-ssr",
|
|
10
|
+
"react",
|
|
11
|
+
"ssr",
|
|
12
|
+
"server-side-rendering",
|
|
13
|
+
"react-ssr",
|
|
14
|
+
"clean-architecture",
|
|
15
|
+
"dependency-injection",
|
|
16
|
+
"solid-principles",
|
|
17
|
+
"separation-of-concerns",
|
|
18
|
+
"mvc",
|
|
19
|
+
"view-layer",
|
|
20
|
+
"vite",
|
|
21
|
+
"typescript",
|
|
22
|
+
"streaming-ssr",
|
|
23
|
+
"hydration",
|
|
24
|
+
"hmr",
|
|
25
|
+
"hot-module-replacement"
|
|
26
|
+
],
|
|
27
|
+
"author": "Georgi Alexandrov",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/georgialexandrov/nestjs-ssr.git",
|
|
32
|
+
"directory": "packages/react"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/georgialexandrov/nestjs-ssr/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/georgialexandrov/nestjs-ssr#readme",
|
|
38
|
+
"main": "./dist/index.js",
|
|
39
|
+
"module": "./dist/index.mjs",
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"exports": {
|
|
42
|
+
".": {
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"import": "./dist/index.mjs",
|
|
45
|
+
"require": "./dist/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./render": {
|
|
48
|
+
"types": "./dist/render/index.d.ts",
|
|
49
|
+
"import": "./dist/render/index.mjs",
|
|
50
|
+
"require": "./dist/render/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./vite": {
|
|
53
|
+
"types": "./dist/vite/index.d.ts",
|
|
54
|
+
"import": "./dist/vite/index.mjs",
|
|
55
|
+
"require": "./dist/vite/index.js"
|
|
56
|
+
},
|
|
57
|
+
"./react/*": {
|
|
58
|
+
"types": "./dist/react/*.d.ts",
|
|
59
|
+
"import": "./dist/react/*.mjs",
|
|
60
|
+
"require": "./dist/react/*.js"
|
|
61
|
+
},
|
|
62
|
+
"./templates/*": "./src/templates/*",
|
|
63
|
+
"./package.json": "./package.json"
|
|
64
|
+
},
|
|
65
|
+
"files": [
|
|
66
|
+
"dist",
|
|
67
|
+
"src/templates",
|
|
68
|
+
"src/global.d.ts",
|
|
69
|
+
"README.md",
|
|
70
|
+
"LICENSE"
|
|
71
|
+
],
|
|
72
|
+
"sideEffects": false,
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "tsup",
|
|
75
|
+
"dev": "tsup --watch",
|
|
76
|
+
"typecheck": "tsc --noEmit",
|
|
77
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
78
|
+
"test": "vitest run",
|
|
79
|
+
"test:watch": "vitest",
|
|
80
|
+
"test:ui": "vitest --ui",
|
|
81
|
+
"test:coverage": "vitest run --coverage",
|
|
82
|
+
"prepublishOnly": "pnpm build && pnpm typecheck && pnpm test"
|
|
83
|
+
},
|
|
84
|
+
"peerDependencies": {
|
|
85
|
+
"@nestjs/common": "^11.0.0",
|
|
86
|
+
"@nestjs/core": "^11.0.0",
|
|
87
|
+
"@nestjs/platform-express": "^11.0.0",
|
|
88
|
+
"http-proxy-middleware": "^3.0.0 || ^2.0.0",
|
|
89
|
+
"react": "^19.0.0",
|
|
90
|
+
"react-dom": "^19.0.0",
|
|
91
|
+
"typescript": "^5.0.0",
|
|
92
|
+
"vite": "^7.0.0 || ^6.0.0"
|
|
93
|
+
},
|
|
94
|
+
"peerDependenciesMeta": {
|
|
95
|
+
"http-proxy-middleware": {
|
|
96
|
+
"optional": true
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"dependencies": {
|
|
100
|
+
"escape-html": "^1.0.3",
|
|
101
|
+
"serialize-javascript": "^6.0.2"
|
|
102
|
+
},
|
|
103
|
+
"devDependencies": {
|
|
104
|
+
"@nestjs/common": "^11.0.0",
|
|
105
|
+
"@nestjs/core": "^11.0.0",
|
|
106
|
+
"@nestjs/platform-express": "^11.0.0",
|
|
107
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
108
|
+
"@testing-library/react": "^16.3.0",
|
|
109
|
+
"@types/escape-html": "^1.0.4",
|
|
110
|
+
"@types/express": "^5.0.5",
|
|
111
|
+
"@types/glob": "^9.0.0",
|
|
112
|
+
"@types/node": "^22.0.0",
|
|
113
|
+
"@types/react": "^19.0.0",
|
|
114
|
+
"@types/react-dom": "^19.0.0",
|
|
115
|
+
"@types/serialize-javascript": "^5.0.4",
|
|
116
|
+
"@vitejs/plugin-react": "^4.7.0",
|
|
117
|
+
"@vitest/ui": "^4.0.14",
|
|
118
|
+
"glob": "^13.0.0",
|
|
119
|
+
"happy-dom": "^20.0.11",
|
|
120
|
+
"react": "^19.0.0",
|
|
121
|
+
"react-dom": "^19.0.0",
|
|
122
|
+
"rxjs": "^7.8.2",
|
|
123
|
+
"tsup": "^8.0.0",
|
|
124
|
+
"typescript": "^5.7.2",
|
|
125
|
+
"vite": "^7.0.5",
|
|
126
|
+
"vitest": "^4.0.14"
|
|
127
|
+
},
|
|
128
|
+
"publishConfig": {
|
|
129
|
+
"access": "public"
|
|
130
|
+
},
|
|
131
|
+
"engines": {
|
|
132
|
+
"node": ">=20.0.0",
|
|
133
|
+
"pnpm": ">=8.0.0"
|
|
134
|
+
}
|
|
135
|
+
}
|
package/src/global.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global type declarations for @nestjs-ssr/react
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
/**
|
|
8
|
+
* Initial state/props serialized from the server for hydration
|
|
9
|
+
*/
|
|
10
|
+
__INITIAL_STATE__: any;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Render context serialized from the server for hydration
|
|
14
|
+
*/
|
|
15
|
+
__CONTEXT__: any;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Component path for the current page
|
|
19
|
+
*/
|
|
20
|
+
__COMPONENT_PATH__: string;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Module declaration for generated view registry
|
|
26
|
+
* This file is generated at build time in user applications
|
|
27
|
+
*/
|
|
28
|
+
declare module '@/views/view-registry.generated' {
|
|
29
|
+
export const viewRegistry: Record<string, React.ComponentType<any>>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { StrictMode } from 'react';
|
|
2
|
+
import { hydrateRoot } from 'react-dom/client';
|
|
3
|
+
import { viewRegistry } from '@/views/view-registry.generated';
|
|
4
|
+
|
|
5
|
+
const viewPath = window.__COMPONENT_PATH__;
|
|
6
|
+
const initialProps = window.__INITIAL_STATE__ || {};
|
|
7
|
+
const renderContext = window.__CONTEXT__ || {};
|
|
8
|
+
|
|
9
|
+
const ViewComponent = viewRegistry[viewPath];
|
|
10
|
+
|
|
11
|
+
if (!ViewComponent) {
|
|
12
|
+
throw new Error(`View "${viewPath}" not found in registry`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
hydrateRoot(
|
|
16
|
+
document.getElementById('root')!,
|
|
17
|
+
<StrictMode>
|
|
18
|
+
<ViewComponent {...initialProps} context={renderContext} />
|
|
19
|
+
</StrictMode>,
|
|
20
|
+
);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { renderToString } from 'react-dom/server';
|
|
2
|
+
import { viewRegistry } from '@/views/view-registry.generated';
|
|
3
|
+
|
|
4
|
+
export function renderComponent(viewPath: string, data: any) {
|
|
5
|
+
const ViewComponent = viewRegistry[viewPath];
|
|
6
|
+
|
|
7
|
+
if (!ViewComponent) {
|
|
8
|
+
throw new Error(`View "${viewPath}" not found in registry`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const { data: pageData, __context: context } = data;
|
|
12
|
+
return renderToString(<ViewComponent {...pageData} context={context} />);
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>NestJS React SSR</title>
|
|
7
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
8
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
9
|
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
|
|
10
|
+
<!--styles-->
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<div id="root"><!--app-html--></div>
|
|
14
|
+
<!--initial-state-->
|
|
15
|
+
<!--client-scripts-->
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|