@fluixi/core 1.0.0-alpha.83 → 1.0.0-alpha.85
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/cdn/core.global.js +2 -1
- package/dist/cli/generate.cjs +4117 -292
- package/dist/cli/generate.mjs +4122 -292
- package/dist/cli/index.cjs +4117 -292
- package/dist/cli/index.mjs +4122 -292
- package/dist/cli/run.cjs +63 -1
- package/dist/cli/run.mjs +39 -1
- package/dist/src/cdn/chunk-MDJLC3PE.mjs +830 -0
- package/dist/src/cdn/core.cjs +1365 -1
- package/dist/src/cdn/core.d.ts +3 -3
- package/dist/src/cdn/core.js +3 -3
- package/dist/src/cdn/core.mjs +642 -1
- package/dist/src/cdn/router-JYFZP3EZ.mjs +70 -0
- package/dist/src/index.cjs +1280 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -11
- package/dist/src/index.mjs +1393 -1
- package/dist/src/jsx-dev-runtime.cjs +26 -1
- package/dist/src/jsx-dev-runtime.mjs +24 -1
- package/dist/src/jsx-runtime.cjs +26 -1
- package/dist/src/jsx-runtime.js +0 -9
- package/dist/src/jsx-runtime.mjs +24 -1
- package/dist/src/lib/client/chunk-7IUN2FLI.mjs +133 -0
- package/dist/src/lib/client/index.cjs +956 -1
- package/dist/src/lib/client/index.d.ts +17 -6
- package/dist/src/lib/client/index.d.ts.map +1 -1
- package/dist/src/lib/client/index.js +26 -19
- package/dist/src/lib/client/index.mjs +222 -1
- package/dist/src/lib/client/router-NOFEMOEH.mjs +631 -0
- package/dist/src/lib/context/context.cjs +118 -1
- package/dist/src/lib/context/context.d.ts +19 -37
- package/dist/src/lib/context/context.d.ts.map +1 -1
- package/dist/src/lib/context/context.js +8 -45
- package/dist/src/lib/context/context.mjs +99 -1
- package/dist/src/lib/context/index.cjs +120 -1
- package/dist/src/lib/context/index.mjs +99 -1
- package/dist/src/lib/control-flow.cjs +35 -1
- package/dist/src/lib/control-flow.mjs +25 -1
- package/dist/src/lib/core.cjs +1279 -1
- package/dist/src/lib/core.d.ts +0 -2
- package/dist/src/lib/core.d.ts.map +1 -1
- package/dist/src/lib/core.js +14 -48
- package/dist/src/lib/core.mjs +1393 -1
- package/dist/src/lib/env/index.cjs +60 -1
- package/dist/src/lib/env/index.d.ts +5 -5
- package/dist/src/lib/env/index.js +5 -5
- package/dist/src/lib/env/index.mjs +39 -1
- package/dist/src/lib/i18n/index.cjs +108 -1
- package/dist/src/lib/i18n/index.d.ts +31 -10
- package/dist/src/lib/i18n/index.d.ts.map +1 -1
- package/dist/src/lib/i18n/index.js +31 -10
- package/dist/src/lib/i18n/index.mjs +88 -1
- package/dist/src/lib/index.cjs +633 -1
- package/dist/src/lib/index.d.ts +0 -2
- package/dist/src/lib/index.d.ts.map +1 -1
- package/dist/src/lib/index.js +5 -11
- package/dist/src/lib/index.mjs +721 -1
- package/dist/src/lib/isomorphic.cjs +85 -1
- package/dist/src/lib/isomorphic.d.ts +41 -8
- package/dist/src/lib/isomorphic.d.ts.map +1 -1
- package/dist/src/lib/isomorphic.js +38 -5
- package/dist/src/lib/isomorphic.mjs +64 -1
- package/dist/src/lib/jsx-runtime/index.cjs +21 -1
- package/dist/src/lib/jsx-runtime/index.d.ts +1 -1
- package/dist/src/lib/jsx-runtime/index.js +1 -11
- package/dist/src/lib/jsx-runtime/index.mjs +4 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -8
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +15 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.js +19 -5
- package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -8
- package/dist/src/lib/plugins/index.cjs +311 -8
- package/dist/src/lib/plugins/index.mjs +279 -8
- package/dist/src/lib/plugins/route-codegen.cjs +73 -8
- package/dist/src/lib/plugins/route-codegen.d.ts +0 -1
- package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -1
- package/dist/src/lib/plugins/route-codegen.js +4 -5
- package/dist/src/lib/plugins/route-codegen.mjs +52 -8
- package/dist/src/lib/plugins/route-scanner.cjs +189 -1
- package/dist/src/lib/plugins/route-scanner.d.ts +1 -2
- package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -1
- package/dist/src/lib/plugins/route-scanner.js +7 -8
- package/dist/src/lib/plugins/route-scanner.mjs +158 -1
- package/dist/src/lib/plugins/vite.cjs +27 -1
- package/dist/src/lib/plugins/vite.mjs +6 -1
- package/dist/src/lib/render/await.cjs +38 -1
- package/dist/src/lib/render/await.d.ts +18 -0
- package/dist/src/lib/render/await.d.ts.map +1 -1
- package/dist/src/lib/render/await.js +20 -2
- package/dist/src/lib/render/await.mjs +17 -1
- package/dist/src/lib/render/component.cjs +221 -1
- package/dist/src/lib/render/component.d.ts +3 -44
- package/dist/src/lib/render/component.d.ts.map +1 -1
- package/dist/src/lib/render/component.js +23 -55
- package/dist/src/lib/render/component.mjs +214 -1
- package/dist/src/lib/render/deferred.cjs +175 -1
- package/dist/src/lib/render/deferred.js +5 -5
- package/dist/src/lib/render/deferred.mjs +158 -1
- package/dist/src/lib/render/index.cjs +573 -1
- package/dist/src/lib/render/index.d.ts +3 -17
- package/dist/src/lib/render/index.d.ts.map +1 -1
- package/dist/src/lib/render/index.js +8 -22
- package/dist/src/lib/render/index.mjs +590 -1
- package/dist/src/lib/render/lazy.cjs +67 -1
- package/dist/src/lib/render/lazy.d.ts +22 -1
- package/dist/src/lib/render/lazy.d.ts.map +1 -1
- package/dist/src/lib/render/lazy.js +26 -5
- package/dist/src/lib/render/lazy.mjs +50 -1
- package/dist/src/lib/render/suspense.cjs +141 -1
- package/dist/src/lib/render/suspense.d.ts +40 -0
- package/dist/src/lib/render/suspense.d.ts.map +1 -1
- package/dist/src/lib/render/suspense.js +46 -6
- package/dist/src/lib/render/suspense.mjs +136 -1
- package/dist/src/lib/render/versions.cjs +35 -1
- package/dist/src/lib/render/versions.js +6 -6
- package/dist/src/lib/render/versions.mjs +14 -1
- package/dist/src/lib/router/data.cjs +230 -1
- package/dist/src/lib/router/data.d.ts +1 -13
- package/dist/src/lib/router/data.d.ts.map +1 -1
- package/dist/src/lib/router/data.js +0 -12
- package/dist/src/lib/router/data.mjs +214 -1
- package/dist/src/lib/router/index.cjs +709 -1
- package/dist/src/lib/router/index.d.ts +78 -23
- package/dist/src/lib/router/index.d.ts.map +1 -1
- package/dist/src/lib/router/index.js +161 -37
- package/dist/src/lib/router/index.mjs +722 -1
- package/dist/src/lib/router/transition.cjs +75 -0
- package/dist/src/lib/router/transition.d.ts +81 -0
- package/dist/src/lib/router/transition.d.ts.map +1 -0
- package/dist/src/lib/router/transition.js +136 -0
- package/dist/src/lib/router/transition.mjs +54 -0
- package/dist/src/lib/server/hydration.cjs +169 -1
- package/dist/src/lib/server/hydration.d.ts +15 -55
- package/dist/src/lib/server/hydration.d.ts.map +1 -1
- package/dist/src/lib/server/hydration.js +23 -62
- package/dist/src/lib/server/hydration.mjs +148 -1
- package/dist/src/lib/server/index.cjs +401 -11
- package/dist/src/lib/server/index.d.ts +30 -6
- package/dist/src/lib/server/index.d.ts.map +1 -1
- package/dist/src/lib/server/index.js +34 -11
- package/dist/src/lib/server/index.mjs +379 -11
- package/dist/src/lib/server/reactive.cjs +197 -1
- package/dist/src/lib/server/reactive.d.ts +18 -77
- package/dist/src/lib/server/reactive.d.ts.map +1 -1
- package/dist/src/lib/server/reactive.js +19 -78
- package/dist/src/lib/server/reactive.mjs +176 -1
- package/dist/src/lib/theme/index.cjs +110 -1
- package/dist/src/lib/theme/index.d.ts +19 -4
- package/dist/src/lib/theme/index.d.ts.map +1 -1
- package/dist/src/lib/theme/index.js +17 -2
- package/dist/src/lib/theme/index.mjs +89 -1
- package/dist/src/lib/utils/index.cjs +209 -1
- package/dist/src/lib/utils/index.d.ts +0 -93
- package/dist/src/lib/utils/index.d.ts.map +1 -1
- package/dist/src/lib/utils/index.js +0 -93
- package/dist/src/lib/utils/index.mjs +188 -1
- package/dist/src/routes.cjs +37 -1
- package/dist/src/routes.d.ts +1 -1
- package/dist/src/routes.js +2 -2
- package/dist/src/routes.mjs +17 -1
- package/dist/src/server.cjs +400 -11
- package/dist/src/server.d.ts +0 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +0 -1
- package/dist/src/server.mjs +377 -11
- package/dist/src/utils.cjs +21 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/utils.mjs +4 -1
- package/dist/src/version.generated.cjs +26 -1
- package/dist/src/version.generated.d.ts +1 -1
- package/dist/src/version.generated.js +2 -2
- package/dist/src/version.generated.mjs +5 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +17 -16
- package/src/index.ts +2 -14
- package/dist/src/cdn/chunk-55BT3H6E.mjs +0 -1
- package/dist/src/cdn/router-5JJZBK4E.mjs +0 -1
- package/dist/src/lib/client/chunk-SM4WHBOP.mjs +0 -1
- package/dist/src/lib/client/router-IBD4WPQT.mjs +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Hydration utilities for Fluixi
|
|
3
2
|
* @module @fluixi/core/server/hydration
|
|
4
3
|
*
|
|
5
4
|
* Hydration:
|
|
@@ -17,9 +16,7 @@ export interface HydrationData {
|
|
|
17
16
|
/**
|
|
18
17
|
* Check if currently hydrating
|
|
19
18
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @returns {boolean} True if hydrating
|
|
19
|
+
* During hydration, DOM is reused, not recreated
|
|
23
20
|
*
|
|
24
21
|
* @example
|
|
25
22
|
* ```typescript
|
|
@@ -34,19 +31,15 @@ export declare function isHydrating(): boolean;
|
|
|
34
31
|
/**
|
|
35
32
|
* Set hydration state
|
|
36
33
|
*
|
|
37
|
-
* @param {boolean} state - Hydration state
|
|
38
34
|
* @internal
|
|
39
35
|
*/
|
|
40
36
|
export declare function setHydrating(state: boolean): void;
|
|
41
37
|
/**
|
|
42
38
|
* Store data for hydration
|
|
43
39
|
*
|
|
44
|
-
*
|
|
40
|
+
* On server, store data to serialize into HTML
|
|
45
41
|
* On client during hydration, this data is reused
|
|
46
42
|
*
|
|
47
|
-
* @param {string} key - Unique key
|
|
48
|
-
* @param {any} data - Data to store
|
|
49
|
-
*
|
|
50
43
|
* @example
|
|
51
44
|
* ```typescript
|
|
52
45
|
* import { setHydrationData } from '@fluixi/core/server';
|
|
@@ -59,10 +52,7 @@ export declare function setHydrationData(key: string, data: any): void;
|
|
|
59
52
|
/**
|
|
60
53
|
* Get hydration data
|
|
61
54
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* @param {string} key - Unique key
|
|
65
|
-
* @returns {any} Data or undefined
|
|
55
|
+
* On client, retrieve data stored on server
|
|
66
56
|
*
|
|
67
57
|
* @example
|
|
68
58
|
* ```typescript
|
|
@@ -75,9 +65,6 @@ export declare function setHydrationData(key: string, data: any): void;
|
|
|
75
65
|
export declare function getHydrationData(key: string): any;
|
|
76
66
|
/**
|
|
77
67
|
* Check if hydration data exists
|
|
78
|
-
*
|
|
79
|
-
* @param {string} key - Unique key
|
|
80
|
-
* @returns {boolean} True if exists
|
|
81
68
|
*/
|
|
82
69
|
export declare function hasHydrationData(key: string): boolean;
|
|
83
70
|
/**
|
|
@@ -88,16 +75,12 @@ export declare function hasHydrationData(key: string): boolean;
|
|
|
88
75
|
export declare function clearHydrationData(): void;
|
|
89
76
|
/**
|
|
90
77
|
* Clear specific hydration data
|
|
91
|
-
*
|
|
92
|
-
* @param {string} key - Key to clear
|
|
93
78
|
*/
|
|
94
79
|
export declare function clearHydrationDataKey(key: string): void;
|
|
95
80
|
/**
|
|
96
81
|
* Serialize hydration data to script tag
|
|
97
82
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* @returns {string} Script tag with JSON data
|
|
83
|
+
* Embed data in HTML for client hydration
|
|
101
84
|
*
|
|
102
85
|
* @example
|
|
103
86
|
* ```typescript
|
|
@@ -112,9 +95,7 @@ export declare function serializeHydrationData(): string;
|
|
|
112
95
|
/**
|
|
113
96
|
* Deserialize hydration data from DOM
|
|
114
97
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* @returns {boolean} True if data was loaded
|
|
98
|
+
* On client, load data from script tag
|
|
118
99
|
*
|
|
119
100
|
* @example
|
|
120
101
|
* ```typescript
|
|
@@ -130,17 +111,13 @@ export declare function deserializeHydrationData(): boolean;
|
|
|
130
111
|
/**
|
|
131
112
|
* Generate unique hydration marker ID
|
|
132
113
|
*
|
|
133
|
-
* @returns {string} Unique marker ID
|
|
134
114
|
* @internal
|
|
135
115
|
*/
|
|
136
116
|
export declare function generateMarkerID(): string;
|
|
137
117
|
/**
|
|
138
118
|
* Create hydration marker
|
|
139
119
|
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* @param {string} id - Marker ID
|
|
143
|
-
* @returns {string} HTML comment marker
|
|
120
|
+
* Structural markers required for hydration points
|
|
144
121
|
*
|
|
145
122
|
* @example
|
|
146
123
|
* ```typescript
|
|
@@ -153,29 +130,18 @@ export declare function generateMarkerID(): string;
|
|
|
153
130
|
export declare function hydrationMarker(id: string): string;
|
|
154
131
|
/**
|
|
155
132
|
* Create start hydration marker
|
|
156
|
-
*
|
|
157
|
-
* @param {string} id - Marker ID
|
|
158
|
-
* @returns {string} Start marker
|
|
159
133
|
*/
|
|
160
134
|
export declare function hydrationMarkerStart(id: string): string;
|
|
161
135
|
/**
|
|
162
136
|
* Create end hydration marker
|
|
163
|
-
*
|
|
164
|
-
* @param {string} id - Marker ID
|
|
165
|
-
* @returns {string} End marker
|
|
166
137
|
*/
|
|
167
138
|
export declare function hydrationMarkerEnd(id: string): string;
|
|
168
139
|
/**
|
|
169
140
|
* Create hydration-friendly resource
|
|
170
141
|
*
|
|
171
|
-
*
|
|
142
|
+
* Resources loaded on server are serialized
|
|
172
143
|
* On client, reused during hydration (no re-fetch)
|
|
173
144
|
*
|
|
174
|
-
* @template T
|
|
175
|
-
* @param {string} key - Unique resource key
|
|
176
|
-
* @param {() => Promise<T>} fetcher - Resource fetcher
|
|
177
|
-
* @returns {() => Promise<T>} Hydration-aware fetcher
|
|
178
|
-
*
|
|
179
145
|
* @example
|
|
180
146
|
* ```typescript
|
|
181
147
|
* import { createHydratableResource } from '@fluixi/core/server';
|
|
@@ -190,14 +156,9 @@ export declare function createHydratableResource<T>(key: string, fetcher: () =>
|
|
|
190
156
|
/**
|
|
191
157
|
* Use hydration data in component
|
|
192
158
|
*
|
|
193
|
-
*
|
|
159
|
+
* Components use hydration data to restore state
|
|
194
160
|
* without re-execution
|
|
195
161
|
*
|
|
196
|
-
* @template T
|
|
197
|
-
* @param {string} key - Data key
|
|
198
|
-
* @param {T | (() => T)} value - Value or getter
|
|
199
|
-
* @returns {T} Value
|
|
200
|
-
*
|
|
201
162
|
* @example
|
|
202
163
|
* ```typescript
|
|
203
164
|
* import { useHydrationData } from '@fluixi/core/server';
|
|
@@ -212,7 +173,7 @@ export declare function useHydrationData<T>(key: string, value: T | (() => T)):
|
|
|
212
173
|
/**
|
|
213
174
|
* Cleanup hydration artifacts from DOM
|
|
214
175
|
*
|
|
215
|
-
*
|
|
176
|
+
* After hydration, remove markers and serialized data
|
|
216
177
|
*
|
|
217
178
|
* @example
|
|
218
179
|
* ```typescript
|
|
@@ -224,15 +185,14 @@ export declare function useHydrationData<T>(key: string, value: T | (() => T)):
|
|
|
224
185
|
*/
|
|
225
186
|
export declare function cleanupHydration(): void;
|
|
226
187
|
/**
|
|
227
|
-
*
|
|
188
|
+
* Whether this is a server render.
|
|
228
189
|
*
|
|
229
|
-
*
|
|
190
|
+
* Defers to `@fluixi/dom`, which keeps the flag on a realm singleton that
|
|
191
|
+
* `renderToString` sets. A local `typeof window` test disagrees with it inside a jsdom
|
|
192
|
+
* process, which is where server rendering is usually tested, and `router/data.ts`
|
|
193
|
+
* branches on this to decide whether a loader may touch the client.
|
|
230
194
|
*/
|
|
231
195
|
export declare function isServerEnvironment(): boolean;
|
|
232
|
-
/**
|
|
233
|
-
* Check if on client
|
|
234
|
-
*
|
|
235
|
-
* @returns {boolean} True if client
|
|
236
|
-
*/
|
|
196
|
+
/** Whether this is running in a browser, the negation of a server render. */
|
|
237
197
|
export declare function isClientEnvironment(): boolean;
|
|
238
198
|
//# sourceMappingURL=hydration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydration.d.ts","sourceRoot":"","sources":["../../../../src/lib/server/hydration.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hydration.d.ts","sourceRoot":"","sources":["../../../../src/lib/server/hydration.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AA2BD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAEjD;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI,CAE7D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAEjD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEvD;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAS/C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,IAAI,OAAO,CAuBlD;AAMD;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAErD;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EACxC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACxB,MAAM,OAAO,CAAC,CAAC,CAAC,CAoBlB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAiBxE;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAiCvC;AAgBD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAE7C;AAED,6EAA6E;AAC7E,wBAAgB,mBAAmB,IAAI,OAAO,CAE7C"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Hydration utilities for Fluixi
|
|
3
2
|
* @module @fluixi/core/server/hydration
|
|
4
3
|
*
|
|
5
4
|
* Hydration:
|
|
@@ -8,12 +7,13 @@
|
|
|
8
7
|
* - Bindings reattached
|
|
9
8
|
* - Structural markers required
|
|
10
9
|
*/
|
|
10
|
+
import { isServer as domIsServer } from '@fluixi/dom';
|
|
11
11
|
// ============================================================================
|
|
12
12
|
// STATE
|
|
13
13
|
// ============================================================================
|
|
14
14
|
/**
|
|
15
15
|
* Global hydration flag
|
|
16
|
-
*
|
|
16
|
+
* Indicates if we're currently hydrating
|
|
17
17
|
*/
|
|
18
18
|
let hydrating = false;
|
|
19
19
|
/**
|
|
@@ -31,9 +31,7 @@ let markerCounter = 0;
|
|
|
31
31
|
/**
|
|
32
32
|
* Check if currently hydrating
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @returns {boolean} True if hydrating
|
|
34
|
+
* During hydration, DOM is reused, not recreated
|
|
37
35
|
*
|
|
38
36
|
* @example
|
|
39
37
|
* ```typescript
|
|
@@ -50,7 +48,6 @@ export function isHydrating() {
|
|
|
50
48
|
/**
|
|
51
49
|
* Set hydration state
|
|
52
50
|
*
|
|
53
|
-
* @param {boolean} state - Hydration state
|
|
54
51
|
* @internal
|
|
55
52
|
*/
|
|
56
53
|
export function setHydrating(state) {
|
|
@@ -62,12 +59,9 @@ export function setHydrating(state) {
|
|
|
62
59
|
/**
|
|
63
60
|
* Store data for hydration
|
|
64
61
|
*
|
|
65
|
-
*
|
|
62
|
+
* On server, store data to serialize into HTML
|
|
66
63
|
* On client during hydration, this data is reused
|
|
67
64
|
*
|
|
68
|
-
* @param {string} key - Unique key
|
|
69
|
-
* @param {any} data - Data to store
|
|
70
|
-
*
|
|
71
65
|
* @example
|
|
72
66
|
* ```typescript
|
|
73
67
|
* import { setHydrationData } from '@fluixi/core/server';
|
|
@@ -82,10 +76,7 @@ export function setHydrationData(key, data) {
|
|
|
82
76
|
/**
|
|
83
77
|
* Get hydration data
|
|
84
78
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @param {string} key - Unique key
|
|
88
|
-
* @returns {any} Data or undefined
|
|
79
|
+
* On client, retrieve data stored on server
|
|
89
80
|
*
|
|
90
81
|
* @example
|
|
91
82
|
* ```typescript
|
|
@@ -100,9 +91,6 @@ export function getHydrationData(key) {
|
|
|
100
91
|
}
|
|
101
92
|
/**
|
|
102
93
|
* Check if hydration data exists
|
|
103
|
-
*
|
|
104
|
-
* @param {string} key - Unique key
|
|
105
|
-
* @returns {boolean} True if exists
|
|
106
94
|
*/
|
|
107
95
|
export function hasHydrationData(key) {
|
|
108
96
|
return hydrationDataMap.has(key);
|
|
@@ -117,8 +105,6 @@ export function clearHydrationData() {
|
|
|
117
105
|
}
|
|
118
106
|
/**
|
|
119
107
|
* Clear specific hydration data
|
|
120
|
-
*
|
|
121
|
-
* @param {string} key - Key to clear
|
|
122
108
|
*/
|
|
123
109
|
export function clearHydrationDataKey(key) {
|
|
124
110
|
hydrationDataMap.delete(key);
|
|
@@ -129,9 +115,7 @@ export function clearHydrationDataKey(key) {
|
|
|
129
115
|
/**
|
|
130
116
|
* Serialize hydration data to script tag
|
|
131
117
|
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* @returns {string} Script tag with JSON data
|
|
118
|
+
* Embed data in HTML for client hydration
|
|
135
119
|
*
|
|
136
120
|
* @example
|
|
137
121
|
* ```typescript
|
|
@@ -153,9 +137,7 @@ export function serializeHydrationData() {
|
|
|
153
137
|
/**
|
|
154
138
|
* Deserialize hydration data from DOM
|
|
155
139
|
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* @returns {boolean} True if data was loaded
|
|
140
|
+
* On client, load data from script tag
|
|
159
141
|
*
|
|
160
142
|
* @example
|
|
161
143
|
* ```typescript
|
|
@@ -194,7 +176,6 @@ export function deserializeHydrationData() {
|
|
|
194
176
|
/**
|
|
195
177
|
* Generate unique hydration marker ID
|
|
196
178
|
*
|
|
197
|
-
* @returns {string} Unique marker ID
|
|
198
179
|
* @internal
|
|
199
180
|
*/
|
|
200
181
|
export function generateMarkerID() {
|
|
@@ -203,10 +184,7 @@ export function generateMarkerID() {
|
|
|
203
184
|
/**
|
|
204
185
|
* Create hydration marker
|
|
205
186
|
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* @param {string} id - Marker ID
|
|
209
|
-
* @returns {string} HTML comment marker
|
|
187
|
+
* Structural markers required for hydration points
|
|
210
188
|
*
|
|
211
189
|
* @example
|
|
212
190
|
* ```typescript
|
|
@@ -221,18 +199,12 @@ export function hydrationMarker(id) {
|
|
|
221
199
|
}
|
|
222
200
|
/**
|
|
223
201
|
* Create start hydration marker
|
|
224
|
-
*
|
|
225
|
-
* @param {string} id - Marker ID
|
|
226
|
-
* @returns {string} Start marker
|
|
227
202
|
*/
|
|
228
203
|
export function hydrationMarkerStart(id) {
|
|
229
204
|
return `<!--#${id}-->`;
|
|
230
205
|
}
|
|
231
206
|
/**
|
|
232
207
|
* Create end hydration marker
|
|
233
|
-
*
|
|
234
|
-
* @param {string} id - Marker ID
|
|
235
|
-
* @returns {string} End marker
|
|
236
208
|
*/
|
|
237
209
|
export function hydrationMarkerEnd(id) {
|
|
238
210
|
return `<!--/${id}-->`;
|
|
@@ -243,14 +215,9 @@ export function hydrationMarkerEnd(id) {
|
|
|
243
215
|
/**
|
|
244
216
|
* Create hydration-friendly resource
|
|
245
217
|
*
|
|
246
|
-
*
|
|
218
|
+
* Resources loaded on server are serialized
|
|
247
219
|
* On client, reused during hydration (no re-fetch)
|
|
248
220
|
*
|
|
249
|
-
* @template T
|
|
250
|
-
* @param {string} key - Unique resource key
|
|
251
|
-
* @param {() => Promise<T>} fetcher - Resource fetcher
|
|
252
|
-
* @returns {() => Promise<T>} Hydration-aware fetcher
|
|
253
|
-
*
|
|
254
221
|
* @example
|
|
255
222
|
* ```typescript
|
|
256
223
|
* import { createHydratableResource } from '@fluixi/core/server';
|
|
@@ -263,7 +230,7 @@ export function hydrationMarkerEnd(id) {
|
|
|
263
230
|
*/
|
|
264
231
|
export function createHydratableResource(key, fetcher) {
|
|
265
232
|
return async () => {
|
|
266
|
-
//
|
|
233
|
+
// During hydration or on client, check for cached data
|
|
267
234
|
if (isHydrating() || typeof window !== 'undefined') {
|
|
268
235
|
const cached = getHydrationData(key);
|
|
269
236
|
if (cached !== undefined) {
|
|
@@ -272,7 +239,7 @@ export function createHydratableResource(key, fetcher) {
|
|
|
272
239
|
}
|
|
273
240
|
// Server or no cache: fetch data
|
|
274
241
|
const data = await fetcher();
|
|
275
|
-
//
|
|
242
|
+
// On server, store for serialization
|
|
276
243
|
if (typeof window === 'undefined') {
|
|
277
244
|
setHydrationData(key, data);
|
|
278
245
|
}
|
|
@@ -282,14 +249,9 @@ export function createHydratableResource(key, fetcher) {
|
|
|
282
249
|
/**
|
|
283
250
|
* Use hydration data in component
|
|
284
251
|
*
|
|
285
|
-
*
|
|
252
|
+
* Components use hydration data to restore state
|
|
286
253
|
* without re-execution
|
|
287
254
|
*
|
|
288
|
-
* @template T
|
|
289
|
-
* @param {string} key - Data key
|
|
290
|
-
* @param {T | (() => T)} value - Value or getter
|
|
291
|
-
* @returns {T} Value
|
|
292
|
-
*
|
|
293
255
|
* @example
|
|
294
256
|
* ```typescript
|
|
295
257
|
* import { useHydrationData } from '@fluixi/core/server';
|
|
@@ -301,14 +263,14 @@ export function createHydratableResource(key, fetcher) {
|
|
|
301
263
|
* ```
|
|
302
264
|
*/
|
|
303
265
|
export function useHydrationData(key, value) {
|
|
304
|
-
//
|
|
266
|
+
// Check for hydration data first
|
|
305
267
|
const hydrationData = getHydrationData(key);
|
|
306
268
|
if (hydrationData !== undefined) {
|
|
307
269
|
return hydrationData;
|
|
308
270
|
}
|
|
309
271
|
// Compute or use provided value
|
|
310
272
|
const computedValue = typeof value === 'function' ? value() : value;
|
|
311
|
-
//
|
|
273
|
+
// On server, store for serialization
|
|
312
274
|
if (typeof window === 'undefined') {
|
|
313
275
|
setHydrationData(key, computedValue);
|
|
314
276
|
}
|
|
@@ -320,7 +282,7 @@ export function useHydrationData(key, value) {
|
|
|
320
282
|
/**
|
|
321
283
|
* Cleanup hydration artifacts from DOM
|
|
322
284
|
*
|
|
323
|
-
*
|
|
285
|
+
* After hydration, remove markers and serialized data
|
|
324
286
|
*
|
|
325
287
|
* @example
|
|
326
288
|
* ```typescript
|
|
@@ -367,18 +329,17 @@ if (typeof window !== 'undefined') {
|
|
|
367
329
|
// ENVIRONMENT HELPERS
|
|
368
330
|
// ============================================================================
|
|
369
331
|
/**
|
|
370
|
-
*
|
|
332
|
+
* Whether this is a server render.
|
|
371
333
|
*
|
|
372
|
-
*
|
|
334
|
+
* Defers to `@fluixi/dom`, which keeps the flag on a realm singleton that
|
|
335
|
+
* `renderToString` sets. A local `typeof window` test disagrees with it inside a jsdom
|
|
336
|
+
* process, which is where server rendering is usually tested, and `router/data.ts`
|
|
337
|
+
* branches on this to decide whether a loader may touch the client.
|
|
373
338
|
*/
|
|
374
339
|
export function isServerEnvironment() {
|
|
375
|
-
return
|
|
340
|
+
return domIsServer();
|
|
376
341
|
}
|
|
377
|
-
/**
|
|
378
|
-
* Check if on client
|
|
379
|
-
*
|
|
380
|
-
* @returns {boolean} True if client
|
|
381
|
-
*/
|
|
342
|
+
/** Whether this is running in a browser, the negation of a server render. */
|
|
382
343
|
export function isClientEnvironment() {
|
|
383
|
-
return
|
|
344
|
+
return !domIsServer();
|
|
384
345
|
}
|
|
@@ -1 +1,148 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/server/hydration.ts
|
|
2
|
+
import { isServer as domIsServer } from "@fluixi/dom";
|
|
3
|
+
var hydrating = false;
|
|
4
|
+
var hydrationDataMap = /* @__PURE__ */ new Map();
|
|
5
|
+
var markerCounter = 0;
|
|
6
|
+
function isHydrating() {
|
|
7
|
+
return hydrating;
|
|
8
|
+
}
|
|
9
|
+
function setHydrating(state) {
|
|
10
|
+
hydrating = state;
|
|
11
|
+
}
|
|
12
|
+
function setHydrationData(key, data) {
|
|
13
|
+
hydrationDataMap.set(key, data);
|
|
14
|
+
}
|
|
15
|
+
function getHydrationData(key) {
|
|
16
|
+
return hydrationDataMap.get(key);
|
|
17
|
+
}
|
|
18
|
+
function hasHydrationData(key) {
|
|
19
|
+
return hydrationDataMap.has(key);
|
|
20
|
+
}
|
|
21
|
+
function clearHydrationData() {
|
|
22
|
+
hydrationDataMap.clear();
|
|
23
|
+
}
|
|
24
|
+
function clearHydrationDataKey(key) {
|
|
25
|
+
hydrationDataMap.delete(key);
|
|
26
|
+
}
|
|
27
|
+
function serializeHydrationData() {
|
|
28
|
+
if (hydrationDataMap.size === 0) {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
const data = Object.fromEntries(hydrationDataMap);
|
|
32
|
+
const json = JSON.stringify(data);
|
|
33
|
+
return `<script type="application/json" id="__FLUIXI_HYDRATION__">${json}<\/script>`;
|
|
34
|
+
}
|
|
35
|
+
function deserializeHydrationData() {
|
|
36
|
+
if (typeof window === "undefined") {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const script = document.getElementById("__FLUIXI_HYDRATION__");
|
|
40
|
+
if (!script || script.getAttribute("type") !== "application/json") {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const json = script.textContent || "{}";
|
|
45
|
+
const data = JSON.parse(json);
|
|
46
|
+
for (const [key, value] of Object.entries(data)) {
|
|
47
|
+
hydrationDataMap.set(key, value);
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error("Failed to deserialize hydration data:", error);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function generateMarkerID() {
|
|
56
|
+
return `h${markerCounter++}`;
|
|
57
|
+
}
|
|
58
|
+
function hydrationMarker(id) {
|
|
59
|
+
return `<!--#${id}-->`;
|
|
60
|
+
}
|
|
61
|
+
function hydrationMarkerStart(id) {
|
|
62
|
+
return `<!--#${id}-->`;
|
|
63
|
+
}
|
|
64
|
+
function hydrationMarkerEnd(id) {
|
|
65
|
+
return `<!--/${id}-->`;
|
|
66
|
+
}
|
|
67
|
+
function createHydratableResource(key, fetcher) {
|
|
68
|
+
return async () => {
|
|
69
|
+
if (isHydrating() || typeof window !== "undefined") {
|
|
70
|
+
const cached = getHydrationData(key);
|
|
71
|
+
if (cached !== void 0) {
|
|
72
|
+
return cached;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const data = await fetcher();
|
|
76
|
+
if (typeof window === "undefined") {
|
|
77
|
+
setHydrationData(key, data);
|
|
78
|
+
}
|
|
79
|
+
return data;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function useHydrationData(key, value) {
|
|
83
|
+
const hydrationData = getHydrationData(key);
|
|
84
|
+
if (hydrationData !== void 0) {
|
|
85
|
+
return hydrationData;
|
|
86
|
+
}
|
|
87
|
+
const computedValue = typeof value === "function" ? value() : value;
|
|
88
|
+
if (typeof window === "undefined") {
|
|
89
|
+
setHydrationData(key, computedValue);
|
|
90
|
+
}
|
|
91
|
+
return computedValue;
|
|
92
|
+
}
|
|
93
|
+
function cleanupHydration() {
|
|
94
|
+
if (typeof window === "undefined") {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const script = document.getElementById("__FLUIXI_HYDRATION__");
|
|
98
|
+
if (script) {
|
|
99
|
+
script.remove();
|
|
100
|
+
}
|
|
101
|
+
const walker = document.createTreeWalker(
|
|
102
|
+
document.body,
|
|
103
|
+
NodeFilter.SHOW_COMMENT,
|
|
104
|
+
null
|
|
105
|
+
);
|
|
106
|
+
const comments = [];
|
|
107
|
+
let node;
|
|
108
|
+
while (node = walker.nextNode()) {
|
|
109
|
+
const comment = node;
|
|
110
|
+
const text = comment.nodeValue || "";
|
|
111
|
+
if (text.startsWith("#") || text.startsWith("/")) {
|
|
112
|
+
comments.push(comment);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
comments.forEach((comment) => comment.remove());
|
|
116
|
+
clearHydrationData();
|
|
117
|
+
}
|
|
118
|
+
if (typeof window !== "undefined") {
|
|
119
|
+
window.addEventListener("load", () => {
|
|
120
|
+
setTimeout(cleanupHydration, 100);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function isServerEnvironment() {
|
|
124
|
+
return domIsServer();
|
|
125
|
+
}
|
|
126
|
+
function isClientEnvironment() {
|
|
127
|
+
return !domIsServer();
|
|
128
|
+
}
|
|
129
|
+
export {
|
|
130
|
+
cleanupHydration,
|
|
131
|
+
clearHydrationData,
|
|
132
|
+
clearHydrationDataKey,
|
|
133
|
+
createHydratableResource,
|
|
134
|
+
deserializeHydrationData,
|
|
135
|
+
generateMarkerID,
|
|
136
|
+
getHydrationData,
|
|
137
|
+
hasHydrationData,
|
|
138
|
+
hydrationMarker,
|
|
139
|
+
hydrationMarkerEnd,
|
|
140
|
+
hydrationMarkerStart,
|
|
141
|
+
isClientEnvironment,
|
|
142
|
+
isHydrating,
|
|
143
|
+
isServerEnvironment,
|
|
144
|
+
serializeHydrationData,
|
|
145
|
+
setHydrating,
|
|
146
|
+
setHydrationData,
|
|
147
|
+
useHydrationData
|
|
148
|
+
};
|