@cordis-web/plugin-ui-runtime-ssr 0.0.0-stage → 0.2.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/dist/browser/index.html +27 -0
- package/dist/browser/runtime.js +271 -0
- package/dist/client/entry.d.ts +2 -0
- package/dist/client/entry.d.ts.map +1 -0
- package/dist/client/entry.js +6 -0
- package/dist/client/entry.js.map +1 -0
- package/dist/client/index.d.ts +28 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +58 -0
- package/dist/client/index.js.map +1 -0
- package/dist/server/index.d.ts +62 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +245 -0
- package/dist/server/index.js.map +1 -0
- package/dist/shared/index.d.ts +40 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +87 -0
- package/dist/shared/index.js.map +1 -0
- package/package.json +39 -4
- package/README.md +0 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>cordis-web</title>
|
|
7
|
+
<script type="importmap">
|
|
8
|
+
{
|
|
9
|
+
"imports": {
|
|
10
|
+
"react": "/ui-runtime/vendor/react.js",
|
|
11
|
+
"react/jsx-runtime": "/ui-runtime/vendor/react.js",
|
|
12
|
+
"react-dom/client": "/ui-runtime/vendor/react-dom-client.js",
|
|
13
|
+
"scheduler": "/ui-runtime/vendor/scheduler.js",
|
|
14
|
+
"react-router": "/ui-runtime/vendor/react-router.js",
|
|
15
|
+
"jotai": "/ui-runtime/vendor/jotai.js",
|
|
16
|
+
"jotai/utils": "/ui-runtime/vendor/jotai.js",
|
|
17
|
+
"cordis": "/ui-runtime/vendor/cordis.js"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
</head>
|
|
22
|
+
<body>
|
|
23
|
+
<!--SSR_ROOT-->
|
|
24
|
+
<script>window.__CORDIS_WEB_SSR_STATE__ = null/*SSR_STATE*/;</script>
|
|
25
|
+
<script type="module" src="/ui-runtime-ssr/runtime.js"></script>
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name3 in all)
|
|
4
|
+
__defProp(target, name3, { get: all[name3], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/client/index.tsx
|
|
8
|
+
import { createElement as createElement3 } from "react";
|
|
9
|
+
import { hydrateRoot, createRoot as createRoot2 } from "react-dom/client";
|
|
10
|
+
import { BrowserRouter as BrowserRouter2, Route as Route2, Routes as Routes2 } from "react-router";
|
|
11
|
+
import { Provider as JotaiProvider2 } from "jotai";
|
|
12
|
+
import { Context as Context2 } from "cordis";
|
|
13
|
+
|
|
14
|
+
// ../ui-registry/dist/client/index.js
|
|
15
|
+
var client_exports = {};
|
|
16
|
+
__export(client_exports, {
|
|
17
|
+
UiRegistryService: () => UiRegistryService,
|
|
18
|
+
apply: () => apply,
|
|
19
|
+
inject: () => inject,
|
|
20
|
+
name: () => name
|
|
21
|
+
});
|
|
22
|
+
import { Service } from "cordis";
|
|
23
|
+
var UiRegistryService = class extends Service {
|
|
24
|
+
uis = /* @__PURE__ */ new Map();
|
|
25
|
+
constructor(ctx) {
|
|
26
|
+
super(ctx, "uiRegistry");
|
|
27
|
+
}
|
|
28
|
+
register(ui) {
|
|
29
|
+
if (this.uis.has(ui.name)) {
|
|
30
|
+
throw new Error(`UI "${ui.name}" \u5DF2\u6CE8\u518C`);
|
|
31
|
+
}
|
|
32
|
+
this.uis.set(ui.name, ui);
|
|
33
|
+
this.ctx.emit("ui-registry/register", ui);
|
|
34
|
+
}
|
|
35
|
+
get(name3) {
|
|
36
|
+
return this.uis.get(name3);
|
|
37
|
+
}
|
|
38
|
+
list() {
|
|
39
|
+
return [...this.uis.values()];
|
|
40
|
+
}
|
|
41
|
+
listRoutes() {
|
|
42
|
+
return this.list().flatMap((ui) => ui.routes);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var name = "ui-registry";
|
|
46
|
+
var inject = [];
|
|
47
|
+
function apply(ctx) {
|
|
48
|
+
ctx.use(UiRegistryService);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ../layout-registry/dist/client/index.js
|
|
52
|
+
var client_exports2 = {};
|
|
53
|
+
__export(client_exports2, {
|
|
54
|
+
LayoutRegistryService: () => LayoutRegistryService,
|
|
55
|
+
LayoutShell: () => LayoutShell,
|
|
56
|
+
apply: () => apply2,
|
|
57
|
+
inject: () => inject2,
|
|
58
|
+
name: () => name2
|
|
59
|
+
});
|
|
60
|
+
import { Service as Service2 } from "cordis";
|
|
61
|
+
|
|
62
|
+
// ../layout-registry/dist/client/shell.js
|
|
63
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
64
|
+
import { useSearchParams } from "react-router";
|
|
65
|
+
function slotKey(item) {
|
|
66
|
+
return item.path ?? item.label;
|
|
67
|
+
}
|
|
68
|
+
function groupSlots(items) {
|
|
69
|
+
const groups = /* @__PURE__ */ new Map();
|
|
70
|
+
for (const item of items) {
|
|
71
|
+
const group = item.group ?? "";
|
|
72
|
+
groups.set(group, [...groups.get(group) ?? [], item]);
|
|
73
|
+
}
|
|
74
|
+
return [...groups.entries()].map(([group, list]) => ({ group, items: list }));
|
|
75
|
+
}
|
|
76
|
+
function LayoutShell({ ctx, scope, title, subtitle }) {
|
|
77
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
78
|
+
const items = ctx.layoutRegistry.slots(scope);
|
|
79
|
+
const active = items.find((item) => slotKey(item) === searchParams.get("tab")) ?? items[0];
|
|
80
|
+
if (active == null) {
|
|
81
|
+
return _jsxs("div", { style: { display: "flex", minHeight: "100vh" }, children: [_jsxs("nav", { style: { width: 220, borderRight: "1px solid #e5e5e5", padding: "12px 16px" }, children: [_jsx("h2", { style: { margin: 0 }, children: title }), subtitle ? _jsx("p", { style: { color: "#777" }, children: subtitle }) : null, _jsx("p", { style: { color: "#999" }, children: "\u6682\u65E0\u83DC\u5355\u9879" })] }), _jsx("main", { style: { flex: 1, padding: "12px 16px" }, children: "\u6682\u65E0\u5185\u5BB9" })] });
|
|
82
|
+
}
|
|
83
|
+
const ActiveComponent = active.component;
|
|
84
|
+
return _jsxs("div", { style: { display: "flex", minHeight: "100vh" }, children: [_jsxs("nav", { style: { width: 220, borderRight: "1px solid #e5e5e5", padding: "12px 16px" }, children: [_jsx("h2", { style: { margin: 0 }, children: title }), subtitle ? _jsx("p", { style: { color: "#777" }, children: subtitle }) : null, groupSlots(items).map(({ group, items: list }) => _jsxs("div", { children: [group ? _jsx("h3", { style: { color: "#999" }, children: group }) : null, _jsx("ul", { style: { listStyle: "none", padding: 0, margin: 0 }, children: list.map((item) => {
|
|
85
|
+
const key = slotKey(item);
|
|
86
|
+
const selected = slotKey(active) === key;
|
|
87
|
+
return _jsx("li", { children: _jsx("button", { type: "button", onClick: () => setSearchParams({ tab: key }), style: { fontWeight: selected ? 700 : 400 }, children: item.label }) }, key);
|
|
88
|
+
}) })] }, group || "__default"))] }), _jsx("main", { style: { flex: 1, padding: "12px 16px" }, children: _jsx(ActiveComponent, {}) })] });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ../layout-registry/dist/client/index.js
|
|
92
|
+
var LayoutRegistryService = class extends Service2 {
|
|
93
|
+
slotMap = /* @__PURE__ */ new Map();
|
|
94
|
+
constructor(ctx) {
|
|
95
|
+
super(ctx, "layoutRegistry");
|
|
96
|
+
}
|
|
97
|
+
/** 注册插槽;同一 scope 内 path(缺省 label)重复时抛错 */
|
|
98
|
+
registerSlot(scope, slot) {
|
|
99
|
+
const list = this.slotMap.get(scope) ?? [];
|
|
100
|
+
const key = slot.path ?? slot.label;
|
|
101
|
+
if (list.some((item) => (item.path ?? item.label) === key)) {
|
|
102
|
+
throw new Error(`\u5E03\u5C40 "${scope}" \u4E2D\u5DF2\u5B58\u5728\u83DC\u5355 "${key}"`);
|
|
103
|
+
}
|
|
104
|
+
list.push(slot);
|
|
105
|
+
this.slotMap.set(scope, list);
|
|
106
|
+
this.ctx.emit("layout-registry/register", scope, slot);
|
|
107
|
+
}
|
|
108
|
+
/** 读取某布局的全部插槽(按 order 升序,未指定 order 视为靠后,其次注册顺序) */
|
|
109
|
+
slots(scope) {
|
|
110
|
+
const list = this.slotMap.get(scope);
|
|
111
|
+
if (!list)
|
|
112
|
+
return [];
|
|
113
|
+
return list.map((slot, index) => ({ slot, index, order: slot.order ?? Number.MAX_SAFE_INTEGER })).sort((a, b) => a.order - b.order || a.index - b.index).map(({ slot }) => slot);
|
|
114
|
+
}
|
|
115
|
+
/** 已注册过插槽的布局 scope 列表 */
|
|
116
|
+
scopes() {
|
|
117
|
+
return [...this.slotMap.keys()];
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var name2 = "layout-registry";
|
|
121
|
+
var inject2 = [];
|
|
122
|
+
function apply2(ctx) {
|
|
123
|
+
ctx.use(LayoutRegistryService);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ../ui-runtime/dist/client/index.js
|
|
127
|
+
import { createContext, createElement, useContext } from "react";
|
|
128
|
+
import { createRoot } from "react-dom/client";
|
|
129
|
+
import { BrowserRouter, Route, Routes } from "react-router";
|
|
130
|
+
import { Provider as JotaiProvider, createStore } from "jotai";
|
|
131
|
+
import { Context, Service as Service3 } from "cordis";
|
|
132
|
+
async function loadClientManifest(url) {
|
|
133
|
+
const response = await fetch(url);
|
|
134
|
+
if (!response.ok)
|
|
135
|
+
throw new Error(`\u52A0\u8F7D UI manifest \u5931\u8D25\uFF08${response.status}\uFF09\uFF1A${url}`);
|
|
136
|
+
const manifest = await response.json();
|
|
137
|
+
const entries = [];
|
|
138
|
+
for (const plugin of manifest.plugins) {
|
|
139
|
+
const entry = await import(
|
|
140
|
+
/* @vite-ignore */
|
|
141
|
+
plugin.url
|
|
142
|
+
);
|
|
143
|
+
entries.push(entry);
|
|
144
|
+
}
|
|
145
|
+
return entries;
|
|
146
|
+
}
|
|
147
|
+
var globalScope = globalThis;
|
|
148
|
+
var CordisContext = globalScope.__cordisWebCordisContext ?? createContext(void 0);
|
|
149
|
+
if (!globalScope.__cordisWebCordisContext) {
|
|
150
|
+
globalScope.__cordisWebCordisContext = CordisContext;
|
|
151
|
+
}
|
|
152
|
+
var UiRuntimeService = class extends Service3 {
|
|
153
|
+
static inject = ["uiRegistry"];
|
|
154
|
+
store = createStore();
|
|
155
|
+
constructor(ctx) {
|
|
156
|
+
super(ctx, "uiRuntime");
|
|
157
|
+
}
|
|
158
|
+
register(ui) {
|
|
159
|
+
this.ctx.uiRegistry.register(ui);
|
|
160
|
+
}
|
|
161
|
+
list() {
|
|
162
|
+
return this.ctx.uiRegistry.list();
|
|
163
|
+
}
|
|
164
|
+
routes() {
|
|
165
|
+
return this.ctx.uiRegistry.listRoutes();
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// src/shared/index.ts
|
|
170
|
+
import { createContext as createContext2, createElement as createElement2, useContext as useContext2 } from "react";
|
|
171
|
+
import { matchRoutes, useLocation } from "react-router";
|
|
172
|
+
var SSR_STATE_KEY = "__CORDIS_WEB_SSR_STATE__";
|
|
173
|
+
function readSsrState() {
|
|
174
|
+
if (typeof window === "undefined") return null;
|
|
175
|
+
const raw = window[SSR_STATE_KEY];
|
|
176
|
+
if (!raw || typeof raw !== "object") return null;
|
|
177
|
+
const state = raw;
|
|
178
|
+
if (state.rendered !== true || !state.data || typeof state.data !== "object") return null;
|
|
179
|
+
return { rendered: true, data: state.data };
|
|
180
|
+
}
|
|
181
|
+
var globalScope2 = globalThis;
|
|
182
|
+
function sharedContext(key, initial) {
|
|
183
|
+
const existing = globalScope2[key];
|
|
184
|
+
if (existing) return existing;
|
|
185
|
+
const created = createContext2(initial);
|
|
186
|
+
globalScope2[key] = created;
|
|
187
|
+
return created;
|
|
188
|
+
}
|
|
189
|
+
var SsrDataContext = sharedContext("__cordisWebSsrDataContext", null);
|
|
190
|
+
var SsrRoutesContext = sharedContext("__cordisWebSsrRoutesContext", []);
|
|
191
|
+
function normalizePath(path) {
|
|
192
|
+
return path.startsWith("/") ? path : `/${path}`;
|
|
193
|
+
}
|
|
194
|
+
function flattenRoutes(routes, parent = "") {
|
|
195
|
+
const nodes = [];
|
|
196
|
+
for (const route of routes) {
|
|
197
|
+
const path = normalizePath(parent ? `${parent}${route.path}` : route.path);
|
|
198
|
+
const loader = route.loader ? (args) => route.loader({ params: args.params, request: args.request }) : void 0;
|
|
199
|
+
nodes.push({ path, element: createElement2(route.component), loader, ssr: route.ssr });
|
|
200
|
+
if (route.children?.length) {
|
|
201
|
+
nodes.push(...flattenRoutes(route.children, path));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return nodes;
|
|
205
|
+
}
|
|
206
|
+
function SsrDataProvider({ state, routes, children }) {
|
|
207
|
+
return createElement2(
|
|
208
|
+
SsrRoutesContext.Provider,
|
|
209
|
+
{ value: routes },
|
|
210
|
+
createElement2(SsrDataContext.Provider, { value: state }, children)
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/client/index.tsx
|
|
215
|
+
function buildTree(state, routes, ctx, useBrowserRouter) {
|
|
216
|
+
const routesNode = createElement3(
|
|
217
|
+
Routes2,
|
|
218
|
+
null,
|
|
219
|
+
routes.map(
|
|
220
|
+
(route) => createElement3(Route2, { key: route.path, path: route.path, element: route.element })
|
|
221
|
+
)
|
|
222
|
+
);
|
|
223
|
+
return createElement3(
|
|
224
|
+
CordisContext.Provider,
|
|
225
|
+
{ value: ctx },
|
|
226
|
+
useBrowserRouter ? createElement3(
|
|
227
|
+
BrowserRouter2,
|
|
228
|
+
null,
|
|
229
|
+
createElement3(
|
|
230
|
+
SsrDataProvider,
|
|
231
|
+
{ state, routes },
|
|
232
|
+
createElement3(JotaiProvider2, { store: ctx.uiRuntime.store }, routesNode)
|
|
233
|
+
)
|
|
234
|
+
) : createElement3(
|
|
235
|
+
SsrDataProvider,
|
|
236
|
+
{ state, routes },
|
|
237
|
+
createElement3(JotaiProvider2, { store: ctx.uiRuntime.store }, routesNode)
|
|
238
|
+
)
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
async function hydrateBootstrap(options = {}) {
|
|
242
|
+
const { container = document.getElementById("root") ?? document.body } = options;
|
|
243
|
+
const ctx = new Context2();
|
|
244
|
+
await ctx.use(client_exports);
|
|
245
|
+
await ctx.use(client_exports2);
|
|
246
|
+
await ctx.use(UiRuntimeService);
|
|
247
|
+
if (options.plugins?.length) {
|
|
248
|
+
for (const entry of options.plugins) {
|
|
249
|
+
await ctx.use(entry);
|
|
250
|
+
}
|
|
251
|
+
} else {
|
|
252
|
+
const entries = await loadClientManifest(options.manifestUrl ?? "/ui-runtime/manifest.json");
|
|
253
|
+
for (const entry of entries) {
|
|
254
|
+
await ctx.use(entry);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const state = readSsrState();
|
|
258
|
+
const routes = flattenRoutes(ctx.uiRegistry.listRoutes());
|
|
259
|
+
const tree = buildTree(state ?? { rendered: false, data: {} }, routes, ctx, true);
|
|
260
|
+
if (state) {
|
|
261
|
+
hydrateRoot(container, tree);
|
|
262
|
+
} else {
|
|
263
|
+
createRoot2(container).render(tree);
|
|
264
|
+
}
|
|
265
|
+
return ctx;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// src/client/entry.ts
|
|
269
|
+
hydrateBootstrap().catch((error) => {
|
|
270
|
+
console.error("[ui-runtime-ssr] bootstrap failed:", error);
|
|
271
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/client/entry.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../src/client/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,sCAAsC;AACtC,gBAAgB,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACjC,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAA;AAC5D,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Context } from 'cordis';
|
|
2
|
+
import { useCordisContext, type ClientEntry } from '@cordis-web/plugin-ui-runtime/client';
|
|
3
|
+
export { useCordisContext };
|
|
4
|
+
export { useLoaderData } from '../shared/index.js';
|
|
5
|
+
export interface UiRuntimeSsrBootstrapOptions {
|
|
6
|
+
/**
|
|
7
|
+
* 挂载点。默认优先使用 `#root`(SSR 模板注入的 React 容器),
|
|
8
|
+
* 其次 document.body。
|
|
9
|
+
* 注意:水合容器必须只包含服务端渲染的 React 内容——
|
|
10
|
+
* 若传 document.body,模板注入的 state/runtime script(均为非 React 节点)
|
|
11
|
+
* 会被 React 视为水合不匹配并回退客户端渲染。
|
|
12
|
+
*/
|
|
13
|
+
container?: HTMLElement;
|
|
14
|
+
/** 需要加载的业务插件 client 入口(静态集成时使用) */
|
|
15
|
+
plugins?: ClientEntry[];
|
|
16
|
+
/**
|
|
17
|
+
* 运行时集成:从服务端 manifest 动态加载业务插件 client bundle。
|
|
18
|
+
* 未传 plugins 时生效,默认 /ui-runtime/manifest.json
|
|
19
|
+
*/
|
|
20
|
+
manifestUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* SSR 水合入口:创建前端 cordis 实例、加载插件 client 入口后,
|
|
24
|
+
* 服务器已渲染(window.__CORDIS_WEB_SSR_STATE__)→ hydrateRoot;
|
|
25
|
+
* 否则(SPA 空壳)→ createRoot 纯客户端渲染。
|
|
26
|
+
*/
|
|
27
|
+
export declare function hydrateBootstrap(options?: UiRuntimeSsrBootstrapOptions): Promise<Context>;
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAGhC,OAAO,EAIL,gBAAgB,EAChB,KAAK,WAAW,EACjB,MAAM,sCAAsC,CAAA;AAQ7C,OAAO,EAAE,gBAAgB,EAAE,CAAA;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,MAAM,WAAW,4BAA4B;IAC3C;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,mCAAmC;IACnC,OAAO,CAAC,EAAE,WAAW,EAAE,CAAA;IACvB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAgCD;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,OAAO,CAAC,CAmClB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { hydrateRoot, createRoot } from 'react-dom/client';
|
|
3
|
+
import { BrowserRouter, Route, Routes } from 'react-router';
|
|
4
|
+
import { Provider as JotaiProvider } from 'jotai';
|
|
5
|
+
import { Context } from 'cordis';
|
|
6
|
+
import * as UiRegistryPlugin from '@cordis-web/plugin-ui-registry/client';
|
|
7
|
+
import * as LayoutRegistryPlugin from '@cordis-web/plugin-layout-registry/client';
|
|
8
|
+
import { CordisContext, UiRuntimeService, loadClientManifest, useCordisContext, } from '@cordis-web/plugin-ui-runtime/client';
|
|
9
|
+
import { flattenRoutes, readSsrState, SsrDataProvider, } from '../shared/index.js';
|
|
10
|
+
export { useCordisContext };
|
|
11
|
+
export { useLoaderData } from '../shared/index.js';
|
|
12
|
+
/** 构建与 UI 树(服务端渲染与服务端渲染同构:StaticRouter ↔ BrowserRouter) */
|
|
13
|
+
function buildTree(state, routes, ctx, useBrowserRouter) {
|
|
14
|
+
const routesNode = createElement(Routes, null, routes.map((route) => createElement(Route, { key: route.path, path: route.path, element: route.element })));
|
|
15
|
+
return createElement(CordisContext.Provider, { value: ctx }, useBrowserRouter
|
|
16
|
+
? createElement(BrowserRouter, null, createElement(SsrDataProvider, { state, routes }, createElement(JotaiProvider, { store: ctx.uiRuntime.store }, routesNode)))
|
|
17
|
+
: createElement(SsrDataProvider, { state, routes }, createElement(JotaiProvider, { store: ctx.uiRuntime.store }, routesNode)));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* SSR 水合入口:创建前端 cordis 实例、加载插件 client 入口后,
|
|
21
|
+
* 服务器已渲染(window.__CORDIS_WEB_SSR_STATE__)→ hydrateRoot;
|
|
22
|
+
* 否则(SPA 空壳)→ createRoot 纯客户端渲染。
|
|
23
|
+
*/
|
|
24
|
+
export async function hydrateBootstrap(options = {}) {
|
|
25
|
+
const { container = document.getElementById('root') ?? document.body } = options;
|
|
26
|
+
const ctx = new Context();
|
|
27
|
+
await ctx.use(UiRegistryPlugin);
|
|
28
|
+
await ctx.use(LayoutRegistryPlugin);
|
|
29
|
+
await ctx.use(UiRuntimeService);
|
|
30
|
+
if (options.plugins?.length) {
|
|
31
|
+
for (const entry of options.plugins) {
|
|
32
|
+
await ctx.use(entry);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// 运行时集成:从 manifest 拉取插件 client bundle
|
|
37
|
+
const entries = await loadClientManifest(options.manifestUrl ?? '/ui-runtime/manifest.json');
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
await ctx.use(entry);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const state = readSsrState();
|
|
43
|
+
// 始终保留完整路由表:
|
|
44
|
+
// 水合期的 SSR 数据路由不需要剥离 ssr:false 路由;而剥离后(原实现)会在水合完成后
|
|
45
|
+
//把静态路由(/news/new、/news/mine)从路由表移除,后续客户端导航到这些路径时会被
|
|
46
|
+
// 同前缀的动态路由(/news/:id)错误接管。当前 pathname 的命中链不含 ssr:false 路由
|
|
47
|
+
//(否则服务端不会 SSR 下发状态),因此保留完整路由表不影响水合同构。
|
|
48
|
+
const routes = flattenRoutes(ctx.uiRegistry.listRoutes());
|
|
49
|
+
const tree = buildTree(state ?? { rendered: false, data: {} }, routes, ctx, true);
|
|
50
|
+
if (state) {
|
|
51
|
+
hydrateRoot(container, tree);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
createRoot(container).render(tree);
|
|
55
|
+
}
|
|
56
|
+
return ctx;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE3D,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,OAAO,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAChC,OAAO,KAAK,gBAAgB,MAAM,uCAAuC,CAAA;AACzE,OAAO,KAAK,oBAAoB,MAAM,2CAA2C,CAAA;AACjF,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EACL,aAAa,EACb,YAAY,EACZ,eAAe,GAEhB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,gBAAgB,EAAE,CAAA;AAC3B,O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js),默认包内 dist/browser */
|
|
4
|
+
dir?: string;
|
|
5
|
+
/** 本包运行时下发前缀,默认 /ui-runtime-ssr */
|
|
6
|
+
prefix?: string;
|
|
7
|
+
/** vendor import map 前缀(构建期写入 index.html),默认复用 ui-runtime 的 /ui-runtime/vendor */
|
|
8
|
+
vendorBase?: string;
|
|
9
|
+
/** 是否启用 SSR(false 时所有页面返回 SPA 空壳,由客户端纯 CSR),默认 true */
|
|
10
|
+
hydrate?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* UI 运行时 SSR(服务端):接管 HTML 导航请求,在 Node 端做服务端渲染。
|
|
14
|
+
*
|
|
15
|
+
* 渲染链:
|
|
16
|
+
* 1. 隐形加载各业务插件的 client bundle,构建「幽灵 client cordis 实例」(与浏览器端
|
|
17
|
+
* bootstrap 相同的加载顺序),收集完整 IUi 路由表;
|
|
18
|
+
* 2. 按 request URL 用 react-router 的 matchRoutes 匹配路由,并行执行匹配链上所有
|
|
19
|
+
* IUiRoute.loader,收集数据;
|
|
20
|
+
* 3. 以 StaticRouter + 每请求独立 jotai store 渲染页面,序列化数据注入 HTML;
|
|
21
|
+
* 4. HTML 中插入 runtime.js 的 module script,客户端 hydrateBootstrap 用同一份数据水合。
|
|
22
|
+
*
|
|
23
|
+
* 未匹配路由 / 路由标记 ssr:false / hydrate:false 时返回 SPA 空壳(客户端纯 CSR),
|
|
24
|
+
* 与未启用 SSR 时的行为一致。
|
|
25
|
+
*
|
|
26
|
+
* 注意:与 UiRuntimeServerService 同时加载时,需给后者配置 `spa: false`,
|
|
27
|
+
* 否则其 SPA 回退会先于本服务接管 `GET /`。
|
|
28
|
+
*/
|
|
29
|
+
export declare class UiRuntimeSsrService extends Service {
|
|
30
|
+
static inject: string[];
|
|
31
|
+
dir: string;
|
|
32
|
+
prefix: string;
|
|
33
|
+
vendorBase: string;
|
|
34
|
+
hydrate: boolean;
|
|
35
|
+
/** 插件 client bundle 自动发现结果(name -> 绝对路径) */
|
|
36
|
+
readonly clientBundles: Map<string, string>;
|
|
37
|
+
/** 幽灵 client cordis 实例(加载插件 client 入口,收集 IUi 路由) */
|
|
38
|
+
private phantom?;
|
|
39
|
+
private phantomReady?;
|
|
40
|
+
private template?;
|
|
41
|
+
constructor(ctx: Context, config?: UiRuntimeSsrConfig);
|
|
42
|
+
private isFile;
|
|
43
|
+
private serveRuntime;
|
|
44
|
+
/** 页面请求处理:SSR 渲染;未启用 / 无路由匹配 / 初始化失败时回退 SPA 空壳 */
|
|
45
|
+
private handleHtml;
|
|
46
|
+
/** SPA 空壳:未匹配路由 / ssr:false / hydrate:false 时下发,客户端走纯 CSR */
|
|
47
|
+
private shellResponse;
|
|
48
|
+
private htmlResponse;
|
|
49
|
+
private loadTemplate;
|
|
50
|
+
private ready;
|
|
51
|
+
/** 构建幽灵 client cordis 实例:加载各插件 client bundle(与浏览器端 bootstrap 对称) */
|
|
52
|
+
private createPhantom;
|
|
53
|
+
}
|
|
54
|
+
export declare const name = "ui-runtime-ssr";
|
|
55
|
+
export declare const inject: string[];
|
|
56
|
+
export declare function apply(ctx: Context, config?: UiRuntimeSsrConfig): void;
|
|
57
|
+
declare module 'cordis' {
|
|
58
|
+
interface Context {
|
|
59
|
+
uiRuntimeSsr: UiRuntimeSsrService;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAiBzC,MAAM,WAAW,kBAAkB;IACjC,+DAA+D;IAC/D,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,mCAAmC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,kFAAkF;IAClF,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,uDAAuD;IACvD,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AA4CD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,mBAAoB,SAAQ,OAAO;IAC9C,MAAM,CAAC,MAAM,WAAkB;IAE/B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;IAChB,4CAA4C;IAC5C,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3C,oDAAoD;IACpD,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,YAAY,CAAC,CAAkB;IACvC,OAAO,CAAC,QAAQ,CAAC,CAAQ;IAEzB,YAAY,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,kBAAuB,EAwCxD;IAED,OAAO,CAAC,MAAM;YAIA,YAAY;IAa1B,kDAAkD;YACpC,UAAU;IA4ExB,6DAA6D;IAC7D,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,KAAK;IAQb,oEAAoE;YACtD,aAAa;CAc5B;AAOD,eAAO,MAAM,IAAI,mBAAmB,CAAA;AACpC,eAAO,MAAM,MAAM,UAAkB,CAAA;AAErC,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,kBAAuB,QAElE;AAED,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,OAAO;QACf,YAAY,EAAE,mBAAmB,CAAA;KAClC;CACF"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
+
import { createElement } from 'react';
|
|
5
|
+
import { renderToString } from 'react-dom/server';
|
|
6
|
+
import { matchRoutes, Route, Routes, StaticRouter } from 'react-router';
|
|
7
|
+
import { createStore, Provider as JotaiProvider } from 'jotai';
|
|
8
|
+
import { Context, Service } from 'cordis';
|
|
9
|
+
// 幽灵 client 实例所需的 client 端服务(在 Node 环境加载,与浏览器端 bootstrap 对称)
|
|
10
|
+
import * as UiRegistryClient from '@cordis-web/plugin-ui-registry/client';
|
|
11
|
+
import * as LayoutRegistryClient from '@cordis-web/plugin-layout-registry/client';
|
|
12
|
+
import { CordisContext, UiRuntimeService } from '@cordis-web/plugin-ui-runtime/client';
|
|
13
|
+
// 复用 ui-runtime/server 的插件 client bundle 自动发现
|
|
14
|
+
import { discoverClientBundles } from '@cordis-web/plugin-ui-runtime/server';
|
|
15
|
+
import { SSR_STATE_KEY, filterSsrRoutes, flattenRoutes, SsrDataProvider, } from '../shared/index.js';
|
|
16
|
+
const packageRoot = fileURLToPath(new URL('../../', import.meta.url));
|
|
17
|
+
const DEFAULT_DIR = join(packageRoot, 'dist/browser');
|
|
18
|
+
/** index.html 模板占位符(与 scripts/build-browser.mjs 生成的模板一致) */
|
|
19
|
+
const ROOT_PLACEHOLDER = '<!--SSR_ROOT-->';
|
|
20
|
+
const STATE_PLACEHOLDER = 'null/*SSR_STATE*/';
|
|
21
|
+
const IMPORTMAP_ENTRIES = [
|
|
22
|
+
['react', 'react.js'],
|
|
23
|
+
['react/jsx-runtime', 'react.js'],
|
|
24
|
+
['react-dom/client', 'react-dom-client.js'],
|
|
25
|
+
['scheduler', 'scheduler.js'],
|
|
26
|
+
['react-router', 'react-router.js'],
|
|
27
|
+
['jotai', 'jotai.js'],
|
|
28
|
+
['jotai/utils', 'jotai.js'],
|
|
29
|
+
['cordis', 'cordis.js'],
|
|
30
|
+
];
|
|
31
|
+
/** 模板缺失时的兜底模板(仍含占位符,SSR 功能可用) */
|
|
32
|
+
function defaultTemplate(vendorBase, prefix) {
|
|
33
|
+
const imports = Object.fromEntries(IMPORTMAP_ENTRIES.map(([specifier, file]) => [specifier, `${vendorBase}/${file}`]));
|
|
34
|
+
return `<!doctype html>
|
|
35
|
+
<html lang="zh-CN">
|
|
36
|
+
<head>
|
|
37
|
+
<meta charset="utf-8" />
|
|
38
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
39
|
+
<title>cordis-web</title>
|
|
40
|
+
<script type="importmap">
|
|
41
|
+
${JSON.stringify({ imports }, null, 2)}
|
|
42
|
+
</script>
|
|
43
|
+
</head>
|
|
44
|
+
<body>
|
|
45
|
+
${ROOT_PLACEHOLDER}
|
|
46
|
+
<script>window.${SSR_STATE_KEY} = ${STATE_PLACEHOLDER};</script>
|
|
47
|
+
<script type="module" src="${prefix}/runtime.js"></script>
|
|
48
|
+
</body>
|
|
49
|
+
</html>
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* UI 运行时 SSR(服务端):接管 HTML 导航请求,在 Node 端做服务端渲染。
|
|
54
|
+
*
|
|
55
|
+
* 渲染链:
|
|
56
|
+
* 1. 隐形加载各业务插件的 client bundle,构建「幽灵 client cordis 实例」(与浏览器端
|
|
57
|
+
* bootstrap 相同的加载顺序),收集完整 IUi 路由表;
|
|
58
|
+
* 2. 按 request URL 用 react-router 的 matchRoutes 匹配路由,并行执行匹配链上所有
|
|
59
|
+
* IUiRoute.loader,收集数据;
|
|
60
|
+
* 3. 以 StaticRouter + 每请求独立 jotai store 渲染页面,序列化数据注入 HTML;
|
|
61
|
+
* 4. HTML 中插入 runtime.js 的 module script,客户端 hydrateBootstrap 用同一份数据水合。
|
|
62
|
+
*
|
|
63
|
+
* 未匹配路由 / 路由标记 ssr:false / hydrate:false 时返回 SPA 空壳(客户端纯 CSR),
|
|
64
|
+
* 与未启用 SSR 时的行为一致。
|
|
65
|
+
*
|
|
66
|
+
* 注意:与 UiRuntimeServerService 同时加载时,需给后者配置 `spa: false`,
|
|
67
|
+
* 否则其 SPA 回退会先于本服务接管 `GET /`。
|
|
68
|
+
*/
|
|
69
|
+
export class UiRuntimeSsrService extends Service {
|
|
70
|
+
static inject = ['apiRegistry'];
|
|
71
|
+
dir;
|
|
72
|
+
prefix;
|
|
73
|
+
vendorBase;
|
|
74
|
+
hydrate;
|
|
75
|
+
/** 插件 client bundle 自动发现结果(name -> 绝对路径) */
|
|
76
|
+
clientBundles;
|
|
77
|
+
/** 幽灵 client cordis 实例(加载插件 client 入口,收集 IUi 路由) */
|
|
78
|
+
phantom;
|
|
79
|
+
phantomReady;
|
|
80
|
+
template;
|
|
81
|
+
constructor(ctx, config = {}) {
|
|
82
|
+
super(ctx, 'uiRuntimeSsr');
|
|
83
|
+
this.dir = config.dir ? resolve(config.dir) : DEFAULT_DIR;
|
|
84
|
+
this.prefix = (config.prefix ?? '/ui-runtime-ssr').replace(/\/$/, '');
|
|
85
|
+
this.vendorBase = (config.vendorBase ?? '/ui-runtime/vendor').replace(/\/$/, '');
|
|
86
|
+
this.hydrate = config.hydrate ?? true;
|
|
87
|
+
this.clientBundles = discoverClientBundles((message) => ctx.logger.warn(message));
|
|
88
|
+
if (this.clientBundles.size === 0) {
|
|
89
|
+
ctx.logger.warn('[ui-runtime-ssr] 未发现任何插件 client bundle,页面将只有空壳');
|
|
90
|
+
}
|
|
91
|
+
const register = (api) => ctx.apiRegistry.register(api);
|
|
92
|
+
register({
|
|
93
|
+
name: 'ui-runtime-ssr/runtime',
|
|
94
|
+
method: 'GET',
|
|
95
|
+
path: `${this.prefix}/runtime.js`,
|
|
96
|
+
description: 'ui-runtime-ssr 水合运行时(浏览器端)',
|
|
97
|
+
handle: async (c) => this.serveRuntime(c),
|
|
98
|
+
});
|
|
99
|
+
register({
|
|
100
|
+
name: 'ui-runtime-ssr/index',
|
|
101
|
+
method: 'GET',
|
|
102
|
+
path: '/',
|
|
103
|
+
description: '页面入口(SSR 渲染,未匹配路由回退 SPA 空壳)',
|
|
104
|
+
handle: async (c) => this.handleHtml(c),
|
|
105
|
+
});
|
|
106
|
+
register({
|
|
107
|
+
name: 'ui-runtime-ssr/spa-fallback',
|
|
108
|
+
method: 'GET',
|
|
109
|
+
path: '*',
|
|
110
|
+
description: 'HTML 导航回退(SSR 渲染,非 HTML 请求 notFound)',
|
|
111
|
+
handle: async (c) => {
|
|
112
|
+
const accept = c.req.header('accept') ?? '';
|
|
113
|
+
if (!accept.includes('text/html'))
|
|
114
|
+
return c.notFound();
|
|
115
|
+
return this.handleHtml(c);
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
ctx.logger.info(`[ui-runtime-ssr] 已启用(prefix=${this.prefix})`);
|
|
119
|
+
}
|
|
120
|
+
isFile(full) {
|
|
121
|
+
return existsSync(full) && statSync(full).isFile();
|
|
122
|
+
}
|
|
123
|
+
async serveRuntime(c) {
|
|
124
|
+
const full = join(this.dir, 'runtime.js');
|
|
125
|
+
if (!this.isFile(full)) {
|
|
126
|
+
return c.json({ error: `runtime.js 不存在:${full},请先执行 npm run build:client -w @cordis-web/plugin-ui-runtime-ssr` }, 404);
|
|
127
|
+
}
|
|
128
|
+
return new Response(readFileSync(full), {
|
|
129
|
+
headers: { 'content-type': 'text/javascript; charset=utf-8', 'cache-control': 'no-cache' },
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/** 页面请求处理:SSR 渲染;未启用 / 无路由匹配 / 初始化失败时回退 SPA 空壳 */
|
|
133
|
+
async handleHtml(c) {
|
|
134
|
+
if (!this.hydrate)
|
|
135
|
+
return this.shellResponse();
|
|
136
|
+
let phantom;
|
|
137
|
+
try {
|
|
138
|
+
phantom = await this.ready();
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
this.ctx.logger.error('[ui-runtime-ssr] 幽灵 client 实例初始化失败,回退 SPA 空壳', error);
|
|
142
|
+
return this.shellResponse();
|
|
143
|
+
}
|
|
144
|
+
const url = new URL(c.req.url);
|
|
145
|
+
// 匹配基于「未过滤」路由表:ssr:false 路由被过滤后,同前缀的动态路由
|
|
146
|
+
// (如 /news/:id)会错误接管其 URL,因此需先按完整路由表匹配再判断标记
|
|
147
|
+
const allRoutes = flattenRoutes(phantom.uiRegistry.listRoutes());
|
|
148
|
+
if (allRoutes.length === 0)
|
|
149
|
+
return this.shellResponse();
|
|
150
|
+
const matches = matchRoutes(allRoutes, url.pathname);
|
|
151
|
+
if (!matches?.length)
|
|
152
|
+
return this.shellResponse();
|
|
153
|
+
// 命中链上存在 ssr:false 路由:该 URL 交由客户端渲染,返回 SPA 空壳
|
|
154
|
+
if (matches.some((match) => match.route.ssr === false)) {
|
|
155
|
+
return this.shellResponse();
|
|
156
|
+
}
|
|
157
|
+
const routes = flattenRoutes(filterSsrRoutes(phantom.uiRegistry.listRoutes()));
|
|
158
|
+
if (routes.length === 0)
|
|
159
|
+
return this.shellResponse();
|
|
160
|
+
// 并行执行匹配链上各路由的 loader(react-router loader 语义)
|
|
161
|
+
const request = c.req.raw;
|
|
162
|
+
const data = {};
|
|
163
|
+
await Promise.all(matches.map(async (match) => {
|
|
164
|
+
const loader = match.route.loader;
|
|
165
|
+
if (!loader)
|
|
166
|
+
return;
|
|
167
|
+
const key = match.route.path ?? '';
|
|
168
|
+
try {
|
|
169
|
+
data[key] = await loader({ params: match.params, request });
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
// loader 失败不阻断渲染:该路由页面拿到 undefined,由页面自行降级
|
|
173
|
+
this.ctx.logger.error(`[ui-runtime-ssr] loader 失败(${key})`, error);
|
|
174
|
+
data[key] = undefined;
|
|
175
|
+
}
|
|
176
|
+
}));
|
|
177
|
+
const state = { rendered: true, data };
|
|
178
|
+
const app = ctxWrap(phantom, createElement(StaticRouter, { location: { pathname: url.pathname, search: url.search, hash: url.hash } }, createElement(SsrDataProvider, { state, routes }, createElement(JotaiProvider,
|
|
179
|
+
// 每请求独立 store,避免并发渲染共享可变状态
|
|
180
|
+
{ store: createStore() }, createElement(Routes, null, routes.map((route) => createElement(Route, {
|
|
181
|
+
key: route.path,
|
|
182
|
+
path: route.path,
|
|
183
|
+
element: route.element,
|
|
184
|
+
})))))));
|
|
185
|
+
return this.htmlResponse(`<div id="root">${renderToString(app)}</div>`, state);
|
|
186
|
+
}
|
|
187
|
+
/** SPA 空壳:未匹配路由 / ssr:false / hydrate:false 时下发,客户端走纯 CSR */
|
|
188
|
+
shellResponse() {
|
|
189
|
+
return this.htmlResponse('<div id="root"></div>', null);
|
|
190
|
+
}
|
|
191
|
+
htmlResponse(rootMarkup, state) {
|
|
192
|
+
const template = this.loadTemplate();
|
|
193
|
+
// </script> 转义,避免序列化数据破坏 script 标签
|
|
194
|
+
const stateJson = JSON.stringify(state).replace(/</g, '\\u003c');
|
|
195
|
+
const html = template
|
|
196
|
+
.replace(ROOT_PLACEHOLDER, rootMarkup)
|
|
197
|
+
.replace(STATE_PLACEHOLDER, stateJson);
|
|
198
|
+
return new Response(html, {
|
|
199
|
+
headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-cache' },
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
loadTemplate() {
|
|
203
|
+
if (this.template)
|
|
204
|
+
return this.template;
|
|
205
|
+
const full = join(this.dir, 'index.html');
|
|
206
|
+
if (this.isFile(full)) {
|
|
207
|
+
this.template = readFileSync(full, 'utf8');
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
this.ctx.logger.warn(`[ui-runtime-ssr] 缺少 ${full},使用内置模板(请先执行 build:client)`);
|
|
211
|
+
this.template = defaultTemplate(this.vendorBase, this.prefix);
|
|
212
|
+
}
|
|
213
|
+
return this.template;
|
|
214
|
+
}
|
|
215
|
+
ready() {
|
|
216
|
+
this.phantomReady ??= this.createPhantom().catch((error) => {
|
|
217
|
+
this.phantomReady = undefined;
|
|
218
|
+
throw error;
|
|
219
|
+
});
|
|
220
|
+
return this.phantomReady;
|
|
221
|
+
}
|
|
222
|
+
/** 构建幽灵 client cordis 实例:加载各插件 client bundle(与浏览器端 bootstrap 对称) */
|
|
223
|
+
async createPhantom() {
|
|
224
|
+
const phantom = new Context();
|
|
225
|
+
await phantom.use(UiRegistryClient);
|
|
226
|
+
await phantom.use(LayoutRegistryClient);
|
|
227
|
+
await phantom.use(UiRuntimeService);
|
|
228
|
+
for (const bundle of this.clientBundles.values()) {
|
|
229
|
+
const entry = (await import(pathToFileURL(bundle).href));
|
|
230
|
+
await phantom.use(entry);
|
|
231
|
+
}
|
|
232
|
+
this.phantom = phantom;
|
|
233
|
+
return phantom;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/** 用幽灵 client 实例提供 CordisContext(页面组件可通过 useCordisContext 访问注册表) */
|
|
237
|
+
function ctxWrap(phantom, children) {
|
|
238
|
+
return createElement(CordisContext.Provider, { value: phantom }, children);
|
|
239
|
+
}
|
|
240
|
+
export const name = 'ui-runtime-ssr';
|
|
241
|
+
export const inject = ['apiRegistry'];
|
|
242
|
+
export function apply(ctx, config = {}) {
|
|
243
|
+
ctx.use(UiRuntimeSsrService, config);
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC5D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAEvD,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAEvE,OAAO,EAAE,WAAW,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,OAAO,CAAA;AAC9D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAGzC,6DAA6D;AAC7D,OAAO,KAAK,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,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;QACnC,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC;YACjD,MAAM,KAAK,GAAG,CAAC,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAEtD,CAAA;YACD,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AAED,oEAAoE;AACpE,SAAS,OAAO,CAAC,OAAgB,EAAE,QAAmB;IACpD,OAAO,aAAa,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAA;AAC5E,CAAC;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,gBAAgB,CAAA;AACpC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,aAAa,CAAC,CAAA;AAErC,MAAM,UAAU,KAAK,CAAC,GAAY,EAAE,MAAM,GAAuB,EAAE;IACjE,GAAG,CAAC,GAAG,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAA;AACtC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Context, ReactNode } from 'react';
|
|
2
|
+
import type { RouteObject } from 'react-router';
|
|
3
|
+
import type { IUiRoute } from '@cordis-web/plugin-ui-registry/shared';
|
|
4
|
+
/** 挂在 window 上的 SSR 状态键(ui-runtime-ssr 注入) */
|
|
5
|
+
export declare const SSR_STATE_KEY = "__CORDIS_WEB_SSR_STATE__";
|
|
6
|
+
/** SSR 注入的状态:是否渲染 + 各路由 loader 结果 */
|
|
7
|
+
export interface SsrState {
|
|
8
|
+
/** 是否由 SSR 渲染(false 表示 SPA 空壳,客户端走纯 CSR) */
|
|
9
|
+
rendered: boolean;
|
|
10
|
+
/** loader 结果:key 为展平后的完整路由 path */
|
|
11
|
+
data: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
/** 读取 window 上的 SSR 状态;非 SSR 页面(SPA 空壳)返回 null */
|
|
14
|
+
export declare function readSsrState(): SsrState | null;
|
|
15
|
+
export declare const SsrDataContext: Context<SsrState | null>;
|
|
16
|
+
export declare const SsrRoutesContext: Context<RouteObject[]>;
|
|
17
|
+
/** 过滤 ssr:false 的路由(递归处理子路由) */
|
|
18
|
+
export declare function filterSsrRoutes(routes: IUiRoute[]): IUiRoute[];
|
|
19
|
+
/**
|
|
20
|
+
* IUiRoute[] → 展平的 react-router RouteObject[](与 ui-runtime client 的 renderRoutes
|
|
21
|
+
* 相同的父路径拼接规则)。loader 透传给 react-router 语义实参。
|
|
22
|
+
*/
|
|
23
|
+
export declare function flattenRoutes(routes: IUiRoute[], parent?: string): RouteObject[];
|
|
24
|
+
export interface SsrDataProviderProps {
|
|
25
|
+
state: SsrState;
|
|
26
|
+
routes: RouteObject[];
|
|
27
|
+
children?: ReactNode;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* SSR 数据 Provider:服务端渲染(StaticRouter)与客户端水合(BrowserRouter)
|
|
31
|
+
* 使用同一构造,保证两端 useLoaderData 结果一致。
|
|
32
|
+
*/
|
|
33
|
+
export declare function SsrDataProvider({ state, routes, children }: SsrDataProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<RouteObject[]>>;
|
|
34
|
+
/**
|
|
35
|
+
* 读取当前 URL 匹配路由的 SSR loader 数据(react-router useLoaderData 语义)。
|
|
36
|
+
* 需在 Router(StaticRouter / BrowserRouter)上下文中使用;
|
|
37
|
+
* SPA 空壳(未 SSR)或该路由未定义 loader 时返回 undefined。
|
|
38
|
+
*/
|
|
39
|
+
export declare function useLoaderData<T = unknown>(): T | undefined;
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAE/C,OAAO,KAAK,EAAsB,WAAW,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAA;AAErE,8CAA8C;AAC9C,eAAO,MAAM,aAAa,6BAA6B,CAAA;AAEvD,qCAAqC;AACrC,MAAM,WAAW,QAAQ;IACvB,4CAA4C;IAC5C,QAAQ,EAAE,OAAO,CAAA;IACjB,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B;AAED,kDAAkD;AAClD,wBAAgB,YAAY,IAAI,QAAQ,GAAG,IAAI,CAO9C;AAkBD,eAAO,MAAM,cAAc,0BAAoE,CAAA;AAC/F,eAAO,MAAM,gBAAgB,wBAAkE,CAAA;AAO/F,gCAAgC;AAChC,wBAAgB,eAAe,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAM9D;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,SAAK,GAAG,WAAW,EAAE,CAe5E;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,QAAQ,CAAA;IACf,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,oBAAoB,0FAMhF;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,GAAG,OAAO,KAAK,CAAC,GAAG,SAAS,CAS1D"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createContext, createElement, useContext } from 'react';
|
|
2
|
+
import { matchRoutes, useLocation } from 'react-router';
|
|
3
|
+
/** 挂在 window 上的 SSR 状态键(ui-runtime-ssr 注入) */
|
|
4
|
+
export const SSR_STATE_KEY = '__CORDIS_WEB_SSR_STATE__';
|
|
5
|
+
/** 读取 window 上的 SSR 状态;非 SSR 页面(SPA 空壳)返回 null */
|
|
6
|
+
export function readSsrState() {
|
|
7
|
+
if (typeof window === 'undefined')
|
|
8
|
+
return null;
|
|
9
|
+
const raw = window[SSR_STATE_KEY];
|
|
10
|
+
if (!raw || typeof raw !== 'object')
|
|
11
|
+
return null;
|
|
12
|
+
const state = raw;
|
|
13
|
+
if (state.rendered !== true || !state.data || typeof state.data !== 'object')
|
|
14
|
+
return null;
|
|
15
|
+
return { rendered: true, data: state.data };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 全局共享的 React Context 单例:
|
|
19
|
+
* 插件 client bundle 会把本模块代码内联进各自 bundle,不同副本的 createContext()
|
|
20
|
+
* 互不相等会导致 Provider/useContext 失效,因此统一挂到 globalThis 上,
|
|
21
|
+
* 保证任意 bundle(uid-runtime-ssr runtime / 插件 bundle 内联副本)拿到同一对象。
|
|
22
|
+
*/
|
|
23
|
+
const globalScope = globalThis;
|
|
24
|
+
function sharedContext(key, initial) {
|
|
25
|
+
const existing = globalScope[key];
|
|
26
|
+
if (existing)
|
|
27
|
+
return existing;
|
|
28
|
+
const created = createContext(initial);
|
|
29
|
+
globalScope[key] = created;
|
|
30
|
+
return created;
|
|
31
|
+
}
|
|
32
|
+
export const SsrDataContext = sharedContext('__cordisWebSsrDataContext', null);
|
|
33
|
+
export const SsrRoutesContext = sharedContext('__cordisWebSsrRoutesContext', []);
|
|
34
|
+
/** 路径归一化,保证以 / 开头(与 ui-runtime client 规则一致) */
|
|
35
|
+
function normalizePath(path) {
|
|
36
|
+
return path.startsWith('/') ? path : `/${path}`;
|
|
37
|
+
}
|
|
38
|
+
/** 过滤 ssr:false 的路由(递归处理子路由) */
|
|
39
|
+
export function filterSsrRoutes(routes) {
|
|
40
|
+
return routes
|
|
41
|
+
.filter((route) => route.ssr !== false)
|
|
42
|
+
.map((route) => route.children?.length ? { ...route, children: filterSsrRoutes(route.children) } : route);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* IUiRoute[] → 展平的 react-router RouteObject[](与 ui-runtime client 的 renderRoutes
|
|
46
|
+
* 相同的父路径拼接规则)。loader 透传给 react-router 语义实参。
|
|
47
|
+
*/
|
|
48
|
+
export function flattenRoutes(routes, parent = '') {
|
|
49
|
+
const nodes = [];
|
|
50
|
+
for (const route of routes) {
|
|
51
|
+
const path = normalizePath(parent ? `${parent}${route.path}` : route.path);
|
|
52
|
+
const loader = route.loader
|
|
53
|
+
? (args) => route.loader({ params: args.params, request: args.request })
|
|
54
|
+
: undefined;
|
|
55
|
+
// 透传 ssr 标记,供服务端判断命中链上是否存在 ssr:false 路由
|
|
56
|
+
nodes.push({ path, element: createElement(route.component), loader, ssr: route.ssr });
|
|
57
|
+
if (route.children?.length) {
|
|
58
|
+
nodes.push(...flattenRoutes(route.children, path));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return nodes;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* SSR 数据 Provider:服务端渲染(StaticRouter)与客户端水合(BrowserRouter)
|
|
65
|
+
* 使用同一构造,保证两端 useLoaderData 结果一致。
|
|
66
|
+
*/
|
|
67
|
+
export function SsrDataProvider({ state, routes, children }) {
|
|
68
|
+
return createElement(SsrRoutesContext.Provider, { value: routes }, createElement(SsrDataContext.Provider, { value: state }, children));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 读取当前 URL 匹配路由的 SSR loader 数据(react-router useLoaderData 语义)。
|
|
72
|
+
* 需在 Router(StaticRouter / BrowserRouter)上下文中使用;
|
|
73
|
+
* SPA 空壳(未 SSR)或该路由未定义 loader 时返回 undefined。
|
|
74
|
+
*/
|
|
75
|
+
export function useLoaderData() {
|
|
76
|
+
const state = useContext(SsrDataContext);
|
|
77
|
+
const routes = useContext(SsrRoutesContext);
|
|
78
|
+
const location = useLocation();
|
|
79
|
+
if (!state?.rendered)
|
|
80
|
+
return undefined;
|
|
81
|
+
const matches = matchRoutes(routes, location.pathname);
|
|
82
|
+
const last = matches?.[matches.length - 1];
|
|
83
|
+
if (!last)
|
|
84
|
+
return undefined;
|
|
85
|
+
return state.data[last.route.path ?? ''] ?? undefined;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAEhE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAIvD,8CAA8C;AAC9C,MAAM,CAAC,MAAM,aAAa,GAAG,0BAA0B,CAAA;AAUvD,kDAAkD;AAClD,MAAM,UAAU,YAAY;IAC1B,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,IAAI,CAAA;IAC9C,MAAM,GAAG,GAAI,MAA6C,CAAC,aAAa,CAAC,CAAA;IACzE,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAChD,MAAM,KAAK,GAAG,GAAwB,CAAA;IACtC,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IACzF,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,IAA+B,EAAE,CAAA;AACxE,CAAC;AAED;;;;;GAKG;AACH,MAAM,WAAW,GAAG,UAAgD,CAAA;AAEpE,SAAS,aAAa,CAAI,GAAW,EAAE,OAAU;IAC/C,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC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;IACtD,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAC1C,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAA;IAC3B,OAAQ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAmB,IAAI,SAAS,CAAA;AAC1E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cordis-web/plugin-ui-runtime-ssr",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"exports": {
|
|
9
|
+
"./shared": {
|
|
10
|
+
"types": "./dist/shared/index.d.ts",
|
|
11
|
+
"default": "./dist/shared/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./dist/client/index.d.ts",
|
|
15
|
+
"default": "./dist/client/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./server": {
|
|
18
|
+
"types": "./dist/server/index.d.ts",
|
|
19
|
+
"default": "./dist/server/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -b",
|
|
24
|
+
"build:client": "tsc -b && node scripts/build-browser.mjs",
|
|
25
|
+
"dev": "tsc -b --watch"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@cordis-web/plugin-api-registry": "^0.2.0",
|
|
29
|
+
"@cordis-web/plugin-layout-registry": "^0.2.0",
|
|
30
|
+
"@cordis-web/plugin-ui-registry": "^0.2.0",
|
|
31
|
+
"@cordis-web/plugin-ui-runtime": "^0.2.0",
|
|
32
|
+
"cordis": "^4.0.0-rc.13",
|
|
33
|
+
"jotai": "^3.0.2",
|
|
34
|
+
"react": "^19.3.1",
|
|
35
|
+
"react-dom": "^19.3.1",
|
|
36
|
+
"react-router": "^7.18.5"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"esbuild": "^0.28.2"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/README.md
DELETED