dinou 9.0.3 → 9.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/CHANGELOG.md +24 -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 +176 -50
- package/dinou/core/get-jsx.js +405 -333
- package/dinou/core/handler.js +3078 -2983
- package/dinou/core/no-dynamic.js +25 -0
- package/dinou/core/ppr-context.js +500 -256
- package/dinou/core/ppr-runtime.js +660 -540
- package/dinou/core/render-jsx-to-client-jsx.js +576 -44
- package/dinou/core/rsc-renderer.js +3 -0
- package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +242 -242
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +253 -253
- package/dinou/esbuild/react-refresh/esm-hmr/client.js +209 -209
- package/dinou/index.d.ts +10 -0
- package/dinou/index.js +3 -0
- package/dinou/node/dev.js +2866 -2853
- package/dinou/package.json +4 -4
- package/dinou/rollup/react-refresh/esm-hmr/client.js +220 -220
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +182 -182
- package/dinou/server.d.ts +39 -0
- package/dinou/server.js +6 -0
- package/dinou/webpack/loaders/server-functions-loader.js +101 -101
- package/package.json +1 -1
|
@@ -1,256 +1,500 @@
|
|
|
1
|
-
// dinou/core/ppr-context.js
|
|
2
|
-
// PPR Pre-rendering Context and Suspense Hole Tracker for Dinou.
|
|
3
|
-
|
|
4
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
-
|
|
6
|
-
const pprStorage = new AsyncLocalStorage();
|
|
7
|
-
const pageSegmentStorage = new AsyncLocalStorage();
|
|
8
|
-
const layoutSegmentStorage = new AsyncLocalStorage();
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export function
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export function
|
|
232
|
-
const store = getPprStore();
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
1
|
+
// dinou/core/ppr-context.js
|
|
2
|
+
// PPR Pre-rendering Context and Suspense Hole Tracker for Dinou.
|
|
3
|
+
|
|
4
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
|
|
6
|
+
const pprStorage = new AsyncLocalStorage();
|
|
7
|
+
const pageSegmentStorage = new AsyncLocalStorage();
|
|
8
|
+
const layoutSegmentStorage = new AsyncLocalStorage();
|
|
9
|
+
const cachedSlotStorage = new AsyncLocalStorage();
|
|
10
|
+
const slotDiscoveryStorage = new AsyncLocalStorage();
|
|
11
|
+
const runtimeStaticSuspenseStorage = new AsyncLocalStorage();
|
|
12
|
+
const pageRootElements = new WeakSet();
|
|
13
|
+
const layoutRootElements = new WeakSet();
|
|
14
|
+
const layoutChildrenPlaceholders = new WeakSet();
|
|
15
|
+
|
|
16
|
+
const NO_DYNAMIC_HOOK_KEY = Symbol.for("dinou.ppr.noDynamic.hook");
|
|
17
|
+
export const SKIP_STATIC_SUSPENSE_SYMBOL = Symbol.for("dinou.ppr.skipStatic");
|
|
18
|
+
let currentComponentNoDynamic = false;
|
|
19
|
+
|
|
20
|
+
export function runInRuntimeStaticSuspense(callback) {
|
|
21
|
+
const prev = runtimeStaticSuspenseStorage.getStore();
|
|
22
|
+
return runtimeStaticSuspenseStorage.run(
|
|
23
|
+
{ active: true, depth: (prev?.depth || 0) + 1 },
|
|
24
|
+
callback
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function runInRuntimeDynamicHole(callback, holeId = null) {
|
|
29
|
+
const prev = runtimeStaticSuspenseStorage.getStore();
|
|
30
|
+
return runtimeStaticSuspenseStorage.run(
|
|
31
|
+
{
|
|
32
|
+
active: false,
|
|
33
|
+
depth: 0,
|
|
34
|
+
holeId: holeId || prev?.holeId || null,
|
|
35
|
+
idCount: 0,
|
|
36
|
+
childHoleCount: 0,
|
|
37
|
+
},
|
|
38
|
+
callback
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getActiveRuntimeDynamicHoleStore() {
|
|
43
|
+
const store = runtimeStaticSuspenseStorage.getStore();
|
|
44
|
+
return store && store.holeId ? store : null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function isRuntimeStaticSuspenseActive() {
|
|
48
|
+
const store = runtimeStaticSuspenseStorage.getStore();
|
|
49
|
+
return Boolean(store && store.active && store.depth > 0);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function noDynamic() {
|
|
53
|
+
if (isRuntimeStaticSuspenseActive() && !isPprBuildActive()) {
|
|
54
|
+
const err = new Error(
|
|
55
|
+
"[Dinou PPR] Skipping static noDynamic() subtree during runtime hole traversal"
|
|
56
|
+
);
|
|
57
|
+
err.$$typeof = SKIP_STATIC_SUSPENSE_SYMBOL;
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
currentComponentNoDynamic = true;
|
|
61
|
+
const store = pprStorage.getStore();
|
|
62
|
+
if (store && store.suspenseDepth > 0) {
|
|
63
|
+
store.noDynamic = true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof globalThis !== "undefined") {
|
|
68
|
+
globalThis[NO_DYNAMIC_HOOK_KEY] = noDynamic;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function resetComponentNoDynamicFlag() {
|
|
72
|
+
currentComponentNoDynamic = false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function consumeComponentNoDynamicFlag() {
|
|
76
|
+
const val = currentComponentNoDynamic;
|
|
77
|
+
currentComponentNoDynamic = false;
|
|
78
|
+
return val;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function isNoDynamicActive() {
|
|
82
|
+
if (currentComponentNoDynamic) return true;
|
|
83
|
+
const store = pprStorage.getStore();
|
|
84
|
+
return Boolean(store && store.noDynamic);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function runInCachedSlot(callback, options = {}) {
|
|
88
|
+
const prev = cachedSlotStorage.getStore();
|
|
89
|
+
const isCached = options?.cached !== false;
|
|
90
|
+
const slotId =
|
|
91
|
+
typeof options === "string"
|
|
92
|
+
? options
|
|
93
|
+
: options?.slotId || prev?.slotId || null;
|
|
94
|
+
return cachedSlotStorage.run(
|
|
95
|
+
{
|
|
96
|
+
depth: (prev?.depth || 0) + (isCached ? 1 : 0),
|
|
97
|
+
slotId,
|
|
98
|
+
idCount: 0,
|
|
99
|
+
},
|
|
100
|
+
callback
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function getActiveCachedSlotStore() {
|
|
105
|
+
return cachedSlotStorage.getStore() || null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function isInsideCachedSlot() {
|
|
109
|
+
return Boolean((cachedSlotStorage.getStore()?.depth || 0) > 0);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function runInSlotDiscovery(callback) {
|
|
113
|
+
return slotDiscoveryStorage.run({ active: true }, callback);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function isSlotDiscoveryActive() {
|
|
117
|
+
return Boolean(slotDiscoveryStorage.getStore()?.active);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function markPageRootElement(el) {
|
|
121
|
+
if (el && typeof el === "object") {
|
|
122
|
+
pageRootElements.add(el);
|
|
123
|
+
}
|
|
124
|
+
return el;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function isPageRootElement(el) {
|
|
128
|
+
return Boolean(el && typeof el === "object" && pageRootElements.has(el));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function markLayoutRootElement(el) {
|
|
132
|
+
if (el && typeof el === "object") {
|
|
133
|
+
layoutRootElements.add(el);
|
|
134
|
+
}
|
|
135
|
+
return el;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function isLayoutRootElement(el) {
|
|
139
|
+
return Boolean(el && typeof el === "object" && layoutRootElements.has(el));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function createLayoutChildrenPlaceholder() {
|
|
143
|
+
const placeholder = {
|
|
144
|
+
$$typeof: Symbol.for("react.transitional.element"),
|
|
145
|
+
type: Symbol.for("dinou.layout.children.placeholder"),
|
|
146
|
+
key: null,
|
|
147
|
+
ref: null,
|
|
148
|
+
props: {},
|
|
149
|
+
};
|
|
150
|
+
layoutChildrenPlaceholders.add(placeholder);
|
|
151
|
+
return placeholder;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function isLayoutChildrenPlaceholder(el) {
|
|
155
|
+
return Boolean(
|
|
156
|
+
el &&
|
|
157
|
+
typeof el === "object" &&
|
|
158
|
+
(layoutChildrenPlaceholders.has(el) ||
|
|
159
|
+
el.type === Symbol.for("dinou.layout.children.placeholder"))
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function runInPageSegment(callback, storeOverride = null) {
|
|
164
|
+
const prev = pageSegmentStorage.getStore();
|
|
165
|
+
const store =
|
|
166
|
+
storeOverride || prev || { active: true, idCount: 0, holeCount: 0 };
|
|
167
|
+
return pageSegmentStorage.run(store, callback);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function getActivePageSegmentStore() {
|
|
171
|
+
return pageSegmentStorage.getStore() || null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function isInsidePageSegment() {
|
|
175
|
+
return Boolean(pageSegmentStorage.getStore()?.active);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function runInLayoutSegment(callback, storeOverride = null) {
|
|
179
|
+
const prev = layoutSegmentStorage.getStore();
|
|
180
|
+
const store =
|
|
181
|
+
storeOverride || prev || { active: true, idCount: 0, holeCount: 0 };
|
|
182
|
+
return layoutSegmentStorage.run(store, callback);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function getActiveLayoutSegmentStore() {
|
|
186
|
+
return layoutSegmentStorage.getStore() || null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function isInsideLayoutSegment() {
|
|
190
|
+
return Boolean(
|
|
191
|
+
layoutSegmentStorage.getStore()?.active && !isInsidePageSegment()
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Executes a function within a PPR pre-render context.
|
|
197
|
+
* @param {object} options
|
|
198
|
+
* @param {Function} callback
|
|
199
|
+
* @returns {Promise<any>}
|
|
200
|
+
*/
|
|
201
|
+
export function runWithPprContext(options, callback) {
|
|
202
|
+
const sharedCounter = { nextHoleIndex: 0 };
|
|
203
|
+
const sharedHoles = new Map();
|
|
204
|
+
const store = {
|
|
205
|
+
isPpr: Boolean(options?.isPpr),
|
|
206
|
+
suspenseDepth: 0,
|
|
207
|
+
currentHoleId: null,
|
|
208
|
+
holeStack: [],
|
|
209
|
+
holes: sharedHoles,
|
|
210
|
+
counter: sharedCounter,
|
|
211
|
+
get nextHoleIndex() {
|
|
212
|
+
return sharedCounter.nextHoleIndex;
|
|
213
|
+
},
|
|
214
|
+
set nextHoleIndex(val) {
|
|
215
|
+
sharedCounter.nextHoleIndex = val;
|
|
216
|
+
},
|
|
217
|
+
...options,
|
|
218
|
+
};
|
|
219
|
+
return pprStorage.run(store, callback);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function getPprStore() {
|
|
223
|
+
return pprStorage.getStore() || null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function isPprBuildActive() {
|
|
227
|
+
const store = getPprStore();
|
|
228
|
+
return Boolean(store && store.isPpr);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function isInsideSuspense() {
|
|
232
|
+
const store = getPprStore();
|
|
233
|
+
return Boolean(store && store.suspenseDepth > 0);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function isInsideOuterSuspenseOutsideSlot() {
|
|
237
|
+
const store = getPprStore();
|
|
238
|
+
return Boolean(
|
|
239
|
+
store && store.suspenseDepth > 0 && store.hasOuterSuspenseOutsideSlot
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function rollbackPprHolesAfter(countBefore) {
|
|
244
|
+
const store = getPprStore();
|
|
245
|
+
if (!store) return;
|
|
246
|
+
const target = Number(countBefore) || 0;
|
|
247
|
+
const current = store.counter
|
|
248
|
+
? store.counter.nextHoleIndex
|
|
249
|
+
: store.nextHoleIndex || 0;
|
|
250
|
+
if (current > target) {
|
|
251
|
+
for (let i = target + 1; i <= current; i++) {
|
|
252
|
+
store.holes.delete(`ppr-hole-${i}`);
|
|
253
|
+
}
|
|
254
|
+
if (store.counter) {
|
|
255
|
+
store.counter.nextHoleIndex = target;
|
|
256
|
+
} else {
|
|
257
|
+
store.nextHoleIndex = target;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function resetPprHoles(startIndex = 0) {
|
|
263
|
+
const store = getPprStore();
|
|
264
|
+
if (store) {
|
|
265
|
+
const startVal = Number(startIndex) || 0;
|
|
266
|
+
if (store.counter) {
|
|
267
|
+
store.counter.nextHoleIndex = startVal;
|
|
268
|
+
} else {
|
|
269
|
+
store.nextHoleIndex = startVal;
|
|
270
|
+
}
|
|
271
|
+
if (store.holes && typeof store.holes.clear === "function") {
|
|
272
|
+
store.holes.clear();
|
|
273
|
+
}
|
|
274
|
+
store.suspenseDepth = 0;
|
|
275
|
+
store.currentHoleId = null;
|
|
276
|
+
if (Array.isArray(store.holeStack)) {
|
|
277
|
+
store.holeStack.length = 0;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function getPprHoleCounter() {
|
|
283
|
+
const store = getPprStore();
|
|
284
|
+
if (store) {
|
|
285
|
+
return store.counter ? store.counter.nextHoleIndex : store.nextHoleIndex || 0;
|
|
286
|
+
}
|
|
287
|
+
return 0;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function runInSuspense(callback, explicitHoleId = null) {
|
|
291
|
+
const store = getPprStore();
|
|
292
|
+
if (!store) {
|
|
293
|
+
let holeId = explicitHoleId;
|
|
294
|
+
if (!holeId) {
|
|
295
|
+
const holeStore = getActiveRuntimeDynamicHoleStore();
|
|
296
|
+
const layoutStore = getActiveLayoutSegmentStore();
|
|
297
|
+
const pageStore = getActivePageSegmentStore();
|
|
298
|
+
if (holeStore && holeStore.holeId) {
|
|
299
|
+
holeStore.childHoleCount = (holeStore.childHoleCount || 0) + 1;
|
|
300
|
+
holeId = `${holeStore.holeId}-${holeStore.childHoleCount}`;
|
|
301
|
+
} else if (
|
|
302
|
+
layoutStore &&
|
|
303
|
+
layoutStore.active &&
|
|
304
|
+
!isInsidePageSegment()
|
|
305
|
+
) {
|
|
306
|
+
layoutStore.holeCount = (layoutStore.holeCount || 0) + 1;
|
|
307
|
+
holeId = `layout-hole-${layoutStore.holeCount}`;
|
|
308
|
+
} else if (pageStore && pageStore.active) {
|
|
309
|
+
pageStore.holeCount = (pageStore.holeCount || 0) + 1;
|
|
310
|
+
holeId = `ppr-hole-${pageStore.holeCount}`;
|
|
311
|
+
} else {
|
|
312
|
+
holeId = "ppr-hole-1";
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return callback(holeId, null);
|
|
316
|
+
}
|
|
317
|
+
let holeId = explicitHoleId;
|
|
318
|
+
if (!holeId) {
|
|
319
|
+
if (store.counter) {
|
|
320
|
+
store.counter.nextHoleIndex++;
|
|
321
|
+
holeId = `ppr-hole-${store.counter.nextHoleIndex}`;
|
|
322
|
+
} else {
|
|
323
|
+
store.nextHoleIndex++;
|
|
324
|
+
holeId = `ppr-hole-${store.nextHoleIndex}`;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
const nextStack = Array.isArray(store.holeStack)
|
|
328
|
+
? [...store.holeStack, holeId]
|
|
329
|
+
: [holeId];
|
|
330
|
+
const pendingEffects = [];
|
|
331
|
+
const slotDepthAtSuspense = cachedSlotStorage.getStore()?.depth || 0;
|
|
332
|
+
const hasOuterSuspenseOutsideSlot = Boolean(
|
|
333
|
+
store.hasOuterSuspenseOutsideSlot || slotDepthAtSuspense === 0
|
|
334
|
+
);
|
|
335
|
+
const childStore = {
|
|
336
|
+
...store,
|
|
337
|
+
suspenseDepth: store.suspenseDepth + 1,
|
|
338
|
+
currentHoleId: holeId,
|
|
339
|
+
holeStack: nextStack,
|
|
340
|
+
noDynamic: false,
|
|
341
|
+
settled: false,
|
|
342
|
+
slotDepthAtSuspense,
|
|
343
|
+
hasOuterSuspenseOutsideSlot,
|
|
344
|
+
pendingEffects,
|
|
345
|
+
parentPendingEffects: Array.isArray(store.pendingEffects)
|
|
346
|
+
? store.pendingEffects
|
|
347
|
+
: null,
|
|
348
|
+
};
|
|
349
|
+
return pprStorage.run(childStore, () => callback(holeId, childStore));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function deferPprSuspenseEffect(effectFn) {
|
|
353
|
+
const store = getPprStore();
|
|
354
|
+
if (
|
|
355
|
+
store &&
|
|
356
|
+
store.isPpr &&
|
|
357
|
+
store.suspenseDepth > 0 &&
|
|
358
|
+
Array.isArray(store.pendingEffects) &&
|
|
359
|
+
typeof effectFn === "function"
|
|
360
|
+
) {
|
|
361
|
+
if (store.settled) {
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
store.pendingEffects.push(effectFn);
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export async function commitPprSuspenseEffects(childStore) {
|
|
371
|
+
if (!childStore || !Array.isArray(childStore.pendingEffects)) return;
|
|
372
|
+
const effects = childStore.pendingEffects.splice(0);
|
|
373
|
+
if (effects.length === 0) return;
|
|
374
|
+
if (Array.isArray(childStore.parentPendingEffects)) {
|
|
375
|
+
childStore.parentPendingEffects.push(...effects);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
for (const fn of effects) {
|
|
379
|
+
await fn();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export function enterSuspense(holeId = null) {
|
|
384
|
+
const store = getPprStore();
|
|
385
|
+
if (store) {
|
|
386
|
+
store.suspenseDepth++;
|
|
387
|
+
if (!holeId) {
|
|
388
|
+
if (store.counter) {
|
|
389
|
+
store.counter.nextHoleIndex++;
|
|
390
|
+
holeId = `ppr-hole-${store.counter.nextHoleIndex}`;
|
|
391
|
+
} else {
|
|
392
|
+
store.nextHoleIndex++;
|
|
393
|
+
holeId = `ppr-hole-${store.nextHoleIndex}`;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (Array.isArray(store.holeStack)) {
|
|
397
|
+
store.holeStack.push(holeId);
|
|
398
|
+
}
|
|
399
|
+
store.currentHoleId = holeId;
|
|
400
|
+
return holeId;
|
|
401
|
+
}
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export function exitSuspense() {
|
|
406
|
+
const store = getPprStore();
|
|
407
|
+
if (store) {
|
|
408
|
+
store.suspenseDepth = Math.max(0, store.suspenseDepth - 1);
|
|
409
|
+
if (Array.isArray(store.holeStack) && store.holeStack.length > 0) {
|
|
410
|
+
store.holeStack.pop();
|
|
411
|
+
store.currentHoleId =
|
|
412
|
+
store.holeStack.length > 0
|
|
413
|
+
? store.holeStack[store.holeStack.length - 1]
|
|
414
|
+
: null;
|
|
415
|
+
} else if (store.suspenseDepth === 0) {
|
|
416
|
+
store.currentHoleId = null;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export function markDynamicAccess(type = "dynamic") {
|
|
422
|
+
const store = getPprStore();
|
|
423
|
+
if (
|
|
424
|
+
store &&
|
|
425
|
+
store.isPpr &&
|
|
426
|
+
store.suspenseDepth > 0 &&
|
|
427
|
+
store.hasOuterSuspenseOutsideSlot
|
|
428
|
+
) {
|
|
429
|
+
const idx = store.counter ? store.counter.nextHoleIndex : store.nextHoleIndex;
|
|
430
|
+
const holeId = store.currentHoleId || `ppr-hole-${idx}`;
|
|
431
|
+
const error = new Error(
|
|
432
|
+
`[Dinou PPR] Dynamic access to '${type}' postponed inside Suspense`
|
|
433
|
+
);
|
|
434
|
+
error.$$typeof = Symbol.for("dinou.ppr.postpone");
|
|
435
|
+
error.pprType = type;
|
|
436
|
+
error.holeId = holeId;
|
|
437
|
+
throw error;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export function registerHole(holeId, meta = {}) {
|
|
442
|
+
const store = getPprStore();
|
|
443
|
+
if (store && holeId) {
|
|
444
|
+
store.holes.set(holeId, {
|
|
445
|
+
id: holeId,
|
|
446
|
+
registeredAt: Date.now(),
|
|
447
|
+
...meta,
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export function getRegisteredHoles() {
|
|
453
|
+
const store = getPprStore();
|
|
454
|
+
if (store) {
|
|
455
|
+
return Array.from(store.holes.keys());
|
|
456
|
+
}
|
|
457
|
+
return [];
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export default {
|
|
461
|
+
noDynamic,
|
|
462
|
+
SKIP_STATIC_SUSPENSE_SYMBOL,
|
|
463
|
+
runInRuntimeStaticSuspense,
|
|
464
|
+
runInRuntimeDynamicHole,
|
|
465
|
+
getActiveRuntimeDynamicHoleStore,
|
|
466
|
+
isRuntimeStaticSuspenseActive,
|
|
467
|
+
resetComponentNoDynamicFlag,
|
|
468
|
+
consumeComponentNoDynamicFlag,
|
|
469
|
+
isNoDynamicActive,
|
|
470
|
+
runInCachedSlot,
|
|
471
|
+
isInsideCachedSlot,
|
|
472
|
+
runInSlotDiscovery,
|
|
473
|
+
isSlotDiscoveryActive,
|
|
474
|
+
markPageRootElement,
|
|
475
|
+
isPageRootElement,
|
|
476
|
+
markLayoutRootElement,
|
|
477
|
+
isLayoutRootElement,
|
|
478
|
+
createLayoutChildrenPlaceholder,
|
|
479
|
+
isLayoutChildrenPlaceholder,
|
|
480
|
+
runInPageSegment,
|
|
481
|
+
isInsidePageSegment,
|
|
482
|
+
runInLayoutSegment,
|
|
483
|
+
isInsideLayoutSegment,
|
|
484
|
+
runWithPprContext,
|
|
485
|
+
getPprStore,
|
|
486
|
+
isPprBuildActive,
|
|
487
|
+
isInsideSuspense,
|
|
488
|
+
isInsideOuterSuspenseOutsideSlot,
|
|
489
|
+
rollbackPprHolesAfter,
|
|
490
|
+
resetPprHoles,
|
|
491
|
+
getPprHoleCounter,
|
|
492
|
+
runInSuspense,
|
|
493
|
+
deferPprSuspenseEffect,
|
|
494
|
+
commitPprSuspenseEffects,
|
|
495
|
+
enterSuspense,
|
|
496
|
+
exitSuspense,
|
|
497
|
+
markDynamicAccess,
|
|
498
|
+
registerHole,
|
|
499
|
+
getRegisteredHoles,
|
|
500
|
+
};
|