dinou 9.0.3 → 9.1.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/CHANGELOG.md +11 -0
- package/README.md +520 -503
- package/dinou/cli.js +1 -1
- package/dinou/core/bailout-proxy.js +2 -2
- package/dinou/core/build-static-pages.js +2 -0
- package/dinou/core/cache-revalidate.js +77 -10
- package/dinou/core/cache-slot.js +153 -39
- package/dinou/core/get-jsx.js +337 -333
- package/dinou/core/handler.js +3075 -2983
- package/dinou/core/no-dynamic.js +25 -0
- package/dinou/core/ppr-context.js +388 -256
- package/dinou/core/ppr-runtime.js +603 -540
- package/dinou/core/render-jsx-to-client-jsx.js +83 -12
- package/dinou/index.d.ts +10 -0
- package/dinou/index.js +3 -0
- package/dinou/package.json +4 -4
- package/dinou/server.d.ts +40 -1
- package/dinou/server.js +6 -0
- package/package.json +1 -1
|
@@ -1,14 +1,58 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import {
|
|
3
3
|
isPprBuildActive,
|
|
4
|
+
isInsideSuspense,
|
|
5
|
+
isInsideOuterSuspenseOutsideSlot,
|
|
6
|
+
rollbackPprHolesAfter,
|
|
7
|
+
isInsideCachedSlot,
|
|
4
8
|
runInSuspense,
|
|
9
|
+
getPprHoleCounter,
|
|
5
10
|
commitPprSuspenseEffects,
|
|
6
11
|
registerHole,
|
|
12
|
+
markDynamicAccess,
|
|
7
13
|
isPageRootElement,
|
|
8
14
|
runInPageSegment,
|
|
15
|
+
resetComponentNoDynamicFlag,
|
|
16
|
+
consumeComponentNoDynamicFlag,
|
|
17
|
+
isNoDynamicActive,
|
|
18
|
+
isSlotDiscoveryActive,
|
|
9
19
|
} from "./ppr-context.js";
|
|
10
20
|
import { getContext } from "./request-context.js";
|
|
11
21
|
|
|
22
|
+
function isThenable(val) {
|
|
23
|
+
return (
|
|
24
|
+
val !== null &&
|
|
25
|
+
(typeof val === "object" || typeof val === "function") &&
|
|
26
|
+
typeof val.then === "function"
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isCacheSlotComponent(fn) {
|
|
31
|
+
if (!fn) return false;
|
|
32
|
+
return Boolean(fn.$$dinouCacheSlot || fn.name === "DinouCacheSlot");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function invokeServerComponentInPpr(fn, callFn) {
|
|
36
|
+
resetComponentNoDynamicFlag();
|
|
37
|
+
const rawResult = callFn();
|
|
38
|
+
const optedOut = consumeComponentNoDynamicFlag();
|
|
39
|
+
if (
|
|
40
|
+
isThenable(rawResult) &&
|
|
41
|
+
!isCacheSlotComponent(fn) &&
|
|
42
|
+
isPprBuildActive() &&
|
|
43
|
+
isInsideOuterSuspenseOutsideSlot() &&
|
|
44
|
+
!isSlotDiscoveryActive() &&
|
|
45
|
+
!optedOut &&
|
|
46
|
+
!isNoDynamicActive()
|
|
47
|
+
) {
|
|
48
|
+
try {
|
|
49
|
+
rawResult.then(null, () => {});
|
|
50
|
+
} catch (_) {}
|
|
51
|
+
markDynamicAccess("async-suspense");
|
|
52
|
+
}
|
|
53
|
+
return await rawResult;
|
|
54
|
+
}
|
|
55
|
+
|
|
12
56
|
function cloneWithDevProps(jsx, newProps, resolvedKey, overrideType) {
|
|
13
57
|
const cloned = {
|
|
14
58
|
...jsx,
|
|
@@ -100,25 +144,36 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
|
|
|
100
144
|
if (jsx.type === Symbol.for("react.suspense")) {
|
|
101
145
|
if (isPprBuildActive()) {
|
|
102
146
|
return await runInSuspense(async (holeId, suspenseStore) => {
|
|
147
|
+
const countBefore = getPprHoleCounter();
|
|
103
148
|
try {
|
|
104
149
|
const renderedChildren = await asyncRenderJSXToClientJSX(jsx.props?.children);
|
|
105
150
|
const renderedFallback = await asyncRenderJSXToClientJSX(jsx.props?.fallback);
|
|
151
|
+
const hasNestedSuspense = getPprHoleCounter() > countBefore;
|
|
106
152
|
await commitPprSuspenseEffects(suspenseStore);
|
|
107
153
|
return cloneWithDevProps(
|
|
108
154
|
jsx,
|
|
109
155
|
{
|
|
110
156
|
...jsx.props,
|
|
111
|
-
|
|
157
|
+
...(hasNestedSuspense ? { "data-ppr-static-parent": holeId } : {}),
|
|
158
|
+
children: hasNestedSuspense
|
|
159
|
+
? React.createElement(
|
|
160
|
+
"div",
|
|
161
|
+
{ "data-ppr-static-parent": holeId, style: { display: "contents" } },
|
|
162
|
+
renderedChildren
|
|
163
|
+
)
|
|
164
|
+
: renderedChildren,
|
|
112
165
|
fallback: renderedFallback,
|
|
113
166
|
},
|
|
114
167
|
key ?? jsx.key
|
|
115
168
|
);
|
|
116
169
|
} catch (err) {
|
|
117
170
|
if (
|
|
118
|
-
(
|
|
119
|
-
(err && typeof
|
|
120
|
-
|
|
171
|
+
(suspenseStore?.slotDepthAtSuspense || 0) === 0 &&
|
|
172
|
+
((err && err.$$typeof === Symbol.for("dinou.ppr.postpone")) ||
|
|
173
|
+
(err && typeof err?.then === "function") ||
|
|
174
|
+
(err && err?.$$typeof === Symbol.for("react.postpone")))
|
|
121
175
|
) {
|
|
176
|
+
rollbackPprHolesAfter(countBefore);
|
|
122
177
|
registerHole(holeId, { type: err.pprType || "suspense" });
|
|
123
178
|
const renderedFallback = await asyncRenderJSXToClientJSX(jsx.props?.fallback);
|
|
124
179
|
return cloneWithDevProps(
|
|
@@ -133,14 +188,20 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
|
|
|
133
188
|
);
|
|
134
189
|
}
|
|
135
190
|
throw err;
|
|
191
|
+
} finally {
|
|
192
|
+
if (suspenseStore) {
|
|
193
|
+
suspenseStore.settled = true;
|
|
194
|
+
}
|
|
136
195
|
}
|
|
137
196
|
});
|
|
138
197
|
}
|
|
139
|
-
return
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
198
|
+
return await runInSuspense(async () => {
|
|
199
|
+
return cloneWithDevProps(
|
|
200
|
+
jsx,
|
|
201
|
+
await asyncRenderJSXToClientJSX(jsx.props),
|
|
202
|
+
key ?? jsx.key
|
|
203
|
+
);
|
|
204
|
+
});
|
|
144
205
|
} else if (
|
|
145
206
|
jsx.type === Symbol.for("react.fragment") ||
|
|
146
207
|
jsx.type === Symbol.for("react.view_transition") ||
|
|
@@ -171,7 +232,9 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
|
|
|
171
232
|
);
|
|
172
233
|
} else {
|
|
173
234
|
// Server component: execute and process
|
|
174
|
-
const returnedJsx = await Component(
|
|
235
|
+
const returnedJsx = await invokeServerComponentInPpr(Component, () =>
|
|
236
|
+
Component(props)
|
|
237
|
+
);
|
|
175
238
|
return await asyncRenderJSXToClientJSX(returnedJsx, key ?? jsx.key);
|
|
176
239
|
}
|
|
177
240
|
} else if (
|
|
@@ -187,7 +250,10 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
|
|
|
187
250
|
jsx.type
|
|
188
251
|
);
|
|
189
252
|
} else {
|
|
190
|
-
const returnedJsx = await
|
|
253
|
+
const returnedJsx = await invokeServerComponentInPpr(
|
|
254
|
+
jsx.type.render,
|
|
255
|
+
() => jsx.type.render(jsx.props, jsx.ref)
|
|
256
|
+
);
|
|
191
257
|
return await asyncRenderJSXToClientJSX(returnedJsx, key ?? jsx.key);
|
|
192
258
|
}
|
|
193
259
|
} else if (
|
|
@@ -204,7 +270,12 @@ async function asyncRenderJSXToClientJSXInner(jsx, key = null) {
|
|
|
204
270
|
);
|
|
205
271
|
} else {
|
|
206
272
|
const innerComp = jsx.type.type;
|
|
207
|
-
const returnedJsx =
|
|
273
|
+
const returnedJsx =
|
|
274
|
+
typeof innerComp === "function"
|
|
275
|
+
? await invokeServerComponentInPpr(innerComp, () =>
|
|
276
|
+
innerComp(jsx.props)
|
|
277
|
+
)
|
|
278
|
+
: null;
|
|
208
279
|
return await asyncRenderJSXToClientJSX(returnedJsx, key ?? jsx.key);
|
|
209
280
|
}
|
|
210
281
|
} else {
|
package/dinou/index.d.ts
CHANGED
|
@@ -327,6 +327,16 @@ export declare function defineConfig(config: DinouConfig): DinouConfig;
|
|
|
327
327
|
*/
|
|
328
328
|
export declare function getContext(): RequestContextStore | undefined;
|
|
329
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Opts the enclosing `<Suspense>` boundary out of becoming a Dynamic PPR Hole
|
|
332
|
+
* when wrapping an async Server Component on a PPR route (`ppr = true`).
|
|
333
|
+
*
|
|
334
|
+
* Call `noDynamic()` synchronously at the top of your async Server Component
|
|
335
|
+
* (before its first `await`) so Dinou resolves its promise at build time and
|
|
336
|
+
* bakes the rendered output directly into the Static Shell (`shell.html`).
|
|
337
|
+
*/
|
|
338
|
+
export declare function noDynamic(): void;
|
|
339
|
+
|
|
330
340
|
import type { ReactNode } from "react";
|
|
331
341
|
|
|
332
342
|
// ====================================================================
|
package/dinou/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineConfig } from "./core/config.js";
|
|
2
2
|
import { getContext } from "./core/request-context.js";
|
|
3
|
+
import { noDynamic } from "./core/no-dynamic.js";
|
|
3
4
|
import {
|
|
4
5
|
usePathname,
|
|
5
6
|
useSearchParams,
|
|
@@ -14,6 +15,7 @@ import { Link } from "./core/link.jsx";
|
|
|
14
15
|
const dinou = {
|
|
15
16
|
defineConfig,
|
|
16
17
|
getContext,
|
|
18
|
+
noDynamic,
|
|
17
19
|
usePathname,
|
|
18
20
|
useSearchParams,
|
|
19
21
|
useRouter,
|
|
@@ -27,6 +29,7 @@ const dinou = {
|
|
|
27
29
|
export {
|
|
28
30
|
defineConfig,
|
|
29
31
|
getContext,
|
|
32
|
+
noDynamic,
|
|
30
33
|
usePathname,
|
|
31
34
|
useSearchParams,
|
|
32
35
|
useRouter,
|
package/dinou/package.json
CHANGED
package/dinou/server.d.ts
CHANGED
|
@@ -44,13 +44,35 @@ export declare function revalidateTag(
|
|
|
44
44
|
options?: { cascade?: boolean } | "layout"
|
|
45
45
|
): Promise<void>;
|
|
46
46
|
|
|
47
|
+
import type { RequestContextStore } from "./index";
|
|
48
|
+
|
|
47
49
|
export type {
|
|
48
50
|
PPRConfig,
|
|
49
51
|
RouteSegmentConfig,
|
|
50
52
|
PageFunctions,
|
|
51
53
|
LayoutFunctions,
|
|
52
54
|
StaticPathItem,
|
|
53
|
-
StaticPathsResult,
|
|
55
|
+
StaticPathsResult,
|
|
56
|
+
RequestContextStore,
|
|
57
|
+
ResponseProxy,
|
|
58
|
+
CookieOptions,
|
|
59
|
+
Query,
|
|
60
|
+
Cookies,
|
|
61
|
+
Headers,
|
|
62
|
+
DinouConfig,
|
|
63
|
+
DinouPlugin,
|
|
64
|
+
ServerHookContext,
|
|
65
|
+
NodeMiddleware,
|
|
66
|
+
PageProps,
|
|
67
|
+
LayoutProps,
|
|
68
|
+
ErrorProps,
|
|
69
|
+
RouteParams,
|
|
70
|
+
DinouRoutePattern,
|
|
71
|
+
DinouRoute,
|
|
72
|
+
DinouRouter,
|
|
73
|
+
CleanRoutePath,
|
|
74
|
+
ExtractRouteParams,
|
|
75
|
+
ExtractSegmentParam,
|
|
54
76
|
} from "./index";
|
|
55
77
|
|
|
56
78
|
export interface DinouCacheSlotProps {
|
|
@@ -68,6 +90,23 @@ export interface DinouCacheSlotProps {
|
|
|
68
90
|
*/
|
|
69
91
|
export declare function DinouCacheSlot(props: DinouCacheSlotProps): Promise<any>;
|
|
70
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Opts the enclosing `<Suspense>` boundary out of becoming a Dynamic PPR Hole
|
|
95
|
+
* when wrapping an async Server Component on a PPR route (`ppr = true`).
|
|
96
|
+
*
|
|
97
|
+
* Call `noDynamic()` synchronously at the top of your async Server Component
|
|
98
|
+
* (before its first `await`) so Dinou resolves its promise at build time and
|
|
99
|
+
* bakes the rendered output directly into the Static Shell (`shell.html`).
|
|
100
|
+
*/
|
|
101
|
+
export declare function noDynamic(): void;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Gets the current request context (req and res proxy) synchronously.
|
|
105
|
+
* Must be called within a Server Component, `getProps`, or a `"use server"` Server Function.
|
|
106
|
+
* @returns The current request context store, or `undefined` if called outside a request scope.
|
|
107
|
+
*/
|
|
108
|
+
export declare function getContext(): RequestContextStore | undefined;
|
|
109
|
+
|
|
71
110
|
// ====================================================================
|
|
72
111
|
// STORAGE ADAPTER TYPES (ISR / CACHE)
|
|
73
112
|
// ====================================================================
|
package/dinou/server.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { getContext } from "./core/request-context.js";
|
|
2
|
+
import { noDynamic } from "./core/no-dynamic.js";
|
|
3
|
+
|
|
4
|
+
export { getContext, noDynamic };
|
|
5
|
+
|
|
1
6
|
export async function revalidatePath(path, options) {
|
|
2
7
|
const { revalidatePath: fn } = await import("./core/cache-revalidate.js");
|
|
3
8
|
return fn(path, options);
|
|
@@ -22,6 +27,7 @@ export async function DinouCacheSlot(props) {
|
|
|
22
27
|
const { DinouCacheSlot: fn } = await import("./core/cache-slot.js");
|
|
23
28
|
return fn(props);
|
|
24
29
|
}
|
|
30
|
+
DinouCacheSlot.$$dinouCacheSlot = true;
|
|
25
31
|
|
|
26
32
|
export {
|
|
27
33
|
StorageAdapter,
|
package/package.json
CHANGED