vite-plugin-react-server 1.2.5 → 1.3.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/package.json +8 -3
- package/dist/plugin/orchestrator/createPluginOrchestrator.client.d.ts.map +1 -1
- package/dist/plugin/orchestrator/createPluginOrchestrator.client.js +3 -0
- package/dist/plugin/orchestrator/createPluginOrchestrator.server.d.ts.map +1 -1
- package/dist/plugin/orchestrator/createPluginOrchestrator.server.js +3 -0
- package/dist/plugin/vendor/vendor-alias.d.ts +12 -0
- package/dist/plugin/vendor/vendor-alias.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor-alias.js +87 -0
- package/dist/plugin/vendor/vendor.client.d.ts +1 -1
- package/dist/plugin/vendor/vendor.client.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.client.js +19 -6
- package/dist/plugin/vendor/vendor.server.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.server.js +18 -5
- package/dist/plugin/vendor/vendor.static.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.static.js +18 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/oss-experimental/react-server-dom-esm/LICENSE +21 -0
- package/oss-experimental/react-server-dom-esm/README.md +5 -0
- package/oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.development.js +2996 -0
- package/oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.browser.production.js +1612 -0
- package/oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.development.js +3124 -0
- package/oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-client.node.production.js +1752 -0
- package/oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.development.js +4213 -0
- package/oss-experimental/react-server-dom-esm/cjs/react-server-dom-esm-server.node.production.js +2857 -0
- package/oss-experimental/react-server-dom-esm/client.browser.js +7 -0
- package/oss-experimental/react-server-dom-esm/client.js +3 -0
- package/oss-experimental/react-server-dom-esm/client.node.js +7 -0
- package/oss-experimental/react-server-dom-esm/esm/package.json +3 -0
- package/oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js +3969 -0
- package/oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.production.js +2347 -0
- package/oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-node-loader.production.js +515 -0
- package/oss-experimental/react-server-dom-esm/index.js +12 -0
- package/oss-experimental/react-server-dom-esm/package.json +63 -0
- package/oss-experimental/react-server-dom-esm/server.js +6 -0
- package/oss-experimental/react-server-dom-esm/server.node.js +17 -0
- package/oss-experimental/react-server-dom-esm/static.js +6 -0
- package/oss-experimental/react-server-dom-esm/static.node.js +12 -0
- package/package.json +8 -3
- package/plugin/orchestrator/createPluginOrchestrator.client.ts +4 -0
- package/plugin/orchestrator/createPluginOrchestrator.server.ts +4 -0
- package/plugin/vendor/vendor-alias.ts +102 -0
- package/plugin/vendor/vendor.client.ts +24 -9
- package/plugin/vendor/vendor.server.ts +22 -7
- package/plugin/vendor/vendor.static.ts +21 -7
- package/scripts/build-oss-experimental.sh +161 -0
package/oss-experimental/react-server-dom-esm/esm/react-server-dom-esm-client.browser.development.js
ADDED
|
@@ -0,0 +1,3969 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-server-dom-esm-client.browser.development.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import * as React from 'react';
|
|
12
|
+
import * as ReactDOM from 'react-dom';
|
|
13
|
+
|
|
14
|
+
function _defineProperty(e, r, t) {
|
|
15
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
16
|
+
value: t,
|
|
17
|
+
enumerable: !0,
|
|
18
|
+
configurable: !0,
|
|
19
|
+
writable: !0
|
|
20
|
+
}) : e[r] = t, e;
|
|
21
|
+
}
|
|
22
|
+
function _toPrimitive(t, r) {
|
|
23
|
+
if ("object" != typeof t || !t) return t;
|
|
24
|
+
var e = t[Symbol.toPrimitive];
|
|
25
|
+
if (void 0 !== e) {
|
|
26
|
+
var i = e.call(t, r || "default");
|
|
27
|
+
if ("object" != typeof i) return i;
|
|
28
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
29
|
+
}
|
|
30
|
+
return ("string" === r ? String : Number)(t);
|
|
31
|
+
}
|
|
32
|
+
function _toPropertyKey(t) {
|
|
33
|
+
var i = _toPrimitive(t, "string");
|
|
34
|
+
return "symbol" == typeof i ? i : i + "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var ReactVersion = '19.2.0-experimental-0ca8420f-20250504';
|
|
38
|
+
|
|
39
|
+
function createStringDecoder() {
|
|
40
|
+
return new TextDecoder();
|
|
41
|
+
}
|
|
42
|
+
var decoderOptions = {
|
|
43
|
+
stream: true
|
|
44
|
+
};
|
|
45
|
+
function readPartialStringChunk(decoder, buffer) {
|
|
46
|
+
return decoder.decode(buffer, decoderOptions);
|
|
47
|
+
}
|
|
48
|
+
function readFinalStringChunk(decoder, buffer) {
|
|
49
|
+
return decoder.decode(buffer);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var badgeFormat = '%c%s%c ';
|
|
53
|
+
// Same badge styling as DevTools.
|
|
54
|
+
var badgeStyle =
|
|
55
|
+
// We use a fixed background if light-dark is not supported, otherwise
|
|
56
|
+
// we use a transparent background.
|
|
57
|
+
'background: #e6e6e6;' + 'background: light-dark(rgba(0,0,0,0.1), rgba(255,255,255,0.25));' + 'color: #000000;' + 'color: light-dark(#000000, #ffffff);' + 'border-radius: 2px';
|
|
58
|
+
var resetStyle = '';
|
|
59
|
+
var pad = ' ';
|
|
60
|
+
var bind = Function.prototype.bind;
|
|
61
|
+
function bindToConsole(methodName, args, badgeName) {
|
|
62
|
+
var offset = 0;
|
|
63
|
+
switch (methodName) {
|
|
64
|
+
case 'dir':
|
|
65
|
+
case 'dirxml':
|
|
66
|
+
case 'groupEnd':
|
|
67
|
+
case 'table':
|
|
68
|
+
{
|
|
69
|
+
// These methods cannot be colorized because they don't take a formatting string.
|
|
70
|
+
// $FlowFixMe
|
|
71
|
+
return bind.apply(console[methodName], [console].concat(args)); // eslint-disable-line react-internal/no-production-logging
|
|
72
|
+
}
|
|
73
|
+
case 'assert':
|
|
74
|
+
{
|
|
75
|
+
// assert takes formatting options as the second argument.
|
|
76
|
+
offset = 1;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
var newArgs = args.slice(0);
|
|
80
|
+
if (typeof newArgs[offset] === 'string') {
|
|
81
|
+
newArgs.splice(offset, 1, badgeFormat + newArgs[offset], badgeStyle, pad + badgeName + pad, resetStyle);
|
|
82
|
+
} else {
|
|
83
|
+
newArgs.splice(offset, 0, badgeFormat, badgeStyle, pad + badgeName + pad, resetStyle);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// The "this" binding in the "bind";
|
|
87
|
+
newArgs.unshift(console);
|
|
88
|
+
|
|
89
|
+
// $FlowFixMe
|
|
90
|
+
return bind.apply(console[methodName], newArgs); // eslint-disable-line react-internal/no-production-logging
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Module root path
|
|
94
|
+
|
|
95
|
+
function resolveClientReference(bundlerConfig, metadata) {
|
|
96
|
+
var baseURL = bundlerConfig;
|
|
97
|
+
return {
|
|
98
|
+
specifier: baseURL + metadata[0],
|
|
99
|
+
name: metadata[1]
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function resolveServerReference(config, id) {
|
|
103
|
+
var baseURL = config;
|
|
104
|
+
var idx = id.lastIndexOf('#');
|
|
105
|
+
var exportName = id.slice(idx + 1);
|
|
106
|
+
var fullURL = id.slice(0, idx);
|
|
107
|
+
if (!fullURL.startsWith(baseURL)) {
|
|
108
|
+
throw new Error('Attempted to load a Server Reference outside the hosted root.');
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
specifier: fullURL,
|
|
112
|
+
name: exportName
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
var asyncModuleCache = new Map();
|
|
116
|
+
function preloadModule(metadata) {
|
|
117
|
+
var existingPromise = asyncModuleCache.get(metadata.specifier);
|
|
118
|
+
if (existingPromise) {
|
|
119
|
+
if (existingPromise.status === 'fulfilled') {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return existingPromise;
|
|
123
|
+
} else {
|
|
124
|
+
// $FlowFixMe[unsupported-syntax]
|
|
125
|
+
var modulePromise = import(metadata.specifier);
|
|
126
|
+
modulePromise.then(function (value) {
|
|
127
|
+
var fulfilledThenable = modulePromise;
|
|
128
|
+
fulfilledThenable.status = 'fulfilled';
|
|
129
|
+
fulfilledThenable.value = value;
|
|
130
|
+
}, function (reason) {
|
|
131
|
+
var rejectedThenable = modulePromise;
|
|
132
|
+
rejectedThenable.status = 'rejected';
|
|
133
|
+
rejectedThenable.reason = reason;
|
|
134
|
+
});
|
|
135
|
+
asyncModuleCache.set(metadata.specifier, modulePromise);
|
|
136
|
+
return modulePromise;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function requireModule(metadata) {
|
|
140
|
+
var moduleExports;
|
|
141
|
+
// We assume that preloadModule has been called before, which
|
|
142
|
+
// should have added something to the module cache.
|
|
143
|
+
var promise = asyncModuleCache.get(metadata.specifier);
|
|
144
|
+
if (promise.status === 'fulfilled') {
|
|
145
|
+
moduleExports = promise.value;
|
|
146
|
+
} else {
|
|
147
|
+
throw promise.reason;
|
|
148
|
+
}
|
|
149
|
+
return moduleExports[metadata.name];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
var ReactDOMSharedInternals = ReactDOM.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
|
153
|
+
|
|
154
|
+
// This client file is in the shared folder because it applies to both SSR and browser contexts.
|
|
155
|
+
// It is the configuration of the FlightClient behavior which can run in either environment.
|
|
156
|
+
|
|
157
|
+
function dispatchHint(code, model) {
|
|
158
|
+
var dispatcher = ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
|
|
159
|
+
switch (code) {
|
|
160
|
+
case 'D':
|
|
161
|
+
{
|
|
162
|
+
var refined = refineModel(code, model);
|
|
163
|
+
var href = refined;
|
|
164
|
+
dispatcher.D(/* prefetchDNS */href);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
case 'C':
|
|
168
|
+
{
|
|
169
|
+
var _refined = refineModel(code, model);
|
|
170
|
+
if (typeof _refined === 'string') {
|
|
171
|
+
var _href = _refined;
|
|
172
|
+
dispatcher.C(/* preconnect */_href);
|
|
173
|
+
} else {
|
|
174
|
+
var _href2 = _refined[0];
|
|
175
|
+
var crossOrigin = _refined[1];
|
|
176
|
+
dispatcher.C(/* preconnect */_href2, crossOrigin);
|
|
177
|
+
}
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
case 'L':
|
|
181
|
+
{
|
|
182
|
+
var _refined2 = refineModel(code, model);
|
|
183
|
+
var _href3 = _refined2[0];
|
|
184
|
+
var as = _refined2[1];
|
|
185
|
+
if (_refined2.length === 3) {
|
|
186
|
+
var options = _refined2[2];
|
|
187
|
+
dispatcher.L(/* preload */_href3, as, options);
|
|
188
|
+
} else {
|
|
189
|
+
dispatcher.L(/* preload */_href3, as);
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
case 'm':
|
|
194
|
+
{
|
|
195
|
+
var _refined3 = refineModel(code, model);
|
|
196
|
+
if (typeof _refined3 === 'string') {
|
|
197
|
+
var _href4 = _refined3;
|
|
198
|
+
dispatcher.m(/* preloadModule */_href4);
|
|
199
|
+
} else {
|
|
200
|
+
var _href5 = _refined3[0];
|
|
201
|
+
var _options = _refined3[1];
|
|
202
|
+
dispatcher.m(/* preloadModule */_href5, _options);
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
case 'X':
|
|
207
|
+
{
|
|
208
|
+
var _refined4 = refineModel(code, model);
|
|
209
|
+
if (typeof _refined4 === 'string') {
|
|
210
|
+
var _href6 = _refined4;
|
|
211
|
+
dispatcher.X(/* preinitScript */_href6);
|
|
212
|
+
} else {
|
|
213
|
+
var _href7 = _refined4[0];
|
|
214
|
+
var _options2 = _refined4[1];
|
|
215
|
+
dispatcher.X(/* preinitScript */_href7, _options2);
|
|
216
|
+
}
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
case 'S':
|
|
220
|
+
{
|
|
221
|
+
var _refined5 = refineModel(code, model);
|
|
222
|
+
if (typeof _refined5 === 'string') {
|
|
223
|
+
var _href8 = _refined5;
|
|
224
|
+
dispatcher.S(/* preinitStyle */_href8);
|
|
225
|
+
} else {
|
|
226
|
+
var _href9 = _refined5[0];
|
|
227
|
+
var precedence = _refined5[1] === 0 ? undefined : _refined5[1];
|
|
228
|
+
var _options3 = _refined5.length === 3 ? _refined5[2] : undefined;
|
|
229
|
+
dispatcher.S(/* preinitStyle */_href9, precedence, _options3);
|
|
230
|
+
}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
case 'M':
|
|
234
|
+
{
|
|
235
|
+
var _refined6 = refineModel(code, model);
|
|
236
|
+
if (typeof _refined6 === 'string') {
|
|
237
|
+
var _href0 = _refined6;
|
|
238
|
+
dispatcher.M(/* preinitModuleScript */_href0);
|
|
239
|
+
} else {
|
|
240
|
+
var _href1 = _refined6[0];
|
|
241
|
+
var _options4 = _refined6[1];
|
|
242
|
+
dispatcher.M(/* preinitModuleScript */_href1, _options4);
|
|
243
|
+
}
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Flow is having trouble refining the HintModels so we help it a bit.
|
|
250
|
+
// This should be compiled out in the production build.
|
|
251
|
+
function refineModel(code, model) {
|
|
252
|
+
return model;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
var rendererPackageName = 'react-server-dom-esm';
|
|
256
|
+
|
|
257
|
+
var REACT_ELEMENT_TYPE = Symbol.for('react.transitional.element') ;
|
|
258
|
+
var REACT_PORTAL_TYPE = Symbol.for('react.portal');
|
|
259
|
+
var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
|
|
260
|
+
var REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
|
|
261
|
+
var REACT_PROFILER_TYPE = Symbol.for('react.profiler');
|
|
262
|
+
var REACT_PROVIDER_TYPE = Symbol.for('react.provider'); // TODO: Delete with enableRenderableContext
|
|
263
|
+
var REACT_CONSUMER_TYPE = Symbol.for('react.consumer');
|
|
264
|
+
var REACT_CONTEXT_TYPE = Symbol.for('react.context');
|
|
265
|
+
var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
|
|
266
|
+
var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
|
|
267
|
+
var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
|
|
268
|
+
var REACT_MEMO_TYPE = Symbol.for('react.memo');
|
|
269
|
+
var REACT_LAZY_TYPE = Symbol.for('react.lazy');
|
|
270
|
+
var REACT_ACTIVITY_TYPE = Symbol.for('react.activity');
|
|
271
|
+
var REACT_POSTPONE_TYPE = Symbol.for('react.postpone');
|
|
272
|
+
var REACT_VIEW_TRANSITION_TYPE = Symbol.for('react.view_transition');
|
|
273
|
+
var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
|
|
274
|
+
var FAUX_ITERATOR_SYMBOL = '@@iterator';
|
|
275
|
+
function getIteratorFn(maybeIterable) {
|
|
276
|
+
if (maybeIterable === null || typeof maybeIterable !== 'object') {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
|
|
280
|
+
if (typeof maybeIterator === 'function') {
|
|
281
|
+
return maybeIterator;
|
|
282
|
+
}
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
var ASYNC_ITERATOR = Symbol.asyncIterator;
|
|
286
|
+
|
|
287
|
+
var isArrayImpl = Array.isArray;
|
|
288
|
+
function isArray(a) {
|
|
289
|
+
return isArrayImpl(a);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
|
293
|
+
|
|
294
|
+
// Used for DEV messages to keep track of which parent rendered some props,
|
|
295
|
+
// in case they error.
|
|
296
|
+
var jsxPropsParents = new WeakMap();
|
|
297
|
+
var jsxChildrenParents = new WeakMap();
|
|
298
|
+
function isObjectPrototype(object) {
|
|
299
|
+
if (!object) {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
var ObjectPrototype = Object.prototype;
|
|
303
|
+
if (object === ObjectPrototype) {
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
// It might be an object from a different Realm which is
|
|
307
|
+
// still just a plain simple object.
|
|
308
|
+
if (getPrototypeOf(object)) {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
var names = Object.getOwnPropertyNames(object);
|
|
312
|
+
for (var i = 0; i < names.length; i++) {
|
|
313
|
+
if (!(names[i] in ObjectPrototype)) {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
function isSimpleObject(object) {
|
|
320
|
+
if (!isObjectPrototype(getPrototypeOf(object))) {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
var names = Object.getOwnPropertyNames(object);
|
|
324
|
+
for (var i = 0; i < names.length; i++) {
|
|
325
|
+
var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
|
|
326
|
+
if (!descriptor) {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
if (!descriptor.enumerable) {
|
|
330
|
+
if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
|
|
331
|
+
// React adds key and ref getters to props objects to issue warnings.
|
|
332
|
+
// Those getters will not be transferred to the client, but that's ok,
|
|
333
|
+
// so we'll special case them.
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
function objectName(object) {
|
|
342
|
+
// $FlowFixMe[method-unbinding]
|
|
343
|
+
var name = Object.prototype.toString.call(object);
|
|
344
|
+
return name.replace(/^\[object (.*)\]$/, function (m, p0) {
|
|
345
|
+
return p0;
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
function describeKeyForErrorMessage(key) {
|
|
349
|
+
var encodedKey = JSON.stringify(key);
|
|
350
|
+
return '"' + key + '"' === encodedKey ? key : encodedKey;
|
|
351
|
+
}
|
|
352
|
+
function describeValueForErrorMessage(value) {
|
|
353
|
+
switch (typeof value) {
|
|
354
|
+
case 'string':
|
|
355
|
+
{
|
|
356
|
+
return JSON.stringify(value.length <= 10 ? value : value.slice(0, 10) + '...');
|
|
357
|
+
}
|
|
358
|
+
case 'object':
|
|
359
|
+
{
|
|
360
|
+
if (isArray(value)) {
|
|
361
|
+
return '[...]';
|
|
362
|
+
}
|
|
363
|
+
if (value !== null && value.$$typeof === CLIENT_REFERENCE_TAG) {
|
|
364
|
+
return describeClientReference();
|
|
365
|
+
}
|
|
366
|
+
var name = objectName(value);
|
|
367
|
+
if (name === 'Object') {
|
|
368
|
+
return '{...}';
|
|
369
|
+
}
|
|
370
|
+
return name;
|
|
371
|
+
}
|
|
372
|
+
case 'function':
|
|
373
|
+
{
|
|
374
|
+
if (value.$$typeof === CLIENT_REFERENCE_TAG) {
|
|
375
|
+
return describeClientReference();
|
|
376
|
+
}
|
|
377
|
+
var _name = value.displayName || value.name;
|
|
378
|
+
return _name ? 'function ' + _name : 'function';
|
|
379
|
+
}
|
|
380
|
+
default:
|
|
381
|
+
// eslint-disable-next-line react-internal/safe-string-coercion
|
|
382
|
+
return String(value);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function describeElementType(type) {
|
|
386
|
+
if (typeof type === 'string') {
|
|
387
|
+
return type;
|
|
388
|
+
}
|
|
389
|
+
switch (type) {
|
|
390
|
+
case REACT_SUSPENSE_TYPE:
|
|
391
|
+
return 'Suspense';
|
|
392
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
|
393
|
+
return 'SuspenseList';
|
|
394
|
+
case REACT_VIEW_TRANSITION_TYPE:
|
|
395
|
+
{
|
|
396
|
+
return 'ViewTransition';
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (typeof type === 'object') {
|
|
400
|
+
switch (type.$$typeof) {
|
|
401
|
+
case REACT_FORWARD_REF_TYPE:
|
|
402
|
+
return describeElementType(type.render);
|
|
403
|
+
case REACT_MEMO_TYPE:
|
|
404
|
+
return describeElementType(type.type);
|
|
405
|
+
case REACT_LAZY_TYPE:
|
|
406
|
+
{
|
|
407
|
+
var lazyComponent = type;
|
|
408
|
+
var payload = lazyComponent._payload;
|
|
409
|
+
var init = lazyComponent._init;
|
|
410
|
+
try {
|
|
411
|
+
// Lazy may contain any component type so we recursively resolve it.
|
|
412
|
+
return describeElementType(init(payload));
|
|
413
|
+
} catch (x) {}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return '';
|
|
418
|
+
}
|
|
419
|
+
var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
|
|
420
|
+
function describeClientReference(ref) {
|
|
421
|
+
return 'client';
|
|
422
|
+
}
|
|
423
|
+
function describeObjectForErrorMessage(objectOrArray, expandedName) {
|
|
424
|
+
var objKind = objectName(objectOrArray);
|
|
425
|
+
if (objKind !== 'Object' && objKind !== 'Array') {
|
|
426
|
+
return objKind;
|
|
427
|
+
}
|
|
428
|
+
var str = '';
|
|
429
|
+
var start = -1;
|
|
430
|
+
var length = 0;
|
|
431
|
+
if (isArray(objectOrArray)) {
|
|
432
|
+
if (jsxChildrenParents.has(objectOrArray)) {
|
|
433
|
+
// Print JSX Children
|
|
434
|
+
var type = jsxChildrenParents.get(objectOrArray);
|
|
435
|
+
str = '<' + describeElementType(type) + '>';
|
|
436
|
+
var array = objectOrArray;
|
|
437
|
+
for (var i = 0; i < array.length; i++) {
|
|
438
|
+
var value = array[i];
|
|
439
|
+
var substr = void 0;
|
|
440
|
+
if (typeof value === 'string') {
|
|
441
|
+
substr = value;
|
|
442
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
443
|
+
substr = '{' + describeObjectForErrorMessage(value) + '}';
|
|
444
|
+
} else {
|
|
445
|
+
substr = '{' + describeValueForErrorMessage(value) + '}';
|
|
446
|
+
}
|
|
447
|
+
if ('' + i === expandedName) {
|
|
448
|
+
start = str.length;
|
|
449
|
+
length = substr.length;
|
|
450
|
+
str += substr;
|
|
451
|
+
} else if (substr.length < 15 && str.length + substr.length < 40) {
|
|
452
|
+
str += substr;
|
|
453
|
+
} else {
|
|
454
|
+
str += '{...}';
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
str += '</' + describeElementType(type) + '>';
|
|
458
|
+
} else {
|
|
459
|
+
// Print Array
|
|
460
|
+
str = '[';
|
|
461
|
+
var _array = objectOrArray;
|
|
462
|
+
for (var _i = 0; _i < _array.length; _i++) {
|
|
463
|
+
if (_i > 0) {
|
|
464
|
+
str += ', ';
|
|
465
|
+
}
|
|
466
|
+
var _value = _array[_i];
|
|
467
|
+
var _substr = void 0;
|
|
468
|
+
if (typeof _value === 'object' && _value !== null) {
|
|
469
|
+
_substr = describeObjectForErrorMessage(_value);
|
|
470
|
+
} else {
|
|
471
|
+
_substr = describeValueForErrorMessage(_value);
|
|
472
|
+
}
|
|
473
|
+
if ('' + _i === expandedName) {
|
|
474
|
+
start = str.length;
|
|
475
|
+
length = _substr.length;
|
|
476
|
+
str += _substr;
|
|
477
|
+
} else if (_substr.length < 10 && str.length + _substr.length < 40) {
|
|
478
|
+
str += _substr;
|
|
479
|
+
} else {
|
|
480
|
+
str += '...';
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
str += ']';
|
|
484
|
+
}
|
|
485
|
+
} else {
|
|
486
|
+
if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
|
|
487
|
+
str = '<' + describeElementType(objectOrArray.type) + '/>';
|
|
488
|
+
} else if (objectOrArray.$$typeof === CLIENT_REFERENCE_TAG) {
|
|
489
|
+
return describeClientReference();
|
|
490
|
+
} else if (jsxPropsParents.has(objectOrArray)) {
|
|
491
|
+
// Print JSX
|
|
492
|
+
var _type = jsxPropsParents.get(objectOrArray);
|
|
493
|
+
str = '<' + (describeElementType(_type) || '...');
|
|
494
|
+
var object = objectOrArray;
|
|
495
|
+
var names = Object.keys(object);
|
|
496
|
+
for (var _i2 = 0; _i2 < names.length; _i2++) {
|
|
497
|
+
str += ' ';
|
|
498
|
+
var name = names[_i2];
|
|
499
|
+
str += describeKeyForErrorMessage(name) + '=';
|
|
500
|
+
var _value2 = object[name];
|
|
501
|
+
var _substr2 = void 0;
|
|
502
|
+
if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
|
|
503
|
+
_substr2 = describeObjectForErrorMessage(_value2);
|
|
504
|
+
} else {
|
|
505
|
+
_substr2 = describeValueForErrorMessage(_value2);
|
|
506
|
+
}
|
|
507
|
+
if (typeof _value2 !== 'string') {
|
|
508
|
+
_substr2 = '{' + _substr2 + '}';
|
|
509
|
+
}
|
|
510
|
+
if (name === expandedName) {
|
|
511
|
+
start = str.length;
|
|
512
|
+
length = _substr2.length;
|
|
513
|
+
str += _substr2;
|
|
514
|
+
} else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
|
|
515
|
+
str += _substr2;
|
|
516
|
+
} else {
|
|
517
|
+
str += '...';
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
str += '>';
|
|
521
|
+
} else {
|
|
522
|
+
// Print Object
|
|
523
|
+
str = '{';
|
|
524
|
+
var _object = objectOrArray;
|
|
525
|
+
var _names = Object.keys(_object);
|
|
526
|
+
for (var _i3 = 0; _i3 < _names.length; _i3++) {
|
|
527
|
+
if (_i3 > 0) {
|
|
528
|
+
str += ', ';
|
|
529
|
+
}
|
|
530
|
+
var _name2 = _names[_i3];
|
|
531
|
+
str += describeKeyForErrorMessage(_name2) + ': ';
|
|
532
|
+
var _value3 = _object[_name2];
|
|
533
|
+
var _substr3 = void 0;
|
|
534
|
+
if (typeof _value3 === 'object' && _value3 !== null) {
|
|
535
|
+
_substr3 = describeObjectForErrorMessage(_value3);
|
|
536
|
+
} else {
|
|
537
|
+
_substr3 = describeValueForErrorMessage(_value3);
|
|
538
|
+
}
|
|
539
|
+
if (_name2 === expandedName) {
|
|
540
|
+
start = str.length;
|
|
541
|
+
length = _substr3.length;
|
|
542
|
+
str += _substr3;
|
|
543
|
+
} else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
|
|
544
|
+
str += _substr3;
|
|
545
|
+
} else {
|
|
546
|
+
str += '...';
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
str += '}';
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (expandedName === undefined) {
|
|
553
|
+
return str;
|
|
554
|
+
}
|
|
555
|
+
if (start > -1 && length > 0) {
|
|
556
|
+
var highlight = ' '.repeat(start) + '^'.repeat(length);
|
|
557
|
+
return '\n ' + str + '\n ' + highlight;
|
|
558
|
+
}
|
|
559
|
+
return '\n ' + str;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function createTemporaryReferenceSet() {
|
|
563
|
+
return new Map();
|
|
564
|
+
}
|
|
565
|
+
function writeTemporaryReference(set, reference, object) {
|
|
566
|
+
set.set(reference, object);
|
|
567
|
+
}
|
|
568
|
+
function readTemporaryReference(set, reference) {
|
|
569
|
+
return set.get(reference);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
var ObjectPrototype = Object.prototype;
|
|
573
|
+
var knownServerReferences = new WeakMap();
|
|
574
|
+
|
|
575
|
+
// Serializable values
|
|
576
|
+
|
|
577
|
+
// Thenable<ReactServerValue>
|
|
578
|
+
|
|
579
|
+
function serializeByValueID(id) {
|
|
580
|
+
return '$' + id.toString(16);
|
|
581
|
+
}
|
|
582
|
+
function serializePromiseID(id) {
|
|
583
|
+
return '$@' + id.toString(16);
|
|
584
|
+
}
|
|
585
|
+
function serializeServerReferenceID(id) {
|
|
586
|
+
return '$F' + id.toString(16);
|
|
587
|
+
}
|
|
588
|
+
function serializeTemporaryReferenceMarker() {
|
|
589
|
+
return '$T';
|
|
590
|
+
}
|
|
591
|
+
function serializeFormDataReference(id) {
|
|
592
|
+
// Why K? F is "Function". D is "Date". What else?
|
|
593
|
+
return '$K' + id.toString(16);
|
|
594
|
+
}
|
|
595
|
+
function serializeNumber(number) {
|
|
596
|
+
if (Number.isFinite(number)) {
|
|
597
|
+
if (number === 0 && 1 / number === -Infinity) {
|
|
598
|
+
return '$-0';
|
|
599
|
+
} else {
|
|
600
|
+
return number;
|
|
601
|
+
}
|
|
602
|
+
} else {
|
|
603
|
+
if (number === Infinity) {
|
|
604
|
+
return '$Infinity';
|
|
605
|
+
} else if (number === -Infinity) {
|
|
606
|
+
return '$-Infinity';
|
|
607
|
+
} else {
|
|
608
|
+
return '$NaN';
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
function serializeUndefined() {
|
|
613
|
+
return '$undefined';
|
|
614
|
+
}
|
|
615
|
+
function serializeDateFromDateJSON(dateJSON) {
|
|
616
|
+
// JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
|
|
617
|
+
// We need only tack on a $D prefix.
|
|
618
|
+
return '$D' + dateJSON;
|
|
619
|
+
}
|
|
620
|
+
function serializeBigInt(n) {
|
|
621
|
+
return '$n' + n.toString(10);
|
|
622
|
+
}
|
|
623
|
+
function serializeMapID(id) {
|
|
624
|
+
return '$Q' + id.toString(16);
|
|
625
|
+
}
|
|
626
|
+
function serializeSetID(id) {
|
|
627
|
+
return '$W' + id.toString(16);
|
|
628
|
+
}
|
|
629
|
+
function serializeBlobID(id) {
|
|
630
|
+
return '$B' + id.toString(16);
|
|
631
|
+
}
|
|
632
|
+
function serializeIteratorID(id) {
|
|
633
|
+
return '$i' + id.toString(16);
|
|
634
|
+
}
|
|
635
|
+
function escapeStringValue(value) {
|
|
636
|
+
if (value[0] === '$') {
|
|
637
|
+
// We need to escape $ prefixed strings since we use those to encode
|
|
638
|
+
// references to IDs and as special symbol values.
|
|
639
|
+
return '$' + value;
|
|
640
|
+
} else {
|
|
641
|
+
return value;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
function processReply(root, formFieldPrefix, temporaryReferences, resolve, reject) {
|
|
645
|
+
var nextPartId = 1;
|
|
646
|
+
var pendingParts = 0;
|
|
647
|
+
var formData = null;
|
|
648
|
+
var writtenObjects = new WeakMap();
|
|
649
|
+
var modelRoot = root;
|
|
650
|
+
function serializeTypedArray(tag, typedArray) {
|
|
651
|
+
var blob = new Blob([
|
|
652
|
+
// We should be able to pass the buffer straight through but Node < 18 treat
|
|
653
|
+
// multi-byte array blobs differently so we first convert it to single-byte.
|
|
654
|
+
new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength)]);
|
|
655
|
+
var blobId = nextPartId++;
|
|
656
|
+
if (formData === null) {
|
|
657
|
+
formData = new FormData();
|
|
658
|
+
}
|
|
659
|
+
formData.append(formFieldPrefix + blobId, blob);
|
|
660
|
+
return '$' + tag + blobId.toString(16);
|
|
661
|
+
}
|
|
662
|
+
function serializeBinaryReader(reader) {
|
|
663
|
+
if (formData === null) {
|
|
664
|
+
// Upgrade to use FormData to allow us to stream this value.
|
|
665
|
+
formData = new FormData();
|
|
666
|
+
}
|
|
667
|
+
var data = formData;
|
|
668
|
+
pendingParts++;
|
|
669
|
+
var streamId = nextPartId++;
|
|
670
|
+
var buffer = [];
|
|
671
|
+
function progress(entry) {
|
|
672
|
+
if (entry.done) {
|
|
673
|
+
var blobId = nextPartId++;
|
|
674
|
+
data.append(formFieldPrefix + blobId, new Blob(buffer));
|
|
675
|
+
data.append(formFieldPrefix + streamId, '"$o' + blobId.toString(16) + '"');
|
|
676
|
+
data.append(formFieldPrefix + streamId, 'C'); // Close signal
|
|
677
|
+
pendingParts--;
|
|
678
|
+
if (pendingParts === 0) {
|
|
679
|
+
resolve(data);
|
|
680
|
+
}
|
|
681
|
+
} else {
|
|
682
|
+
buffer.push(entry.value);
|
|
683
|
+
reader.read(new Uint8Array(1024)).then(progress, reject);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
reader.read(new Uint8Array(1024)).then(progress, reject);
|
|
687
|
+
return '$r' + streamId.toString(16);
|
|
688
|
+
}
|
|
689
|
+
function serializeReader(reader) {
|
|
690
|
+
if (formData === null) {
|
|
691
|
+
// Upgrade to use FormData to allow us to stream this value.
|
|
692
|
+
formData = new FormData();
|
|
693
|
+
}
|
|
694
|
+
var data = formData;
|
|
695
|
+
pendingParts++;
|
|
696
|
+
var streamId = nextPartId++;
|
|
697
|
+
function progress(entry) {
|
|
698
|
+
if (entry.done) {
|
|
699
|
+
data.append(formFieldPrefix + streamId, 'C'); // Close signal
|
|
700
|
+
pendingParts--;
|
|
701
|
+
if (pendingParts === 0) {
|
|
702
|
+
resolve(data);
|
|
703
|
+
}
|
|
704
|
+
} else {
|
|
705
|
+
try {
|
|
706
|
+
// $FlowFixMe[incompatible-type]: While plain JSON can return undefined we never do here.
|
|
707
|
+
var partJSON = JSON.stringify(entry.value, resolveToJSON);
|
|
708
|
+
data.append(formFieldPrefix + streamId, partJSON);
|
|
709
|
+
reader.read().then(progress, reject);
|
|
710
|
+
} catch (x) {
|
|
711
|
+
reject(x);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
reader.read().then(progress, reject);
|
|
716
|
+
return '$R' + streamId.toString(16);
|
|
717
|
+
}
|
|
718
|
+
function serializeReadableStream(stream) {
|
|
719
|
+
// Detect if this is a BYOB stream. BYOB streams should be able to be read as bytes on the
|
|
720
|
+
// receiving side. For binary streams, we serialize them as plain Blobs.
|
|
721
|
+
var binaryReader;
|
|
722
|
+
try {
|
|
723
|
+
// $FlowFixMe[extra-arg]: This argument is accepted.
|
|
724
|
+
binaryReader = stream.getReader({
|
|
725
|
+
mode: 'byob'
|
|
726
|
+
});
|
|
727
|
+
} catch (x) {
|
|
728
|
+
return serializeReader(stream.getReader());
|
|
729
|
+
}
|
|
730
|
+
return serializeBinaryReader(binaryReader);
|
|
731
|
+
}
|
|
732
|
+
function serializeAsyncIterable(iterable, iterator) {
|
|
733
|
+
if (formData === null) {
|
|
734
|
+
// Upgrade to use FormData to allow us to stream this value.
|
|
735
|
+
formData = new FormData();
|
|
736
|
+
}
|
|
737
|
+
var data = formData;
|
|
738
|
+
pendingParts++;
|
|
739
|
+
var streamId = nextPartId++;
|
|
740
|
+
|
|
741
|
+
// Generators/Iterators are Iterables but they're also their own iterator
|
|
742
|
+
// functions. If that's the case, we treat them as single-shot. Otherwise,
|
|
743
|
+
// we assume that this iterable might be a multi-shot and allow it to be
|
|
744
|
+
// iterated more than once on the receiving server.
|
|
745
|
+
var isIterator = iterable === iterator;
|
|
746
|
+
|
|
747
|
+
// There's a race condition between when the stream is aborted and when the promise
|
|
748
|
+
// resolves so we track whether we already aborted it to avoid writing twice.
|
|
749
|
+
function progress(entry) {
|
|
750
|
+
if (entry.done) {
|
|
751
|
+
if (entry.value === undefined) {
|
|
752
|
+
data.append(formFieldPrefix + streamId, 'C'); // Close signal
|
|
753
|
+
} else {
|
|
754
|
+
// Unlike streams, the last value may not be undefined. If it's not
|
|
755
|
+
// we outline it and encode a reference to it in the closing instruction.
|
|
756
|
+
try {
|
|
757
|
+
// $FlowFixMe[incompatible-type]: While plain JSON can return undefined we never do here.
|
|
758
|
+
var partJSON = JSON.stringify(entry.value, resolveToJSON);
|
|
759
|
+
data.append(formFieldPrefix + streamId, 'C' + partJSON); // Close signal
|
|
760
|
+
} catch (x) {
|
|
761
|
+
reject(x);
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
pendingParts--;
|
|
766
|
+
if (pendingParts === 0) {
|
|
767
|
+
resolve(data);
|
|
768
|
+
}
|
|
769
|
+
} else {
|
|
770
|
+
try {
|
|
771
|
+
// $FlowFixMe[incompatible-type]: While plain JSON can return undefined we never do here.
|
|
772
|
+
var _partJSON = JSON.stringify(entry.value, resolveToJSON);
|
|
773
|
+
data.append(formFieldPrefix + streamId, _partJSON);
|
|
774
|
+
iterator.next().then(progress, reject);
|
|
775
|
+
} catch (x) {
|
|
776
|
+
reject(x);
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
iterator.next().then(progress, reject);
|
|
782
|
+
return '$' + (isIterator ? 'x' : 'X') + streamId.toString(16);
|
|
783
|
+
}
|
|
784
|
+
function resolveToJSON(key, value) {
|
|
785
|
+
var parent = this;
|
|
786
|
+
|
|
787
|
+
// Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
|
|
788
|
+
{
|
|
789
|
+
// $FlowFixMe[incompatible-use]
|
|
790
|
+
var originalValue = parent[key];
|
|
791
|
+
if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
|
|
792
|
+
if (objectName(originalValue) !== 'Object') {
|
|
793
|
+
console.error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
|
|
794
|
+
} else {
|
|
795
|
+
console.error('Only plain objects can be passed to Server Functions from the Client. ' + 'Objects with toJSON methods are not supported. Convert it manually ' + 'to a simple value before passing it to props.%s', describeObjectForErrorMessage(parent, key));
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
if (value === null) {
|
|
800
|
+
return null;
|
|
801
|
+
}
|
|
802
|
+
if (typeof value === 'object') {
|
|
803
|
+
switch (value.$$typeof) {
|
|
804
|
+
case REACT_ELEMENT_TYPE:
|
|
805
|
+
{
|
|
806
|
+
if (temporaryReferences !== undefined && key.indexOf(':') === -1) {
|
|
807
|
+
// TODO: If the property name contains a colon, we don't dedupe. Escape instead.
|
|
808
|
+
var parentReference = writtenObjects.get(parent);
|
|
809
|
+
if (parentReference !== undefined) {
|
|
810
|
+
// If the parent has a reference, we can refer to this object indirectly
|
|
811
|
+
// through the property name inside that parent.
|
|
812
|
+
var reference = parentReference + ':' + key;
|
|
813
|
+
// Store this object so that the server can refer to it later in responses.
|
|
814
|
+
writeTemporaryReference(temporaryReferences, reference, value);
|
|
815
|
+
return serializeTemporaryReferenceMarker();
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
throw new Error('React Element cannot be passed to Server Functions from the Client without a ' + 'temporary reference set. Pass a TemporaryReferenceSet to the options.' + (describeObjectForErrorMessage(parent, key) ));
|
|
819
|
+
}
|
|
820
|
+
case REACT_LAZY_TYPE:
|
|
821
|
+
{
|
|
822
|
+
// Resolve lazy as if it wasn't here. In the future this will be encoded as a Promise.
|
|
823
|
+
var lazy = value;
|
|
824
|
+
var payload = lazy._payload;
|
|
825
|
+
var init = lazy._init;
|
|
826
|
+
if (formData === null) {
|
|
827
|
+
// Upgrade to use FormData to allow us to stream this value.
|
|
828
|
+
formData = new FormData();
|
|
829
|
+
}
|
|
830
|
+
pendingParts++;
|
|
831
|
+
try {
|
|
832
|
+
var resolvedModel = init(payload);
|
|
833
|
+
// We always outline this as a separate part even though we could inline it
|
|
834
|
+
// because it ensures a more deterministic encoding.
|
|
835
|
+
var lazyId = nextPartId++;
|
|
836
|
+
var partJSON = serializeModel(resolvedModel, lazyId);
|
|
837
|
+
// $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
|
838
|
+
var data = formData;
|
|
839
|
+
data.append(formFieldPrefix + lazyId, partJSON);
|
|
840
|
+
return serializeByValueID(lazyId);
|
|
841
|
+
} catch (x) {
|
|
842
|
+
if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
|
|
843
|
+
// Suspended
|
|
844
|
+
pendingParts++;
|
|
845
|
+
var _lazyId = nextPartId++;
|
|
846
|
+
var thenable = x;
|
|
847
|
+
var retry = function () {
|
|
848
|
+
// While the first promise resolved, its value isn't necessarily what we'll
|
|
849
|
+
// resolve into because we might suspend again.
|
|
850
|
+
try {
|
|
851
|
+
var _partJSON2 = serializeModel(value, _lazyId);
|
|
852
|
+
// $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
|
853
|
+
var _data = formData;
|
|
854
|
+
_data.append(formFieldPrefix + _lazyId, _partJSON2);
|
|
855
|
+
pendingParts--;
|
|
856
|
+
if (pendingParts === 0) {
|
|
857
|
+
resolve(_data);
|
|
858
|
+
}
|
|
859
|
+
} catch (reason) {
|
|
860
|
+
reject(reason);
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
thenable.then(retry, retry);
|
|
864
|
+
return serializeByValueID(_lazyId);
|
|
865
|
+
} else {
|
|
866
|
+
// In the future we could consider serializing this as an error
|
|
867
|
+
// that throws on the server instead.
|
|
868
|
+
reject(x);
|
|
869
|
+
return null;
|
|
870
|
+
}
|
|
871
|
+
} finally {
|
|
872
|
+
pendingParts--;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// $FlowFixMe[method-unbinding]
|
|
878
|
+
if (typeof value.then === 'function') {
|
|
879
|
+
// We assume that any object with a .then property is a "Thenable" type,
|
|
880
|
+
// or a Promise type. Either of which can be represented by a Promise.
|
|
881
|
+
if (formData === null) {
|
|
882
|
+
// Upgrade to use FormData to allow us to stream this value.
|
|
883
|
+
formData = new FormData();
|
|
884
|
+
}
|
|
885
|
+
pendingParts++;
|
|
886
|
+
var promiseId = nextPartId++;
|
|
887
|
+
var _thenable = value;
|
|
888
|
+
_thenable.then(function (partValue) {
|
|
889
|
+
try {
|
|
890
|
+
var _partJSON3 = serializeModel(partValue, promiseId);
|
|
891
|
+
// $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
|
892
|
+
var _data2 = formData;
|
|
893
|
+
_data2.append(formFieldPrefix + promiseId, _partJSON3);
|
|
894
|
+
pendingParts--;
|
|
895
|
+
if (pendingParts === 0) {
|
|
896
|
+
resolve(_data2);
|
|
897
|
+
}
|
|
898
|
+
} catch (reason) {
|
|
899
|
+
reject(reason);
|
|
900
|
+
}
|
|
901
|
+
},
|
|
902
|
+
// In the future we could consider serializing this as an error
|
|
903
|
+
// that throws on the server instead.
|
|
904
|
+
reject);
|
|
905
|
+
return serializePromiseID(promiseId);
|
|
906
|
+
}
|
|
907
|
+
var existingReference = writtenObjects.get(value);
|
|
908
|
+
if (existingReference !== undefined) {
|
|
909
|
+
if (modelRoot === value) {
|
|
910
|
+
// This is the ID we're currently emitting so we need to write it
|
|
911
|
+
// once but if we discover it again, we refer to it by id.
|
|
912
|
+
modelRoot = null;
|
|
913
|
+
} else {
|
|
914
|
+
// We've already emitted this as an outlined object, so we can
|
|
915
|
+
// just refer to that by its existing ID.
|
|
916
|
+
return existingReference;
|
|
917
|
+
}
|
|
918
|
+
} else if (key.indexOf(':') === -1) {
|
|
919
|
+
// TODO: If the property name contains a colon, we don't dedupe. Escape instead.
|
|
920
|
+
var _parentReference = writtenObjects.get(parent);
|
|
921
|
+
if (_parentReference !== undefined) {
|
|
922
|
+
// If the parent has a reference, we can refer to this object indirectly
|
|
923
|
+
// through the property name inside that parent.
|
|
924
|
+
var _reference = _parentReference + ':' + key;
|
|
925
|
+
writtenObjects.set(value, _reference);
|
|
926
|
+
if (temporaryReferences !== undefined) {
|
|
927
|
+
// Store this object so that the server can refer to it later in responses.
|
|
928
|
+
writeTemporaryReference(temporaryReferences, _reference, value);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
if (isArray(value)) {
|
|
933
|
+
// $FlowFixMe[incompatible-return]
|
|
934
|
+
return value;
|
|
935
|
+
}
|
|
936
|
+
// TODO: Should we the Object.prototype.toString.call() to test for cross-realm objects?
|
|
937
|
+
if (value instanceof FormData) {
|
|
938
|
+
if (formData === null) {
|
|
939
|
+
// Upgrade to use FormData to allow us to use rich objects as its values.
|
|
940
|
+
formData = new FormData();
|
|
941
|
+
}
|
|
942
|
+
var _data3 = formData;
|
|
943
|
+
var refId = nextPartId++;
|
|
944
|
+
// Copy all the form fields with a prefix for this reference.
|
|
945
|
+
// These must come first in the form order because we assume that all the
|
|
946
|
+
// fields are available before this is referenced.
|
|
947
|
+
var prefix = formFieldPrefix + refId + '_';
|
|
948
|
+
// $FlowFixMe[prop-missing]: FormData has forEach.
|
|
949
|
+
value.forEach(function (originalValue, originalKey) {
|
|
950
|
+
// $FlowFixMe[incompatible-call]
|
|
951
|
+
_data3.append(prefix + originalKey, originalValue);
|
|
952
|
+
});
|
|
953
|
+
return serializeFormDataReference(refId);
|
|
954
|
+
}
|
|
955
|
+
if (value instanceof Map) {
|
|
956
|
+
var mapId = nextPartId++;
|
|
957
|
+
var _partJSON4 = serializeModel(Array.from(value), mapId);
|
|
958
|
+
if (formData === null) {
|
|
959
|
+
formData = new FormData();
|
|
960
|
+
}
|
|
961
|
+
formData.append(formFieldPrefix + mapId, _partJSON4);
|
|
962
|
+
return serializeMapID(mapId);
|
|
963
|
+
}
|
|
964
|
+
if (value instanceof Set) {
|
|
965
|
+
var setId = nextPartId++;
|
|
966
|
+
var _partJSON5 = serializeModel(Array.from(value), setId);
|
|
967
|
+
if (formData === null) {
|
|
968
|
+
formData = new FormData();
|
|
969
|
+
}
|
|
970
|
+
formData.append(formFieldPrefix + setId, _partJSON5);
|
|
971
|
+
return serializeSetID(setId);
|
|
972
|
+
}
|
|
973
|
+
if (value instanceof ArrayBuffer) {
|
|
974
|
+
var blob = new Blob([value]);
|
|
975
|
+
var blobId = nextPartId++;
|
|
976
|
+
if (formData === null) {
|
|
977
|
+
formData = new FormData();
|
|
978
|
+
}
|
|
979
|
+
formData.append(formFieldPrefix + blobId, blob);
|
|
980
|
+
return '$' + 'A' + blobId.toString(16);
|
|
981
|
+
}
|
|
982
|
+
if (value instanceof Int8Array) {
|
|
983
|
+
// char
|
|
984
|
+
return serializeTypedArray('O', value);
|
|
985
|
+
}
|
|
986
|
+
if (value instanceof Uint8Array) {
|
|
987
|
+
// unsigned char
|
|
988
|
+
return serializeTypedArray('o', value);
|
|
989
|
+
}
|
|
990
|
+
if (value instanceof Uint8ClampedArray) {
|
|
991
|
+
// unsigned clamped char
|
|
992
|
+
return serializeTypedArray('U', value);
|
|
993
|
+
}
|
|
994
|
+
if (value instanceof Int16Array) {
|
|
995
|
+
// sort
|
|
996
|
+
return serializeTypedArray('S', value);
|
|
997
|
+
}
|
|
998
|
+
if (value instanceof Uint16Array) {
|
|
999
|
+
// unsigned short
|
|
1000
|
+
return serializeTypedArray('s', value);
|
|
1001
|
+
}
|
|
1002
|
+
if (value instanceof Int32Array) {
|
|
1003
|
+
// long
|
|
1004
|
+
return serializeTypedArray('L', value);
|
|
1005
|
+
}
|
|
1006
|
+
if (value instanceof Uint32Array) {
|
|
1007
|
+
// unsigned long
|
|
1008
|
+
return serializeTypedArray('l', value);
|
|
1009
|
+
}
|
|
1010
|
+
if (value instanceof Float32Array) {
|
|
1011
|
+
// float
|
|
1012
|
+
return serializeTypedArray('G', value);
|
|
1013
|
+
}
|
|
1014
|
+
if (value instanceof Float64Array) {
|
|
1015
|
+
// double
|
|
1016
|
+
return serializeTypedArray('g', value);
|
|
1017
|
+
}
|
|
1018
|
+
if (value instanceof BigInt64Array) {
|
|
1019
|
+
// number
|
|
1020
|
+
return serializeTypedArray('M', value);
|
|
1021
|
+
}
|
|
1022
|
+
if (value instanceof BigUint64Array) {
|
|
1023
|
+
// unsigned number
|
|
1024
|
+
// We use "m" instead of "n" since JSON can start with "null"
|
|
1025
|
+
return serializeTypedArray('m', value);
|
|
1026
|
+
}
|
|
1027
|
+
if (value instanceof DataView) {
|
|
1028
|
+
return serializeTypedArray('V', value);
|
|
1029
|
+
}
|
|
1030
|
+
// TODO: Blob is not available in old Node/browsers. Remove the typeof check later.
|
|
1031
|
+
if (typeof Blob === 'function' && value instanceof Blob) {
|
|
1032
|
+
if (formData === null) {
|
|
1033
|
+
formData = new FormData();
|
|
1034
|
+
}
|
|
1035
|
+
var _blobId = nextPartId++;
|
|
1036
|
+
formData.append(formFieldPrefix + _blobId, value);
|
|
1037
|
+
return serializeBlobID(_blobId);
|
|
1038
|
+
}
|
|
1039
|
+
var iteratorFn = getIteratorFn(value);
|
|
1040
|
+
if (iteratorFn) {
|
|
1041
|
+
var iterator = iteratorFn.call(value);
|
|
1042
|
+
if (iterator === value) {
|
|
1043
|
+
// Iterator, not Iterable
|
|
1044
|
+
var iteratorId = nextPartId++;
|
|
1045
|
+
var _partJSON6 = serializeModel(Array.from(iterator), iteratorId);
|
|
1046
|
+
if (formData === null) {
|
|
1047
|
+
formData = new FormData();
|
|
1048
|
+
}
|
|
1049
|
+
formData.append(formFieldPrefix + iteratorId, _partJSON6);
|
|
1050
|
+
return serializeIteratorID(iteratorId);
|
|
1051
|
+
}
|
|
1052
|
+
return Array.from(iterator);
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// TODO: ReadableStream is not available in old Node. Remove the typeof check later.
|
|
1056
|
+
if (typeof ReadableStream === 'function' && value instanceof ReadableStream) {
|
|
1057
|
+
return serializeReadableStream(value);
|
|
1058
|
+
}
|
|
1059
|
+
var getAsyncIterator = value[ASYNC_ITERATOR];
|
|
1060
|
+
if (typeof getAsyncIterator === 'function') {
|
|
1061
|
+
// We treat AsyncIterables as a Fragment and as such we might need to key them.
|
|
1062
|
+
return serializeAsyncIterable(value, getAsyncIterator.call(value));
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
// Verify that this is a simple plain object.
|
|
1066
|
+
var proto = getPrototypeOf(value);
|
|
1067
|
+
if (proto !== ObjectPrototype && (proto === null || getPrototypeOf(proto) !== null)) {
|
|
1068
|
+
if (temporaryReferences === undefined) {
|
|
1069
|
+
throw new Error('Only plain objects, and a few built-ins, can be passed to Server Functions. ' + 'Classes or null prototypes are not supported.' + (describeObjectForErrorMessage(parent, key) ));
|
|
1070
|
+
}
|
|
1071
|
+
// We will have written this object to the temporary reference set above
|
|
1072
|
+
// so we can replace it with a marker to refer to this slot later.
|
|
1073
|
+
return serializeTemporaryReferenceMarker();
|
|
1074
|
+
}
|
|
1075
|
+
{
|
|
1076
|
+
if (value.$$typeof === (REACT_CONTEXT_TYPE )) {
|
|
1077
|
+
console.error('React Context Providers cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
|
|
1078
|
+
} else if (objectName(value) !== 'Object') {
|
|
1079
|
+
console.error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
|
|
1080
|
+
} else if (!isSimpleObject(value)) {
|
|
1081
|
+
console.error('Only plain objects can be passed to Server Functions from the Client. ' + 'Classes or other objects with methods are not supported.%s', describeObjectForErrorMessage(parent, key));
|
|
1082
|
+
} else if (Object.getOwnPropertySymbols) {
|
|
1083
|
+
var symbols = Object.getOwnPropertySymbols(value);
|
|
1084
|
+
if (symbols.length > 0) {
|
|
1085
|
+
console.error('Only plain objects can be passed to Server Functions from the Client. ' + 'Objects with symbol properties like %s are not supported.%s', symbols[0].description, describeObjectForErrorMessage(parent, key));
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
// $FlowFixMe[incompatible-return]
|
|
1091
|
+
return value;
|
|
1092
|
+
}
|
|
1093
|
+
if (typeof value === 'string') {
|
|
1094
|
+
// TODO: Maybe too clever. If we support URL there's no similar trick.
|
|
1095
|
+
if (value[value.length - 1] === 'Z') {
|
|
1096
|
+
// Possibly a Date, whose toJSON automatically calls toISOString
|
|
1097
|
+
// $FlowFixMe[incompatible-use]
|
|
1098
|
+
var _originalValue = parent[key];
|
|
1099
|
+
if (_originalValue instanceof Date) {
|
|
1100
|
+
return serializeDateFromDateJSON(value);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
return escapeStringValue(value);
|
|
1104
|
+
}
|
|
1105
|
+
if (typeof value === 'boolean') {
|
|
1106
|
+
return value;
|
|
1107
|
+
}
|
|
1108
|
+
if (typeof value === 'number') {
|
|
1109
|
+
return serializeNumber(value);
|
|
1110
|
+
}
|
|
1111
|
+
if (typeof value === 'undefined') {
|
|
1112
|
+
return serializeUndefined();
|
|
1113
|
+
}
|
|
1114
|
+
if (typeof value === 'function') {
|
|
1115
|
+
var referenceClosure = knownServerReferences.get(value);
|
|
1116
|
+
if (referenceClosure !== undefined) {
|
|
1117
|
+
var id = referenceClosure.id,
|
|
1118
|
+
bound = referenceClosure.bound;
|
|
1119
|
+
var referenceClosureJSON = JSON.stringify({
|
|
1120
|
+
id: id,
|
|
1121
|
+
bound: bound
|
|
1122
|
+
}, resolveToJSON);
|
|
1123
|
+
if (formData === null) {
|
|
1124
|
+
// Upgrade to use FormData to allow us to stream this value.
|
|
1125
|
+
formData = new FormData();
|
|
1126
|
+
}
|
|
1127
|
+
// The reference to this function came from the same client so we can pass it back.
|
|
1128
|
+
var _refId = nextPartId++;
|
|
1129
|
+
formData.set(formFieldPrefix + _refId, referenceClosureJSON);
|
|
1130
|
+
return serializeServerReferenceID(_refId);
|
|
1131
|
+
}
|
|
1132
|
+
if (temporaryReferences !== undefined && key.indexOf(':') === -1) {
|
|
1133
|
+
// TODO: If the property name contains a colon, we don't dedupe. Escape instead.
|
|
1134
|
+
var _parentReference2 = writtenObjects.get(parent);
|
|
1135
|
+
if (_parentReference2 !== undefined) {
|
|
1136
|
+
// If the parent has a reference, we can refer to this object indirectly
|
|
1137
|
+
// through the property name inside that parent.
|
|
1138
|
+
var _reference2 = _parentReference2 + ':' + key;
|
|
1139
|
+
// Store this object so that the server can refer to it later in responses.
|
|
1140
|
+
writeTemporaryReference(temporaryReferences, _reference2, value);
|
|
1141
|
+
return serializeTemporaryReferenceMarker();
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
throw new Error('Client Functions cannot be passed directly to Server Functions. ' + 'Only Functions passed from the Server can be passed back again.');
|
|
1145
|
+
}
|
|
1146
|
+
if (typeof value === 'symbol') {
|
|
1147
|
+
if (temporaryReferences !== undefined && key.indexOf(':') === -1) {
|
|
1148
|
+
// TODO: If the property name contains a colon, we don't dedupe. Escape instead.
|
|
1149
|
+
var _parentReference3 = writtenObjects.get(parent);
|
|
1150
|
+
if (_parentReference3 !== undefined) {
|
|
1151
|
+
// If the parent has a reference, we can refer to this object indirectly
|
|
1152
|
+
// through the property name inside that parent.
|
|
1153
|
+
var _reference3 = _parentReference3 + ':' + key;
|
|
1154
|
+
// Store this object so that the server can refer to it later in responses.
|
|
1155
|
+
writeTemporaryReference(temporaryReferences, _reference3, value);
|
|
1156
|
+
return serializeTemporaryReferenceMarker();
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
throw new Error('Symbols cannot be passed to a Server Function without a ' + 'temporary reference set. Pass a TemporaryReferenceSet to the options.' + (describeObjectForErrorMessage(parent, key) ));
|
|
1160
|
+
}
|
|
1161
|
+
if (typeof value === 'bigint') {
|
|
1162
|
+
return serializeBigInt(value);
|
|
1163
|
+
}
|
|
1164
|
+
throw new Error("Type " + typeof value + " is not supported as an argument to a Server Function.");
|
|
1165
|
+
}
|
|
1166
|
+
function serializeModel(model, id) {
|
|
1167
|
+
if (typeof model === 'object' && model !== null) {
|
|
1168
|
+
var reference = serializeByValueID(id);
|
|
1169
|
+
writtenObjects.set(model, reference);
|
|
1170
|
+
if (temporaryReferences !== undefined) {
|
|
1171
|
+
// Store this object so that the server can refer to it later in responses.
|
|
1172
|
+
writeTemporaryReference(temporaryReferences, reference, model);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
modelRoot = model;
|
|
1176
|
+
// $FlowFixMe[incompatible-return] it's not going to be undefined because we'll encode it.
|
|
1177
|
+
return JSON.stringify(model, resolveToJSON);
|
|
1178
|
+
}
|
|
1179
|
+
function abort(reason) {
|
|
1180
|
+
if (pendingParts > 0) {
|
|
1181
|
+
pendingParts = 0; // Don't resolve again later.
|
|
1182
|
+
// Resolve with what we have so far, which may have holes at this point.
|
|
1183
|
+
// They'll error when the stream completes on the server.
|
|
1184
|
+
if (formData === null) {
|
|
1185
|
+
resolve(json);
|
|
1186
|
+
} else {
|
|
1187
|
+
resolve(formData);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
var json = serializeModel(root, 0);
|
|
1192
|
+
if (formData === null) {
|
|
1193
|
+
// If it's a simple data structure, we just use plain JSON.
|
|
1194
|
+
resolve(json);
|
|
1195
|
+
} else {
|
|
1196
|
+
// Otherwise, we use FormData to let us stream in the result.
|
|
1197
|
+
formData.set(formFieldPrefix + '0', json);
|
|
1198
|
+
if (pendingParts === 0) {
|
|
1199
|
+
// $FlowFixMe[incompatible-call] this has already been refined.
|
|
1200
|
+
resolve(formData);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
return abort;
|
|
1204
|
+
}
|
|
1205
|
+
var fakeServerFunctionIdx = 0;
|
|
1206
|
+
function createFakeServerFunction(name, filename, sourceMap, line, col, environmentName, innerFunction) {
|
|
1207
|
+
// This creates a fake copy of a Server Module. It represents the Server Action on the server.
|
|
1208
|
+
// We use an eval so we can source map it to the original location.
|
|
1209
|
+
|
|
1210
|
+
var comment = '/* This module is a proxy to a Server Action. Turn on Source Maps to see the server source. */';
|
|
1211
|
+
if (!name) {
|
|
1212
|
+
// An eval:ed function with no name gets the name "eval". We give it something more descriptive.
|
|
1213
|
+
name = '<anonymous>';
|
|
1214
|
+
}
|
|
1215
|
+
var encodedName = JSON.stringify(name);
|
|
1216
|
+
// We generate code where both the beginning of the function and its parenthesis is at the line
|
|
1217
|
+
// and column of the server executed code. We use a method form since that lets us name it
|
|
1218
|
+
// anything we want and because the beginning of the function and its parenthesis is the same
|
|
1219
|
+
// column. Because Chrome inspects the location of the parenthesis and Firefox inspects the
|
|
1220
|
+
// location of the beginning of the function. By not using a function expression we avoid the
|
|
1221
|
+
// ambiguity.
|
|
1222
|
+
var code;
|
|
1223
|
+
if (line <= 1) {
|
|
1224
|
+
var minSize = encodedName.length + 7;
|
|
1225
|
+
code = 's=>({' + encodedName + ' '.repeat(col < minSize ? 0 : col - minSize) + ':' + '(...args) => s(...args)' + '})\n' + comment;
|
|
1226
|
+
} else {
|
|
1227
|
+
code = comment + '\n'.repeat(line - 2) + 'server=>({' + encodedName + ':\n' + ' '.repeat(col < 1 ? 0 : col - 1) +
|
|
1228
|
+
// The function body can get printed so we make it look nice.
|
|
1229
|
+
// This "calls the server with the arguments".
|
|
1230
|
+
'(...args) => server(...args)' + '})';
|
|
1231
|
+
}
|
|
1232
|
+
if (filename.startsWith('/')) {
|
|
1233
|
+
// If the filename starts with `/` we assume that it is a file system file
|
|
1234
|
+
// rather than relative to the current host. Since on the server fully qualified
|
|
1235
|
+
// stack traces use the file path.
|
|
1236
|
+
// TODO: What does this look like on Windows?
|
|
1237
|
+
filename = 'file://' + filename;
|
|
1238
|
+
}
|
|
1239
|
+
if (sourceMap) {
|
|
1240
|
+
// We use the prefix rsc://React/ to separate these from other files listed in
|
|
1241
|
+
// the Chrome DevTools. We need a "host name" and not just a protocol because
|
|
1242
|
+
// otherwise the group name becomes the root folder. Ideally we don't want to
|
|
1243
|
+
// show these at all but there's two reasons to assign a fake URL.
|
|
1244
|
+
// 1) A printed stack trace string needs a unique URL to be able to source map it.
|
|
1245
|
+
// 2) If source maps are disabled or fails, you should at least be able to tell
|
|
1246
|
+
// which file it was.
|
|
1247
|
+
code += '\n//# sourceURL=rsc://React/' + encodeURIComponent(environmentName) + '/' + filename + '?s' +
|
|
1248
|
+
// We add an extra s here to distinguish from the fake stack frames
|
|
1249
|
+
fakeServerFunctionIdx++;
|
|
1250
|
+
code += '\n//# sourceMappingURL=' + sourceMap;
|
|
1251
|
+
} else if (filename) {
|
|
1252
|
+
code += '\n//# sourceURL=' + filename;
|
|
1253
|
+
}
|
|
1254
|
+
try {
|
|
1255
|
+
// Eval a factory and then call it to create a closure over the inner function.
|
|
1256
|
+
|
|
1257
|
+
return (0, eval)(code)(innerFunction)[name];
|
|
1258
|
+
} catch (x) {
|
|
1259
|
+
// If eval fails, such as if in an environment that doesn't support it,
|
|
1260
|
+
// we fallback to just returning the inner function.
|
|
1261
|
+
return innerFunction;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
function registerBoundServerReference(reference, id, bound, encodeFormAction) {
|
|
1265
|
+
if (knownServerReferences.has(reference)) {
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
knownServerReferences.set(reference, {
|
|
1269
|
+
id: id,
|
|
1270
|
+
originalBind: reference.bind,
|
|
1271
|
+
bound: bound
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
function registerServerReference(reference, id, encodeFormAction) {
|
|
1275
|
+
registerBoundServerReference(reference, id, null);
|
|
1276
|
+
return reference;
|
|
1277
|
+
}
|
|
1278
|
+
function createBoundServerReference(metaData, callServer, encodeFormAction, findSourceMapURL // DEV-only
|
|
1279
|
+
) {
|
|
1280
|
+
var id = metaData.id;
|
|
1281
|
+
var bound = metaData.bound;
|
|
1282
|
+
var action = function () {
|
|
1283
|
+
// $FlowFixMe[method-unbinding]
|
|
1284
|
+
var args = Array.prototype.slice.call(arguments);
|
|
1285
|
+
var p = bound;
|
|
1286
|
+
if (!p) {
|
|
1287
|
+
return callServer(id, args);
|
|
1288
|
+
}
|
|
1289
|
+
if (p.status === 'fulfilled') {
|
|
1290
|
+
var boundArgs = p.value;
|
|
1291
|
+
return callServer(id, boundArgs.concat(args));
|
|
1292
|
+
}
|
|
1293
|
+
// Since this is a fake Promise whose .then doesn't chain, we have to wrap it.
|
|
1294
|
+
// TODO: Remove the wrapper once that's fixed.
|
|
1295
|
+
return Promise.resolve(p).then(function (boundArgs) {
|
|
1296
|
+
return callServer(id, boundArgs.concat(args));
|
|
1297
|
+
});
|
|
1298
|
+
};
|
|
1299
|
+
{
|
|
1300
|
+
var location = metaData.location;
|
|
1301
|
+
if (location) {
|
|
1302
|
+
var functionName = metaData.name || '';
|
|
1303
|
+
var filename = location[1],
|
|
1304
|
+
line = location[2],
|
|
1305
|
+
col = location[3];
|
|
1306
|
+
var env = metaData.env || 'Server';
|
|
1307
|
+
var sourceMap = findSourceMapURL == null ? null : findSourceMapURL(filename, env);
|
|
1308
|
+
action = createFakeServerFunction(functionName, filename, sourceMap, line, col, env, action);
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
registerBoundServerReference(action, id, bound);
|
|
1312
|
+
return action;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
// This matches either of these V8 formats.
|
|
1316
|
+
// at name (filename:0:0)
|
|
1317
|
+
// at filename:0:0
|
|
1318
|
+
// at async filename:0:0
|
|
1319
|
+
var v8FrameRegExp = /^ {3} at (?:(.+) \((.+):(\d+):(\d+)\)|(?:async )?(.+):(\d+):(\d+))$/;
|
|
1320
|
+
// This matches either of these JSC/SpiderMonkey formats.
|
|
1321
|
+
// name@filename:0:0
|
|
1322
|
+
// filename:0:0
|
|
1323
|
+
var jscSpiderMonkeyFrameRegExp = /(?:(.*)@)?(.*):(\d+):(\d+)/;
|
|
1324
|
+
function parseStackLocation(error) {
|
|
1325
|
+
// This parsing is special in that we know that the calling function will always
|
|
1326
|
+
// be a module that initializes the server action. We also need this part to work
|
|
1327
|
+
// cross-browser so not worth a Config. It's DEV only so not super code size
|
|
1328
|
+
// sensitive but also a non-essential feature.
|
|
1329
|
+
var stack = error.stack;
|
|
1330
|
+
if (stack.startsWith('Error: react-stack-top-frame\n')) {
|
|
1331
|
+
// V8's default formatting prefixes with the error message which we
|
|
1332
|
+
// don't want/need.
|
|
1333
|
+
stack = stack.slice(29);
|
|
1334
|
+
}
|
|
1335
|
+
var endOfFirst = stack.indexOf('\n');
|
|
1336
|
+
var secondFrame;
|
|
1337
|
+
if (endOfFirst !== -1) {
|
|
1338
|
+
// Skip the first frame.
|
|
1339
|
+
var endOfSecond = stack.indexOf('\n', endOfFirst + 1);
|
|
1340
|
+
if (endOfSecond === -1) {
|
|
1341
|
+
secondFrame = stack.slice(endOfFirst + 1);
|
|
1342
|
+
} else {
|
|
1343
|
+
secondFrame = stack.slice(endOfFirst + 1, endOfSecond);
|
|
1344
|
+
}
|
|
1345
|
+
} else {
|
|
1346
|
+
secondFrame = stack;
|
|
1347
|
+
}
|
|
1348
|
+
var parsed = v8FrameRegExp.exec(secondFrame);
|
|
1349
|
+
if (!parsed) {
|
|
1350
|
+
parsed = jscSpiderMonkeyFrameRegExp.exec(secondFrame);
|
|
1351
|
+
if (!parsed) {
|
|
1352
|
+
return null;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
var name = parsed[1] || '';
|
|
1356
|
+
if (name === '<anonymous>') {
|
|
1357
|
+
name = '';
|
|
1358
|
+
}
|
|
1359
|
+
var filename = parsed[2] || parsed[5] || '';
|
|
1360
|
+
if (filename === '<anonymous>') {
|
|
1361
|
+
filename = '';
|
|
1362
|
+
}
|
|
1363
|
+
var line = +(parsed[3] || parsed[6]);
|
|
1364
|
+
var col = +(parsed[4] || parsed[7]);
|
|
1365
|
+
return [name, filename, line, col];
|
|
1366
|
+
}
|
|
1367
|
+
function createServerReference(id, callServer, encodeFormAction, findSourceMapURL,
|
|
1368
|
+
// DEV-only
|
|
1369
|
+
functionName) {
|
|
1370
|
+
var action = function () {
|
|
1371
|
+
// $FlowFixMe[method-unbinding]
|
|
1372
|
+
var args = Array.prototype.slice.call(arguments);
|
|
1373
|
+
return callServer(id, args);
|
|
1374
|
+
};
|
|
1375
|
+
{
|
|
1376
|
+
// Let's see if we can find a source map for the file which contained the
|
|
1377
|
+
// server action. We extract it from the runtime so that it's resilient to
|
|
1378
|
+
// multiple passes of compilation as long as we can find the final source map.
|
|
1379
|
+
var location = parseStackLocation(new Error('react-stack-top-frame'));
|
|
1380
|
+
if (location !== null) {
|
|
1381
|
+
var filename = location[1],
|
|
1382
|
+
line = location[2],
|
|
1383
|
+
col = location[3];
|
|
1384
|
+
// While the environment that the Server Reference points to can be
|
|
1385
|
+
// in any environment, what matters here is where the compiled source
|
|
1386
|
+
// is from and that's in the currently executing environment. We hard
|
|
1387
|
+
// code that as the value "Client" in case the findSourceMapURL helper
|
|
1388
|
+
// needs it.
|
|
1389
|
+
var env = 'Client';
|
|
1390
|
+
var sourceMap = findSourceMapURL == null ? null : findSourceMapURL(filename, env);
|
|
1391
|
+
action = createFakeServerFunction(functionName || '', filename, sourceMap, line, col, env, action);
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
registerBoundServerReference(action, id, null);
|
|
1395
|
+
return action;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
/* eslint-disable react-internal/no-production-logging */
|
|
1399
|
+
|
|
1400
|
+
var supportsUserTiming = typeof console !== 'undefined' && typeof console.timeStamp === 'function';
|
|
1401
|
+
var COMPONENTS_TRACK = 'Server Components ⚛';
|
|
1402
|
+
function markAllTracksInOrder() {
|
|
1403
|
+
if (supportsUserTiming) {
|
|
1404
|
+
// Ensure we create the Server Component track groups earlier than the Client Scheduler
|
|
1405
|
+
// and Client Components. We can always add the 0 time slot even if it's in the past.
|
|
1406
|
+
// That's still considered for ordering.
|
|
1407
|
+
console.timeStamp('Server Components Track', 0.001, 0.001, 'Primary', COMPONENTS_TRACK, 'primary-light');
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
var trackNames = ['Primary', 'Parallel', "Parallel\u200B",
|
|
1411
|
+
// Padded with zero-width space to give each track a unique name.
|
|
1412
|
+
"Parallel\u200B\u200B", "Parallel\u200B\u200B\u200B", "Parallel\u200B\u200B\u200B\u200B", "Parallel\u200B\u200B\u200B\u200B\u200B", "Parallel\u200B\u200B\u200B\u200B\u200B\u200B", "Parallel\u200B\u200B\u200B\u200B\u200B\u200B\u200B", "Parallel\u200B\u200B\u200B\u200B\u200B\u200B\u200B\u200B"];
|
|
1413
|
+
function logComponentRender(componentInfo, trackIdx, startTime, endTime, childrenEndTime, rootEnv) {
|
|
1414
|
+
if (supportsUserTiming && childrenEndTime >= 0 && trackIdx < 10) {
|
|
1415
|
+
var env = componentInfo.env;
|
|
1416
|
+
var name = componentInfo.name;
|
|
1417
|
+
var isPrimaryEnv = env === rootEnv;
|
|
1418
|
+
var selfTime = endTime - startTime;
|
|
1419
|
+
var color = selfTime < 0.5 ? isPrimaryEnv ? 'primary-light' : 'secondary-light' : selfTime < 50 ? isPrimaryEnv ? 'primary' : 'secondary' : selfTime < 500 ? isPrimaryEnv ? 'primary-dark' : 'secondary-dark' : 'error';
|
|
1420
|
+
var entryName = isPrimaryEnv || env === undefined ? name : name + ' [' + env + ']';
|
|
1421
|
+
var debugTask = componentInfo.debugTask;
|
|
1422
|
+
if (debugTask) {
|
|
1423
|
+
debugTask.run(
|
|
1424
|
+
// $FlowFixMe[method-unbinding]
|
|
1425
|
+
console.timeStamp.bind(console, entryName, startTime < 0 ? 0 : startTime, childrenEndTime, trackNames[trackIdx], COMPONENTS_TRACK, color));
|
|
1426
|
+
} else {
|
|
1427
|
+
console.timeStamp(entryName, startTime < 0 ? 0 : startTime, childrenEndTime, trackNames[trackIdx], COMPONENTS_TRACK, color);
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
function logComponentErrored(componentInfo, trackIdx, startTime, endTime, childrenEndTime, rootEnv, error) {
|
|
1432
|
+
if (supportsUserTiming) {
|
|
1433
|
+
var env = componentInfo.env;
|
|
1434
|
+
var name = componentInfo.name;
|
|
1435
|
+
var isPrimaryEnv = env === rootEnv;
|
|
1436
|
+
var entryName = isPrimaryEnv || env === undefined ? name : name + ' [' + env + ']';
|
|
1437
|
+
if (typeof performance !== 'undefined' &&
|
|
1438
|
+
// $FlowFixMe[method-unbinding]
|
|
1439
|
+
typeof performance.measure === 'function') {
|
|
1440
|
+
var message = typeof error === 'object' && error !== null && typeof error.message === 'string' ?
|
|
1441
|
+
// eslint-disable-next-line react-internal/safe-string-coercion
|
|
1442
|
+
String(error.message) :
|
|
1443
|
+
// eslint-disable-next-line react-internal/safe-string-coercion
|
|
1444
|
+
String(error);
|
|
1445
|
+
var properties = [['Error', message]];
|
|
1446
|
+
performance.measure(entryName, {
|
|
1447
|
+
start: startTime < 0 ? 0 : startTime,
|
|
1448
|
+
end: childrenEndTime,
|
|
1449
|
+
detail: {
|
|
1450
|
+
devtools: {
|
|
1451
|
+
color: 'error',
|
|
1452
|
+
track: trackNames[trackIdx],
|
|
1453
|
+
trackGroup: COMPONENTS_TRACK,
|
|
1454
|
+
tooltipText: entryName + ' Errored',
|
|
1455
|
+
properties: properties
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
} else {
|
|
1460
|
+
console.timeStamp(entryName, startTime < 0 ? 0 : startTime, childrenEndTime, trackNames[trackIdx], COMPONENTS_TRACK, 'error');
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
function logDedupedComponentRender(componentInfo, trackIdx, startTime, endTime) {
|
|
1465
|
+
if (supportsUserTiming && endTime >= 0 && trackIdx < 10) {
|
|
1466
|
+
var name = componentInfo.name;
|
|
1467
|
+
var entryName = name + ' [deduped]';
|
|
1468
|
+
var debugTask = componentInfo.debugTask;
|
|
1469
|
+
if (debugTask) {
|
|
1470
|
+
debugTask.run(
|
|
1471
|
+
// $FlowFixMe[method-unbinding]
|
|
1472
|
+
console.timeStamp.bind(console, entryName, startTime < 0 ? 0 : startTime, endTime, trackNames[trackIdx], COMPONENTS_TRACK, 'tertiary-light'));
|
|
1473
|
+
} else {
|
|
1474
|
+
console.timeStamp(entryName, startTime < 0 ? 0 : startTime, endTime, trackNames[trackIdx], COMPONENTS_TRACK, 'tertiary-light');
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
// Keep in sync with react-reconciler/getComponentNameFromFiber
|
|
1480
|
+
function getWrappedName(outerType, innerType, wrapperName) {
|
|
1481
|
+
var displayName = outerType.displayName;
|
|
1482
|
+
if (displayName) {
|
|
1483
|
+
return displayName;
|
|
1484
|
+
}
|
|
1485
|
+
var functionName = innerType.displayName || innerType.name || '';
|
|
1486
|
+
return functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
// Keep in sync with react-reconciler/getComponentNameFromFiber
|
|
1490
|
+
function getContextName(type) {
|
|
1491
|
+
return type.displayName || 'Context';
|
|
1492
|
+
}
|
|
1493
|
+
var REACT_CLIENT_REFERENCE = Symbol.for('react.client.reference');
|
|
1494
|
+
|
|
1495
|
+
// Note that the reconciler package should generally prefer to use getComponentNameFromFiber() instead.
|
|
1496
|
+
function getComponentNameFromType(type) {
|
|
1497
|
+
if (type == null) {
|
|
1498
|
+
// Host root, text node or just invalid type.
|
|
1499
|
+
return null;
|
|
1500
|
+
}
|
|
1501
|
+
if (typeof type === 'function') {
|
|
1502
|
+
if (type.$$typeof === REACT_CLIENT_REFERENCE) {
|
|
1503
|
+
// TODO: Create a convention for naming client references with debug info.
|
|
1504
|
+
return null;
|
|
1505
|
+
}
|
|
1506
|
+
return type.displayName || type.name || null;
|
|
1507
|
+
}
|
|
1508
|
+
if (typeof type === 'string') {
|
|
1509
|
+
return type;
|
|
1510
|
+
}
|
|
1511
|
+
switch (type) {
|
|
1512
|
+
case REACT_FRAGMENT_TYPE:
|
|
1513
|
+
return 'Fragment';
|
|
1514
|
+
case REACT_PROFILER_TYPE:
|
|
1515
|
+
return 'Profiler';
|
|
1516
|
+
case REACT_STRICT_MODE_TYPE:
|
|
1517
|
+
return 'StrictMode';
|
|
1518
|
+
case REACT_SUSPENSE_TYPE:
|
|
1519
|
+
return 'Suspense';
|
|
1520
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
|
1521
|
+
return 'SuspenseList';
|
|
1522
|
+
case REACT_ACTIVITY_TYPE:
|
|
1523
|
+
return 'Activity';
|
|
1524
|
+
case REACT_VIEW_TRANSITION_TYPE:
|
|
1525
|
+
{
|
|
1526
|
+
return 'ViewTransition';
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
if (typeof type === 'object') {
|
|
1530
|
+
{
|
|
1531
|
+
if (typeof type.tag === 'number') {
|
|
1532
|
+
console.error('Received an unexpected object in getComponentNameFromType(). ' + 'This is likely a bug in React. Please file an issue.');
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
switch (type.$$typeof) {
|
|
1536
|
+
case REACT_PORTAL_TYPE:
|
|
1537
|
+
return 'Portal';
|
|
1538
|
+
case REACT_PROVIDER_TYPE:
|
|
1539
|
+
{
|
|
1540
|
+
return null;
|
|
1541
|
+
}
|
|
1542
|
+
case REACT_CONTEXT_TYPE:
|
|
1543
|
+
var context = type;
|
|
1544
|
+
{
|
|
1545
|
+
return getContextName(context) + '.Provider';
|
|
1546
|
+
}
|
|
1547
|
+
case REACT_CONSUMER_TYPE:
|
|
1548
|
+
{
|
|
1549
|
+
var consumer = type;
|
|
1550
|
+
return getContextName(consumer._context) + '.Consumer';
|
|
1551
|
+
}
|
|
1552
|
+
case REACT_FORWARD_REF_TYPE:
|
|
1553
|
+
return getWrappedName(type, type.render, 'ForwardRef');
|
|
1554
|
+
case REACT_MEMO_TYPE:
|
|
1555
|
+
var outerName = type.displayName || null;
|
|
1556
|
+
if (outerName !== null) {
|
|
1557
|
+
return outerName;
|
|
1558
|
+
}
|
|
1559
|
+
return getComponentNameFromType(type.type) || 'Memo';
|
|
1560
|
+
case REACT_LAZY_TYPE:
|
|
1561
|
+
{
|
|
1562
|
+
var lazyComponent = type;
|
|
1563
|
+
var payload = lazyComponent._payload;
|
|
1564
|
+
var init = lazyComponent._init;
|
|
1565
|
+
try {
|
|
1566
|
+
return getComponentNameFromType(init(payload));
|
|
1567
|
+
} catch (x) {
|
|
1568
|
+
return null;
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
return null;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
// This is forked in server builds where the default stack frame may be source mapped.
|
|
1577
|
+
|
|
1578
|
+
var DefaultPrepareStackTrace = undefined;
|
|
1579
|
+
|
|
1580
|
+
var prefix;
|
|
1581
|
+
var suffix;
|
|
1582
|
+
function describeBuiltInComponentFrame(name) {
|
|
1583
|
+
if (prefix === undefined) {
|
|
1584
|
+
// Extract the VM specific prefix used by each line.
|
|
1585
|
+
try {
|
|
1586
|
+
throw Error();
|
|
1587
|
+
} catch (x) {
|
|
1588
|
+
var match = x.stack.trim().match(/\n( *(at )?)/);
|
|
1589
|
+
prefix = match && match[1] || '';
|
|
1590
|
+
suffix = x.stack.indexOf('\n at') > -1 ?
|
|
1591
|
+
// V8
|
|
1592
|
+
' (<anonymous>)' :
|
|
1593
|
+
// JSC/Spidermonkey
|
|
1594
|
+
x.stack.indexOf('@') > -1 ? '@unknown:0:0' :
|
|
1595
|
+
// Other
|
|
1596
|
+
'';
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
// We use the prefix to ensure our stacks line up with native stack frames.
|
|
1600
|
+
return '\n' + prefix + name + suffix;
|
|
1601
|
+
}
|
|
1602
|
+
{
|
|
1603
|
+
var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
|
|
1604
|
+
new PossiblyWeakMap();
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
function formatOwnerStack(error) {
|
|
1608
|
+
var prevPrepareStackTrace = Error.prepareStackTrace;
|
|
1609
|
+
Error.prepareStackTrace = DefaultPrepareStackTrace;
|
|
1610
|
+
var stack = error.stack;
|
|
1611
|
+
Error.prepareStackTrace = prevPrepareStackTrace;
|
|
1612
|
+
if (stack.startsWith('Error: react-stack-top-frame\n')) {
|
|
1613
|
+
// V8's default formatting prefixes with the error message which we
|
|
1614
|
+
// don't want/need.
|
|
1615
|
+
stack = stack.slice(29);
|
|
1616
|
+
}
|
|
1617
|
+
var idx = stack.indexOf('\n');
|
|
1618
|
+
if (idx !== -1) {
|
|
1619
|
+
// Pop the JSX frame.
|
|
1620
|
+
stack = stack.slice(idx + 1);
|
|
1621
|
+
}
|
|
1622
|
+
idx = stack.indexOf('react-stack-bottom-frame');
|
|
1623
|
+
if (idx !== -1) {
|
|
1624
|
+
idx = stack.lastIndexOf('\n', idx);
|
|
1625
|
+
}
|
|
1626
|
+
if (idx !== -1) {
|
|
1627
|
+
// Cut off everything after the bottom frame since it'll be internals.
|
|
1628
|
+
stack = stack.slice(0, idx);
|
|
1629
|
+
} else {
|
|
1630
|
+
// We didn't find any internal callsite out to user space.
|
|
1631
|
+
// This means that this was called outside an owner or the owner is fully internal.
|
|
1632
|
+
// To keep things light we exclude the entire trace in this case.
|
|
1633
|
+
return '';
|
|
1634
|
+
}
|
|
1635
|
+
return stack;
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
function getOwnerStackByComponentInfoInDev(componentInfo) {
|
|
1639
|
+
try {
|
|
1640
|
+
var info = '';
|
|
1641
|
+
|
|
1642
|
+
// The owner stack of the current component will be where it was created, i.e. inside its owner.
|
|
1643
|
+
// There's no actual name of the currently executing component. Instead, that is available
|
|
1644
|
+
// on the regular stack that's currently executing. However, if there is no owner at all, then
|
|
1645
|
+
// there's no stack frame so we add the name of the root component to the stack to know which
|
|
1646
|
+
// component is currently executing.
|
|
1647
|
+
if (!componentInfo.owner && typeof componentInfo.name === 'string') {
|
|
1648
|
+
return describeBuiltInComponentFrame(componentInfo.name);
|
|
1649
|
+
}
|
|
1650
|
+
var owner = componentInfo;
|
|
1651
|
+
while (owner) {
|
|
1652
|
+
var ownerStack = owner.debugStack;
|
|
1653
|
+
if (ownerStack != null) {
|
|
1654
|
+
// Server Component
|
|
1655
|
+
owner = owner.owner;
|
|
1656
|
+
if (owner) {
|
|
1657
|
+
// TODO: Should we stash this somewhere for caching purposes?
|
|
1658
|
+
info += '\n' + formatOwnerStack(ownerStack);
|
|
1659
|
+
}
|
|
1660
|
+
} else {
|
|
1661
|
+
break;
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
return info;
|
|
1665
|
+
} catch (x) {
|
|
1666
|
+
return '\nError generating stack: ' + x.message + '\n' + x.stack;
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
function injectInternals(internals) {
|
|
1671
|
+
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
|
|
1672
|
+
// No DevTools
|
|
1673
|
+
return false;
|
|
1674
|
+
}
|
|
1675
|
+
var hook = __REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
1676
|
+
if (hook.isDisabled) {
|
|
1677
|
+
// This isn't a real property on the hook, but it can be set to opt out
|
|
1678
|
+
// of DevTools integration and associated warnings and logs.
|
|
1679
|
+
// https://github.com/facebook/react/issues/3877
|
|
1680
|
+
return true;
|
|
1681
|
+
}
|
|
1682
|
+
if (!hook.supportsFlight) {
|
|
1683
|
+
// DevTools exists, even though it doesn't support Flight.
|
|
1684
|
+
return true;
|
|
1685
|
+
}
|
|
1686
|
+
try {
|
|
1687
|
+
hook.inject(internals);
|
|
1688
|
+
} catch (err) {
|
|
1689
|
+
// Catch all errors because it is unsafe to throw during initialization.
|
|
1690
|
+
{
|
|
1691
|
+
console.error('React instrumentation encountered an error: %s.', err);
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
if (hook.checkDCE) {
|
|
1695
|
+
// This is the real DevTools.
|
|
1696
|
+
return true;
|
|
1697
|
+
} else {
|
|
1698
|
+
// This is likely a hook installed by Fast Refresh runtime.
|
|
1699
|
+
return false;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
// TODO: This is an unfortunate hack. We shouldn't feature detect the internals
|
|
1704
|
+
// like this. It's just that for now we support the same build of the Flight
|
|
1705
|
+
// client both in the RSC environment, in the SSR environments as well as the
|
|
1706
|
+
// browser client. We should probably have a separate RSC build. This is DEV
|
|
1707
|
+
// only though.
|
|
1708
|
+
var ReactSharedInteralsServer = React.__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
|
1709
|
+
var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE || ReactSharedInteralsServer;
|
|
1710
|
+
var ROW_ID = 0;
|
|
1711
|
+
var ROW_TAG = 1;
|
|
1712
|
+
var ROW_LENGTH = 2;
|
|
1713
|
+
var ROW_CHUNK_BY_NEWLINE = 3;
|
|
1714
|
+
var ROW_CHUNK_BY_LENGTH = 4;
|
|
1715
|
+
var PENDING = 'pending';
|
|
1716
|
+
var BLOCKED = 'blocked';
|
|
1717
|
+
var RESOLVED_MODEL = 'resolved_model';
|
|
1718
|
+
var RESOLVED_MODULE = 'resolved_module';
|
|
1719
|
+
var INITIALIZED = 'fulfilled';
|
|
1720
|
+
var ERRORED = 'rejected';
|
|
1721
|
+
|
|
1722
|
+
// $FlowFixMe[missing-this-annot]
|
|
1723
|
+
function ReactPromise(status, value, reason, response) {
|
|
1724
|
+
this.status = status;
|
|
1725
|
+
this.value = value;
|
|
1726
|
+
this.reason = reason;
|
|
1727
|
+
this._response = response;
|
|
1728
|
+
{
|
|
1729
|
+
this._children = [];
|
|
1730
|
+
}
|
|
1731
|
+
{
|
|
1732
|
+
this._debugInfo = null;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
// We subclass Promise.prototype so that we get other methods like .catch
|
|
1736
|
+
ReactPromise.prototype = Object.create(Promise.prototype);
|
|
1737
|
+
// TODO: This doesn't return a new Promise chain unlike the real .then
|
|
1738
|
+
ReactPromise.prototype.then = function (resolve, reject) {
|
|
1739
|
+
var chunk = this;
|
|
1740
|
+
// If we have resolved content, we try to initialize it first which
|
|
1741
|
+
// might put us back into one of the other states.
|
|
1742
|
+
switch (chunk.status) {
|
|
1743
|
+
case RESOLVED_MODEL:
|
|
1744
|
+
initializeModelChunk(chunk);
|
|
1745
|
+
break;
|
|
1746
|
+
case RESOLVED_MODULE:
|
|
1747
|
+
initializeModuleChunk(chunk);
|
|
1748
|
+
break;
|
|
1749
|
+
}
|
|
1750
|
+
// The status might have changed after initialization.
|
|
1751
|
+
switch (chunk.status) {
|
|
1752
|
+
case INITIALIZED:
|
|
1753
|
+
resolve(chunk.value);
|
|
1754
|
+
break;
|
|
1755
|
+
case PENDING:
|
|
1756
|
+
case BLOCKED:
|
|
1757
|
+
if (resolve) {
|
|
1758
|
+
if (chunk.value === null) {
|
|
1759
|
+
chunk.value = [];
|
|
1760
|
+
}
|
|
1761
|
+
chunk.value.push(resolve);
|
|
1762
|
+
}
|
|
1763
|
+
if (reject) {
|
|
1764
|
+
if (chunk.reason === null) {
|
|
1765
|
+
chunk.reason = [];
|
|
1766
|
+
}
|
|
1767
|
+
chunk.reason.push(reject);
|
|
1768
|
+
}
|
|
1769
|
+
break;
|
|
1770
|
+
default:
|
|
1771
|
+
if (reject) {
|
|
1772
|
+
reject(chunk.reason);
|
|
1773
|
+
}
|
|
1774
|
+
break;
|
|
1775
|
+
}
|
|
1776
|
+
};
|
|
1777
|
+
function readChunk(chunk) {
|
|
1778
|
+
// If we have resolved content, we try to initialize it first which
|
|
1779
|
+
// might put us back into one of the other states.
|
|
1780
|
+
switch (chunk.status) {
|
|
1781
|
+
case RESOLVED_MODEL:
|
|
1782
|
+
initializeModelChunk(chunk);
|
|
1783
|
+
break;
|
|
1784
|
+
case RESOLVED_MODULE:
|
|
1785
|
+
initializeModuleChunk(chunk);
|
|
1786
|
+
break;
|
|
1787
|
+
}
|
|
1788
|
+
// The status might have changed after initialization.
|
|
1789
|
+
switch (chunk.status) {
|
|
1790
|
+
case INITIALIZED:
|
|
1791
|
+
return chunk.value;
|
|
1792
|
+
case PENDING:
|
|
1793
|
+
case BLOCKED:
|
|
1794
|
+
|
|
1795
|
+
throw chunk;
|
|
1796
|
+
default:
|
|
1797
|
+
throw chunk.reason;
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
function getRoot(response) {
|
|
1801
|
+
var chunk = getChunk(response, 0);
|
|
1802
|
+
return chunk;
|
|
1803
|
+
}
|
|
1804
|
+
function createPendingChunk(response) {
|
|
1805
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
|
1806
|
+
return new ReactPromise(PENDING, null, null, response);
|
|
1807
|
+
}
|
|
1808
|
+
function createBlockedChunk(response) {
|
|
1809
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
|
1810
|
+
return new ReactPromise(BLOCKED, null, null, response);
|
|
1811
|
+
}
|
|
1812
|
+
function createErrorChunk(response, error) {
|
|
1813
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
|
1814
|
+
return new ReactPromise(ERRORED, null, error, response);
|
|
1815
|
+
}
|
|
1816
|
+
function wakeChunk(listeners, value) {
|
|
1817
|
+
for (var i = 0; i < listeners.length; i++) {
|
|
1818
|
+
var listener = listeners[i];
|
|
1819
|
+
listener(value);
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
|
|
1823
|
+
switch (chunk.status) {
|
|
1824
|
+
case INITIALIZED:
|
|
1825
|
+
wakeChunk(resolveListeners, chunk.value);
|
|
1826
|
+
break;
|
|
1827
|
+
case PENDING:
|
|
1828
|
+
case BLOCKED:
|
|
1829
|
+
if (chunk.value) {
|
|
1830
|
+
for (var i = 0; i < resolveListeners.length; i++) {
|
|
1831
|
+
chunk.value.push(resolveListeners[i]);
|
|
1832
|
+
}
|
|
1833
|
+
} else {
|
|
1834
|
+
chunk.value = resolveListeners;
|
|
1835
|
+
}
|
|
1836
|
+
if (chunk.reason) {
|
|
1837
|
+
if (rejectListeners) {
|
|
1838
|
+
for (var _i = 0; _i < rejectListeners.length; _i++) {
|
|
1839
|
+
chunk.reason.push(rejectListeners[_i]);
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
} else {
|
|
1843
|
+
chunk.reason = rejectListeners;
|
|
1844
|
+
}
|
|
1845
|
+
break;
|
|
1846
|
+
case ERRORED:
|
|
1847
|
+
if (rejectListeners) {
|
|
1848
|
+
wakeChunk(rejectListeners, chunk.reason);
|
|
1849
|
+
}
|
|
1850
|
+
break;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
function triggerErrorOnChunk(chunk, error) {
|
|
1854
|
+
if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
|
|
1855
|
+
// If we get more data to an already resolved ID, we assume that it's
|
|
1856
|
+
// a stream chunk since any other row shouldn't have more than one entry.
|
|
1857
|
+
var streamChunk = chunk;
|
|
1858
|
+
var controller = streamChunk.reason;
|
|
1859
|
+
// $FlowFixMe[incompatible-call]: The error method should accept mixed.
|
|
1860
|
+
controller.error(error);
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
var listeners = chunk.reason;
|
|
1864
|
+
var erroredChunk = chunk;
|
|
1865
|
+
erroredChunk.status = ERRORED;
|
|
1866
|
+
erroredChunk.reason = error;
|
|
1867
|
+
if (listeners !== null) {
|
|
1868
|
+
wakeChunk(listeners, error);
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
function createResolvedModelChunk(response, value) {
|
|
1872
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
|
1873
|
+
return new ReactPromise(RESOLVED_MODEL, value, null, response);
|
|
1874
|
+
}
|
|
1875
|
+
function createResolvedModuleChunk(response, value) {
|
|
1876
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
|
1877
|
+
return new ReactPromise(RESOLVED_MODULE, value, null, response);
|
|
1878
|
+
}
|
|
1879
|
+
function createInitializedTextChunk(response, value) {
|
|
1880
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
|
1881
|
+
return new ReactPromise(INITIALIZED, value, null, response);
|
|
1882
|
+
}
|
|
1883
|
+
function createInitializedBufferChunk(response, value) {
|
|
1884
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
|
1885
|
+
return new ReactPromise(INITIALIZED, value, null, response);
|
|
1886
|
+
}
|
|
1887
|
+
function createInitializedIteratorResultChunk(response, value, done) {
|
|
1888
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
|
1889
|
+
return new ReactPromise(INITIALIZED, {
|
|
1890
|
+
done: done,
|
|
1891
|
+
value: value
|
|
1892
|
+
}, null, response);
|
|
1893
|
+
}
|
|
1894
|
+
function createInitializedStreamChunk(response, value, controller) {
|
|
1895
|
+
// We use the reason field to stash the controller since we already have that
|
|
1896
|
+
// field. It's a bit of a hack but efficient.
|
|
1897
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
|
1898
|
+
return new ReactPromise(INITIALIZED, value, controller, response);
|
|
1899
|
+
}
|
|
1900
|
+
function createResolvedIteratorResultChunk(response, value, done) {
|
|
1901
|
+
// To reuse code as much code as possible we add the wrapper element as part of the JSON.
|
|
1902
|
+
var iteratorResultJSON = (done ? '{"done":true,"value":' : '{"done":false,"value":') + value + '}';
|
|
1903
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
|
1904
|
+
return new ReactPromise(RESOLVED_MODEL, iteratorResultJSON, null, response);
|
|
1905
|
+
}
|
|
1906
|
+
function resolveIteratorResultChunk(chunk, value, done) {
|
|
1907
|
+
// To reuse code as much code as possible we add the wrapper element as part of the JSON.
|
|
1908
|
+
var iteratorResultJSON = (done ? '{"done":true,"value":' : '{"done":false,"value":') + value + '}';
|
|
1909
|
+
resolveModelChunk(chunk, iteratorResultJSON);
|
|
1910
|
+
}
|
|
1911
|
+
function resolveModelChunk(chunk, value) {
|
|
1912
|
+
if (chunk.status !== PENDING) {
|
|
1913
|
+
// If we get more data to an already resolved ID, we assume that it's
|
|
1914
|
+
// a stream chunk since any other row shouldn't have more than one entry.
|
|
1915
|
+
var streamChunk = chunk;
|
|
1916
|
+
var controller = streamChunk.reason;
|
|
1917
|
+
controller.enqueueModel(value);
|
|
1918
|
+
return;
|
|
1919
|
+
}
|
|
1920
|
+
var resolveListeners = chunk.value;
|
|
1921
|
+
var rejectListeners = chunk.reason;
|
|
1922
|
+
var resolvedChunk = chunk;
|
|
1923
|
+
resolvedChunk.status = RESOLVED_MODEL;
|
|
1924
|
+
resolvedChunk.value = value;
|
|
1925
|
+
if (resolveListeners !== null) {
|
|
1926
|
+
// This is unfortunate that we're reading this eagerly if
|
|
1927
|
+
// we already have listeners attached since they might no
|
|
1928
|
+
// longer be rendered or might not be the highest pri.
|
|
1929
|
+
initializeModelChunk(resolvedChunk);
|
|
1930
|
+
// The status might have changed after initialization.
|
|
1931
|
+
wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
function resolveModuleChunk(chunk, value) {
|
|
1935
|
+
if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
|
|
1936
|
+
// We already resolved. We didn't expect to see this.
|
|
1937
|
+
return;
|
|
1938
|
+
}
|
|
1939
|
+
var resolveListeners = chunk.value;
|
|
1940
|
+
var rejectListeners = chunk.reason;
|
|
1941
|
+
var resolvedChunk = chunk;
|
|
1942
|
+
resolvedChunk.status = RESOLVED_MODULE;
|
|
1943
|
+
resolvedChunk.value = value;
|
|
1944
|
+
if (resolveListeners !== null) {
|
|
1945
|
+
initializeModuleChunk(resolvedChunk);
|
|
1946
|
+
wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
var initializingHandler = null;
|
|
1950
|
+
var initializingChunk = null;
|
|
1951
|
+
function initializeModelChunk(chunk) {
|
|
1952
|
+
var prevHandler = initializingHandler;
|
|
1953
|
+
var prevChunk = initializingChunk;
|
|
1954
|
+
initializingHandler = null;
|
|
1955
|
+
var resolvedModel = chunk.value;
|
|
1956
|
+
|
|
1957
|
+
// We go to the BLOCKED state until we've fully resolved this.
|
|
1958
|
+
// We do this before parsing in case we try to initialize the same chunk
|
|
1959
|
+
// while parsing the model. Such as in a cyclic reference.
|
|
1960
|
+
var cyclicChunk = chunk;
|
|
1961
|
+
cyclicChunk.status = BLOCKED;
|
|
1962
|
+
cyclicChunk.value = null;
|
|
1963
|
+
cyclicChunk.reason = null;
|
|
1964
|
+
{
|
|
1965
|
+
initializingChunk = cyclicChunk;
|
|
1966
|
+
}
|
|
1967
|
+
try {
|
|
1968
|
+
var value = parseModel(chunk._response, resolvedModel);
|
|
1969
|
+
// Invoke any listeners added while resolving this model. I.e. cyclic
|
|
1970
|
+
// references. This may or may not fully resolve the model depending on
|
|
1971
|
+
// if they were blocked.
|
|
1972
|
+
var resolveListeners = cyclicChunk.value;
|
|
1973
|
+
if (resolveListeners !== null) {
|
|
1974
|
+
cyclicChunk.value = null;
|
|
1975
|
+
cyclicChunk.reason = null;
|
|
1976
|
+
wakeChunk(resolveListeners, value);
|
|
1977
|
+
}
|
|
1978
|
+
if (initializingHandler !== null) {
|
|
1979
|
+
if (initializingHandler.errored) {
|
|
1980
|
+
throw initializingHandler.value;
|
|
1981
|
+
}
|
|
1982
|
+
if (initializingHandler.deps > 0) {
|
|
1983
|
+
// We discovered new dependencies on modules that are not yet resolved.
|
|
1984
|
+
// We have to keep the BLOCKED state until they're resolved.
|
|
1985
|
+
initializingHandler.value = value;
|
|
1986
|
+
initializingHandler.chunk = cyclicChunk;
|
|
1987
|
+
return;
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
var initializedChunk = chunk;
|
|
1991
|
+
initializedChunk.status = INITIALIZED;
|
|
1992
|
+
initializedChunk.value = value;
|
|
1993
|
+
} catch (error) {
|
|
1994
|
+
var erroredChunk = chunk;
|
|
1995
|
+
erroredChunk.status = ERRORED;
|
|
1996
|
+
erroredChunk.reason = error;
|
|
1997
|
+
} finally {
|
|
1998
|
+
initializingHandler = prevHandler;
|
|
1999
|
+
{
|
|
2000
|
+
initializingChunk = prevChunk;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
function initializeModuleChunk(chunk) {
|
|
2005
|
+
try {
|
|
2006
|
+
var value = requireModule(chunk.value);
|
|
2007
|
+
var initializedChunk = chunk;
|
|
2008
|
+
initializedChunk.status = INITIALIZED;
|
|
2009
|
+
initializedChunk.value = value;
|
|
2010
|
+
} catch (error) {
|
|
2011
|
+
var erroredChunk = chunk;
|
|
2012
|
+
erroredChunk.status = ERRORED;
|
|
2013
|
+
erroredChunk.reason = error;
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
// Report that any missing chunks in the model is now going to throw this
|
|
2018
|
+
// error upon read. Also notify any pending promises.
|
|
2019
|
+
function reportGlobalError(response, error) {
|
|
2020
|
+
response._closed = true;
|
|
2021
|
+
response._closedReason = error;
|
|
2022
|
+
response._chunks.forEach(function (chunk) {
|
|
2023
|
+
// If this chunk was already resolved or errored, it won't
|
|
2024
|
+
// trigger an error but if it wasn't then we need to
|
|
2025
|
+
// because we won't be getting any new data to resolve it.
|
|
2026
|
+
if (chunk.status === PENDING) {
|
|
2027
|
+
triggerErrorOnChunk(chunk, error);
|
|
2028
|
+
}
|
|
2029
|
+
});
|
|
2030
|
+
{
|
|
2031
|
+
markAllTracksInOrder();
|
|
2032
|
+
flushComponentPerformance(response, getChunk(response, 0), 0, -Infinity, -Infinity);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
function nullRefGetter() {
|
|
2036
|
+
{
|
|
2037
|
+
return null;
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
function getServerComponentTaskName(componentInfo) {
|
|
2041
|
+
return '<' + (componentInfo.name || '...') + '>';
|
|
2042
|
+
}
|
|
2043
|
+
function getTaskName(type) {
|
|
2044
|
+
if (type === REACT_FRAGMENT_TYPE) {
|
|
2045
|
+
return '<>';
|
|
2046
|
+
}
|
|
2047
|
+
if (typeof type === 'function') {
|
|
2048
|
+
// This is a function so it must have been a Client Reference that resolved to
|
|
2049
|
+
// a function. We use "use client" to indicate that this is the boundary into
|
|
2050
|
+
// the client. There should only be one for any given owner chain.
|
|
2051
|
+
return '"use client"';
|
|
2052
|
+
}
|
|
2053
|
+
if (typeof type === 'object' && type !== null && type.$$typeof === REACT_LAZY_TYPE) {
|
|
2054
|
+
if (type._init === readChunk) {
|
|
2055
|
+
// This is a lazy node created by Flight. It is probably a client reference.
|
|
2056
|
+
// We use the "use client" string to indicate that this is the boundary into
|
|
2057
|
+
// the client. There will only be one for any given owner chain.
|
|
2058
|
+
return '"use client"';
|
|
2059
|
+
}
|
|
2060
|
+
// We don't want to eagerly initialize the initializer in DEV mode so we can't
|
|
2061
|
+
// call it to extract the type so we don't know the type of this component.
|
|
2062
|
+
return '<...>';
|
|
2063
|
+
}
|
|
2064
|
+
try {
|
|
2065
|
+
var name = getComponentNameFromType(type);
|
|
2066
|
+
return name ? '<' + name + '>' : '<...>';
|
|
2067
|
+
} catch (x) {
|
|
2068
|
+
return '<...>';
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
function createElement(response, type, key, props, owner,
|
|
2072
|
+
// DEV-only
|
|
2073
|
+
stack,
|
|
2074
|
+
// DEV-only
|
|
2075
|
+
validated // DEV-only
|
|
2076
|
+
) {
|
|
2077
|
+
var element;
|
|
2078
|
+
{
|
|
2079
|
+
// `ref` is non-enumerable in dev
|
|
2080
|
+
element = {
|
|
2081
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
2082
|
+
type: type,
|
|
2083
|
+
key: key,
|
|
2084
|
+
props: props,
|
|
2085
|
+
_owner: owner === null ? response._debugRootOwner : owner
|
|
2086
|
+
};
|
|
2087
|
+
Object.defineProperty(element, 'ref', {
|
|
2088
|
+
enumerable: false,
|
|
2089
|
+
get: nullRefGetter
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
{
|
|
2093
|
+
// We don't really need to add any of these but keeping them for good measure.
|
|
2094
|
+
// Unfortunately, _store is enumerable in jest matchers so for equality to
|
|
2095
|
+
// work, I need to keep it or make _store non-enumerable in the other file.
|
|
2096
|
+
element._store = {};
|
|
2097
|
+
Object.defineProperty(element._store, 'validated', {
|
|
2098
|
+
configurable: false,
|
|
2099
|
+
enumerable: false,
|
|
2100
|
+
writable: true,
|
|
2101
|
+
value: validated // Whether the element has already been validated on the server.
|
|
2102
|
+
});
|
|
2103
|
+
// debugInfo contains Server Component debug information.
|
|
2104
|
+
Object.defineProperty(element, '_debugInfo', {
|
|
2105
|
+
configurable: false,
|
|
2106
|
+
enumerable: false,
|
|
2107
|
+
writable: true,
|
|
2108
|
+
value: null
|
|
2109
|
+
});
|
|
2110
|
+
var env = response._rootEnvironmentName;
|
|
2111
|
+
if (owner !== null && owner.env != null) {
|
|
2112
|
+
// Interestingly we don't actually have the environment name of where
|
|
2113
|
+
// this JSX was created if it doesn't have an owner but if it does
|
|
2114
|
+
// it must be the same environment as the owner. We could send it separately
|
|
2115
|
+
// but it seems a bit unnecessary for this edge case.
|
|
2116
|
+
env = owner.env;
|
|
2117
|
+
}
|
|
2118
|
+
var normalizedStackTrace = null;
|
|
2119
|
+
if (owner === null && response._debugRootStack != null) {
|
|
2120
|
+
// We override the stack if we override the owner since the stack where the root JSX
|
|
2121
|
+
// was created on the server isn't very useful but where the request was made is.
|
|
2122
|
+
normalizedStackTrace = response._debugRootStack;
|
|
2123
|
+
} else if (stack !== null) {
|
|
2124
|
+
// We create a fake stack and then create an Error object inside of it.
|
|
2125
|
+
// This means that the stack trace is now normalized into the native format
|
|
2126
|
+
// of the browser and the stack frames will have been registered with
|
|
2127
|
+
// source mapping information.
|
|
2128
|
+
// This can unfortunately happen within a user space callstack which will
|
|
2129
|
+
// remain on the stack.
|
|
2130
|
+
normalizedStackTrace = createFakeJSXCallStackInDEV(response, stack, env);
|
|
2131
|
+
}
|
|
2132
|
+
Object.defineProperty(element, '_debugStack', {
|
|
2133
|
+
configurable: false,
|
|
2134
|
+
enumerable: false,
|
|
2135
|
+
writable: true,
|
|
2136
|
+
value: normalizedStackTrace
|
|
2137
|
+
});
|
|
2138
|
+
var task = null;
|
|
2139
|
+
if (supportsCreateTask && stack !== null) {
|
|
2140
|
+
var createTaskFn = console.createTask.bind(console, getTaskName(type));
|
|
2141
|
+
var callStack = buildFakeCallStack(response, stack, env, createTaskFn);
|
|
2142
|
+
// This owner should ideally have already been initialized to avoid getting
|
|
2143
|
+
// user stack frames on the stack.
|
|
2144
|
+
var ownerTask = owner === null ? null : initializeFakeTask(response, owner, env);
|
|
2145
|
+
if (ownerTask === null) {
|
|
2146
|
+
var rootTask = response._debugRootTask;
|
|
2147
|
+
if (rootTask != null) {
|
|
2148
|
+
task = rootTask.run(callStack);
|
|
2149
|
+
} else {
|
|
2150
|
+
task = callStack();
|
|
2151
|
+
}
|
|
2152
|
+
} else {
|
|
2153
|
+
task = ownerTask.run(callStack);
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
Object.defineProperty(element, '_debugTask', {
|
|
2157
|
+
configurable: false,
|
|
2158
|
+
enumerable: false,
|
|
2159
|
+
writable: true,
|
|
2160
|
+
value: task
|
|
2161
|
+
});
|
|
2162
|
+
|
|
2163
|
+
// This owner should ideally have already been initialized to avoid getting
|
|
2164
|
+
// user stack frames on the stack.
|
|
2165
|
+
if (owner !== null) {
|
|
2166
|
+
initializeFakeStack(response, owner);
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
if (initializingHandler !== null) {
|
|
2170
|
+
var handler = initializingHandler;
|
|
2171
|
+
// We pop the stack to the previous outer handler before leaving the Element.
|
|
2172
|
+
// This is effectively the complete phase.
|
|
2173
|
+
initializingHandler = handler.parent;
|
|
2174
|
+
if (handler.errored) {
|
|
2175
|
+
// Something errored inside this Element's props. We can turn this Element
|
|
2176
|
+
// into a Lazy so that we can still render up until that Lazy is rendered.
|
|
2177
|
+
var erroredChunk = createErrorChunk(response, handler.value);
|
|
2178
|
+
{
|
|
2179
|
+
// Conceptually the error happened inside this Element but right before
|
|
2180
|
+
// it was rendered. We don't have a client side component to render but
|
|
2181
|
+
// we can add some DebugInfo to explain that this was conceptually a
|
|
2182
|
+
// Server side error that errored inside this element. That way any stack
|
|
2183
|
+
// traces will point to the nearest JSX that errored - e.g. during
|
|
2184
|
+
// serialization.
|
|
2185
|
+
var erroredComponent = {
|
|
2186
|
+
name: getComponentNameFromType(element.type) || '',
|
|
2187
|
+
owner: element._owner
|
|
2188
|
+
};
|
|
2189
|
+
// $FlowFixMe[cannot-write]
|
|
2190
|
+
erroredComponent.debugStack = element._debugStack;
|
|
2191
|
+
if (supportsCreateTask) {
|
|
2192
|
+
// $FlowFixMe[cannot-write]
|
|
2193
|
+
erroredComponent.debugTask = element._debugTask;
|
|
2194
|
+
}
|
|
2195
|
+
erroredChunk._debugInfo = [erroredComponent];
|
|
2196
|
+
}
|
|
2197
|
+
return createLazyChunkWrapper(erroredChunk);
|
|
2198
|
+
}
|
|
2199
|
+
if (handler.deps > 0) {
|
|
2200
|
+
// We have blocked references inside this Element but we can turn this into
|
|
2201
|
+
// a Lazy node referencing this Element to let everything around it proceed.
|
|
2202
|
+
var blockedChunk = createBlockedChunk(response);
|
|
2203
|
+
handler.value = element;
|
|
2204
|
+
handler.chunk = blockedChunk;
|
|
2205
|
+
{
|
|
2206
|
+
var freeze = Object.freeze.bind(Object, element.props);
|
|
2207
|
+
blockedChunk.then(freeze, freeze);
|
|
2208
|
+
}
|
|
2209
|
+
return createLazyChunkWrapper(blockedChunk);
|
|
2210
|
+
}
|
|
2211
|
+
} else {
|
|
2212
|
+
// TODO: We should be freezing the element but currently, we might write into
|
|
2213
|
+
// _debugInfo later. We could move it into _store which remains mutable.
|
|
2214
|
+
Object.freeze(element.props);
|
|
2215
|
+
}
|
|
2216
|
+
return element;
|
|
2217
|
+
}
|
|
2218
|
+
function createLazyChunkWrapper(chunk) {
|
|
2219
|
+
var lazyType = {
|
|
2220
|
+
$$typeof: REACT_LAZY_TYPE,
|
|
2221
|
+
_payload: chunk,
|
|
2222
|
+
_init: readChunk
|
|
2223
|
+
};
|
|
2224
|
+
{
|
|
2225
|
+
// Ensure we have a live array to track future debug info.
|
|
2226
|
+
var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
|
|
2227
|
+
lazyType._debugInfo = chunkDebugInfo;
|
|
2228
|
+
}
|
|
2229
|
+
return lazyType;
|
|
2230
|
+
}
|
|
2231
|
+
function getChunk(response, id) {
|
|
2232
|
+
var chunks = response._chunks;
|
|
2233
|
+
var chunk = chunks.get(id);
|
|
2234
|
+
if (!chunk) {
|
|
2235
|
+
if (response._closed) {
|
|
2236
|
+
// We have already errored the response and we're not going to get
|
|
2237
|
+
// anything more streaming in so this will immediately error.
|
|
2238
|
+
chunk = createErrorChunk(response, response._closedReason);
|
|
2239
|
+
} else {
|
|
2240
|
+
chunk = createPendingChunk(response);
|
|
2241
|
+
}
|
|
2242
|
+
chunks.set(id, chunk);
|
|
2243
|
+
}
|
|
2244
|
+
return chunk;
|
|
2245
|
+
}
|
|
2246
|
+
function waitForReference(referencedChunk, parentObject, key, response, map, path) {
|
|
2247
|
+
var handler;
|
|
2248
|
+
if (initializingHandler) {
|
|
2249
|
+
handler = initializingHandler;
|
|
2250
|
+
handler.deps++;
|
|
2251
|
+
} else {
|
|
2252
|
+
handler = initializingHandler = {
|
|
2253
|
+
parent: null,
|
|
2254
|
+
chunk: null,
|
|
2255
|
+
value: null,
|
|
2256
|
+
deps: 1,
|
|
2257
|
+
errored: false
|
|
2258
|
+
};
|
|
2259
|
+
}
|
|
2260
|
+
function fulfill(value) {
|
|
2261
|
+
for (var i = 1; i < path.length; i++) {
|
|
2262
|
+
while (value.$$typeof === REACT_LAZY_TYPE) {
|
|
2263
|
+
// We never expect to see a Lazy node on this path because we encode those as
|
|
2264
|
+
// separate models. This must mean that we have inserted an extra lazy node
|
|
2265
|
+
// e.g. to replace a blocked element. We must instead look for it inside.
|
|
2266
|
+
var chunk = value._payload;
|
|
2267
|
+
if (chunk === handler.chunk) {
|
|
2268
|
+
// This is a reference to the thing we're currently blocking. We can peak
|
|
2269
|
+
// inside of it to get the value.
|
|
2270
|
+
value = handler.value;
|
|
2271
|
+
continue;
|
|
2272
|
+
} else if (chunk.status === INITIALIZED) {
|
|
2273
|
+
value = chunk.value;
|
|
2274
|
+
continue;
|
|
2275
|
+
} else {
|
|
2276
|
+
// If we're not yet initialized we need to skip what we've already drilled
|
|
2277
|
+
// through and then wait for the next value to become available.
|
|
2278
|
+
path.splice(0, i - 1);
|
|
2279
|
+
chunk.then(fulfill, reject);
|
|
2280
|
+
return;
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
value = value[path[i]];
|
|
2284
|
+
}
|
|
2285
|
+
var mappedValue = map(response, value, parentObject, key);
|
|
2286
|
+
parentObject[key] = mappedValue;
|
|
2287
|
+
|
|
2288
|
+
// If this is the root object for a model reference, where `handler.value`
|
|
2289
|
+
// is a stale `null`, the resolved value can be used directly.
|
|
2290
|
+
if (key === '' && handler.value === null) {
|
|
2291
|
+
handler.value = mappedValue;
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
// If the parent object is an unparsed React element tuple, we also need to
|
|
2295
|
+
// update the props and owner of the parsed element object (i.e.
|
|
2296
|
+
// handler.value).
|
|
2297
|
+
if (parentObject[0] === REACT_ELEMENT_TYPE && typeof handler.value === 'object' && handler.value !== null && handler.value.$$typeof === REACT_ELEMENT_TYPE) {
|
|
2298
|
+
var element = handler.value;
|
|
2299
|
+
switch (key) {
|
|
2300
|
+
case '3':
|
|
2301
|
+
element.props = mappedValue;
|
|
2302
|
+
break;
|
|
2303
|
+
case '4':
|
|
2304
|
+
{
|
|
2305
|
+
element._owner = mappedValue;
|
|
2306
|
+
}
|
|
2307
|
+
break;
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
handler.deps--;
|
|
2311
|
+
if (handler.deps === 0) {
|
|
2312
|
+
var _chunk = handler.chunk;
|
|
2313
|
+
if (_chunk === null || _chunk.status !== BLOCKED) {
|
|
2314
|
+
return;
|
|
2315
|
+
}
|
|
2316
|
+
var resolveListeners = _chunk.value;
|
|
2317
|
+
var initializedChunk = _chunk;
|
|
2318
|
+
initializedChunk.status = INITIALIZED;
|
|
2319
|
+
initializedChunk.value = handler.value;
|
|
2320
|
+
if (resolveListeners !== null) {
|
|
2321
|
+
wakeChunk(resolveListeners, handler.value);
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
function reject(error) {
|
|
2326
|
+
if (handler.errored) {
|
|
2327
|
+
// We've already errored. We could instead build up an AggregateError
|
|
2328
|
+
// but if there are multiple errors we just take the first one like
|
|
2329
|
+
// Promise.all.
|
|
2330
|
+
return;
|
|
2331
|
+
}
|
|
2332
|
+
var blockedValue = handler.value;
|
|
2333
|
+
handler.errored = true;
|
|
2334
|
+
handler.value = error;
|
|
2335
|
+
var chunk = handler.chunk;
|
|
2336
|
+
if (chunk === null || chunk.status !== BLOCKED) {
|
|
2337
|
+
return;
|
|
2338
|
+
}
|
|
2339
|
+
{
|
|
2340
|
+
if (typeof blockedValue === 'object' && blockedValue !== null && blockedValue.$$typeof === REACT_ELEMENT_TYPE) {
|
|
2341
|
+
var element = blockedValue;
|
|
2342
|
+
// Conceptually the error happened inside this Element but right before
|
|
2343
|
+
// it was rendered. We don't have a client side component to render but
|
|
2344
|
+
// we can add some DebugInfo to explain that this was conceptually a
|
|
2345
|
+
// Server side error that errored inside this element. That way any stack
|
|
2346
|
+
// traces will point to the nearest JSX that errored - e.g. during
|
|
2347
|
+
// serialization.
|
|
2348
|
+
var erroredComponent = {
|
|
2349
|
+
name: getComponentNameFromType(element.type) || '',
|
|
2350
|
+
owner: element._owner
|
|
2351
|
+
};
|
|
2352
|
+
// $FlowFixMe[cannot-write]
|
|
2353
|
+
erroredComponent.debugStack = element._debugStack;
|
|
2354
|
+
if (supportsCreateTask) {
|
|
2355
|
+
// $FlowFixMe[cannot-write]
|
|
2356
|
+
erroredComponent.debugTask = element._debugTask;
|
|
2357
|
+
}
|
|
2358
|
+
var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
|
|
2359
|
+
chunkDebugInfo.push(erroredComponent);
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
triggerErrorOnChunk(chunk, error);
|
|
2363
|
+
}
|
|
2364
|
+
referencedChunk.then(fulfill, reject);
|
|
2365
|
+
|
|
2366
|
+
// Return a place holder value for now.
|
|
2367
|
+
return null;
|
|
2368
|
+
}
|
|
2369
|
+
function loadServerReference(response, metaData, parentObject, key) {
|
|
2370
|
+
if (!response._serverReferenceConfig) {
|
|
2371
|
+
// In the normal case, we can't load this Server Reference in the current environment and
|
|
2372
|
+
// we just return a proxy to it.
|
|
2373
|
+
return createBoundServerReference(metaData, response._callServer, response._encodeFormAction, response._debugFindSourceMapURL );
|
|
2374
|
+
}
|
|
2375
|
+
// If we have a module mapping we can load the real version of this Server Reference.
|
|
2376
|
+
var serverReference = resolveServerReference(response._serverReferenceConfig, metaData.id);
|
|
2377
|
+
var promise = preloadModule(serverReference);
|
|
2378
|
+
if (!promise) {
|
|
2379
|
+
if (!metaData.bound) {
|
|
2380
|
+
var resolvedValue = requireModule(serverReference);
|
|
2381
|
+
registerBoundServerReference(resolvedValue, metaData.id, metaData.bound);
|
|
2382
|
+
return resolvedValue;
|
|
2383
|
+
} else {
|
|
2384
|
+
promise = Promise.resolve(metaData.bound);
|
|
2385
|
+
}
|
|
2386
|
+
} else if (metaData.bound) {
|
|
2387
|
+
promise = Promise.all([promise, metaData.bound]);
|
|
2388
|
+
}
|
|
2389
|
+
var handler;
|
|
2390
|
+
if (initializingHandler) {
|
|
2391
|
+
handler = initializingHandler;
|
|
2392
|
+
handler.deps++;
|
|
2393
|
+
} else {
|
|
2394
|
+
handler = initializingHandler = {
|
|
2395
|
+
parent: null,
|
|
2396
|
+
chunk: null,
|
|
2397
|
+
value: null,
|
|
2398
|
+
deps: 1,
|
|
2399
|
+
errored: false
|
|
2400
|
+
};
|
|
2401
|
+
}
|
|
2402
|
+
function fulfill() {
|
|
2403
|
+
var resolvedValue = requireModule(serverReference);
|
|
2404
|
+
if (metaData.bound) {
|
|
2405
|
+
// This promise is coming from us and should have initilialized by now.
|
|
2406
|
+
var boundArgs = metaData.bound.value.slice(0);
|
|
2407
|
+
boundArgs.unshift(null); // this
|
|
2408
|
+
resolvedValue = resolvedValue.bind.apply(resolvedValue, boundArgs);
|
|
2409
|
+
}
|
|
2410
|
+
registerBoundServerReference(resolvedValue, metaData.id, metaData.bound);
|
|
2411
|
+
parentObject[key] = resolvedValue;
|
|
2412
|
+
|
|
2413
|
+
// If this is the root object for a model reference, where `handler.value`
|
|
2414
|
+
// is a stale `null`, the resolved value can be used directly.
|
|
2415
|
+
if (key === '' && handler.value === null) {
|
|
2416
|
+
handler.value = resolvedValue;
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
// If the parent object is an unparsed React element tuple, we also need to
|
|
2420
|
+
// update the props and owner of the parsed element object (i.e.
|
|
2421
|
+
// handler.value).
|
|
2422
|
+
if (parentObject[0] === REACT_ELEMENT_TYPE && typeof handler.value === 'object' && handler.value !== null && handler.value.$$typeof === REACT_ELEMENT_TYPE) {
|
|
2423
|
+
var element = handler.value;
|
|
2424
|
+
switch (key) {
|
|
2425
|
+
case '3':
|
|
2426
|
+
element.props = resolvedValue;
|
|
2427
|
+
break;
|
|
2428
|
+
case '4':
|
|
2429
|
+
{
|
|
2430
|
+
element._owner = resolvedValue;
|
|
2431
|
+
}
|
|
2432
|
+
break;
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
handler.deps--;
|
|
2436
|
+
if (handler.deps === 0) {
|
|
2437
|
+
var chunk = handler.chunk;
|
|
2438
|
+
if (chunk === null || chunk.status !== BLOCKED) {
|
|
2439
|
+
return;
|
|
2440
|
+
}
|
|
2441
|
+
var resolveListeners = chunk.value;
|
|
2442
|
+
var initializedChunk = chunk;
|
|
2443
|
+
initializedChunk.status = INITIALIZED;
|
|
2444
|
+
initializedChunk.value = handler.value;
|
|
2445
|
+
if (resolveListeners !== null) {
|
|
2446
|
+
wakeChunk(resolveListeners, handler.value);
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
function reject(error) {
|
|
2451
|
+
if (handler.errored) {
|
|
2452
|
+
// We've already errored. We could instead build up an AggregateError
|
|
2453
|
+
// but if there are multiple errors we just take the first one like
|
|
2454
|
+
// Promise.all.
|
|
2455
|
+
return;
|
|
2456
|
+
}
|
|
2457
|
+
var blockedValue = handler.value;
|
|
2458
|
+
handler.errored = true;
|
|
2459
|
+
handler.value = error;
|
|
2460
|
+
var chunk = handler.chunk;
|
|
2461
|
+
if (chunk === null || chunk.status !== BLOCKED) {
|
|
2462
|
+
return;
|
|
2463
|
+
}
|
|
2464
|
+
{
|
|
2465
|
+
if (typeof blockedValue === 'object' && blockedValue !== null && blockedValue.$$typeof === REACT_ELEMENT_TYPE) {
|
|
2466
|
+
var element = blockedValue;
|
|
2467
|
+
// Conceptually the error happened inside this Element but right before
|
|
2468
|
+
// it was rendered. We don't have a client side component to render but
|
|
2469
|
+
// we can add some DebugInfo to explain that this was conceptually a
|
|
2470
|
+
// Server side error that errored inside this element. That way any stack
|
|
2471
|
+
// traces will point to the nearest JSX that errored - e.g. during
|
|
2472
|
+
// serialization.
|
|
2473
|
+
var erroredComponent = {
|
|
2474
|
+
name: getComponentNameFromType(element.type) || '',
|
|
2475
|
+
owner: element._owner
|
|
2476
|
+
};
|
|
2477
|
+
// $FlowFixMe[cannot-write]
|
|
2478
|
+
erroredComponent.debugStack = element._debugStack;
|
|
2479
|
+
if (supportsCreateTask) {
|
|
2480
|
+
// $FlowFixMe[cannot-write]
|
|
2481
|
+
erroredComponent.debugTask = element._debugTask;
|
|
2482
|
+
}
|
|
2483
|
+
var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
|
|
2484
|
+
chunkDebugInfo.push(erroredComponent);
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
triggerErrorOnChunk(chunk, error);
|
|
2488
|
+
}
|
|
2489
|
+
promise.then(fulfill, reject);
|
|
2490
|
+
|
|
2491
|
+
// Return a place holder value for now.
|
|
2492
|
+
return null;
|
|
2493
|
+
}
|
|
2494
|
+
function getOutlinedModel(response, reference, parentObject, key, map) {
|
|
2495
|
+
var path = reference.split(':');
|
|
2496
|
+
var id = parseInt(path[0], 16);
|
|
2497
|
+
var chunk = getChunk(response, id);
|
|
2498
|
+
{
|
|
2499
|
+
if (initializingChunk !== null && isArray(initializingChunk._children)) {
|
|
2500
|
+
initializingChunk._children.push(chunk);
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
switch (chunk.status) {
|
|
2504
|
+
case RESOLVED_MODEL:
|
|
2505
|
+
initializeModelChunk(chunk);
|
|
2506
|
+
break;
|
|
2507
|
+
case RESOLVED_MODULE:
|
|
2508
|
+
initializeModuleChunk(chunk);
|
|
2509
|
+
break;
|
|
2510
|
+
}
|
|
2511
|
+
// The status might have changed after initialization.
|
|
2512
|
+
switch (chunk.status) {
|
|
2513
|
+
case INITIALIZED:
|
|
2514
|
+
var value = chunk.value;
|
|
2515
|
+
for (var i = 1; i < path.length; i++) {
|
|
2516
|
+
while (value.$$typeof === REACT_LAZY_TYPE) {
|
|
2517
|
+
var referencedChunk = value._payload;
|
|
2518
|
+
if (referencedChunk.status === INITIALIZED) {
|
|
2519
|
+
value = referencedChunk.value;
|
|
2520
|
+
} else {
|
|
2521
|
+
return waitForReference(referencedChunk, parentObject, key, response, map, path.slice(i - 1));
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
value = value[path[i]];
|
|
2525
|
+
}
|
|
2526
|
+
var chunkValue = map(response, value, parentObject, key);
|
|
2527
|
+
if (chunk._debugInfo) {
|
|
2528
|
+
// If we have a direct reference to an object that was rendered by a synchronous
|
|
2529
|
+
// server component, it might have some debug info about how it was rendered.
|
|
2530
|
+
// We forward this to the underlying object. This might be a React Element or
|
|
2531
|
+
// an Array fragment.
|
|
2532
|
+
// If this was a string / number return value we lose the debug info. We choose
|
|
2533
|
+
// that tradeoff to allow sync server components to return plain values and not
|
|
2534
|
+
// use them as React Nodes necessarily. We could otherwise wrap them in a Lazy.
|
|
2535
|
+
if (typeof chunkValue === 'object' && chunkValue !== null && (isArray(chunkValue) || typeof chunkValue[ASYNC_ITERATOR] === 'function' || chunkValue.$$typeof === REACT_ELEMENT_TYPE) && !chunkValue._debugInfo) {
|
|
2536
|
+
// We should maybe use a unique symbol for arrays but this is a React owned array.
|
|
2537
|
+
// $FlowFixMe[prop-missing]: This should be added to elements.
|
|
2538
|
+
Object.defineProperty(chunkValue, '_debugInfo', {
|
|
2539
|
+
configurable: false,
|
|
2540
|
+
enumerable: false,
|
|
2541
|
+
writable: true,
|
|
2542
|
+
value: chunk._debugInfo
|
|
2543
|
+
});
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
return chunkValue;
|
|
2547
|
+
case PENDING:
|
|
2548
|
+
case BLOCKED:
|
|
2549
|
+
return waitForReference(chunk, parentObject, key, response, map, path);
|
|
2550
|
+
default:
|
|
2551
|
+
// This is an error. Instead of erroring directly, we're going to encode this on
|
|
2552
|
+
// an initialization handler so that we can catch it at the nearest Element.
|
|
2553
|
+
if (initializingHandler) {
|
|
2554
|
+
initializingHandler.errored = true;
|
|
2555
|
+
initializingHandler.value = chunk.reason;
|
|
2556
|
+
} else {
|
|
2557
|
+
initializingHandler = {
|
|
2558
|
+
parent: null,
|
|
2559
|
+
chunk: null,
|
|
2560
|
+
value: chunk.reason,
|
|
2561
|
+
deps: 0,
|
|
2562
|
+
errored: true
|
|
2563
|
+
};
|
|
2564
|
+
}
|
|
2565
|
+
// Placeholder
|
|
2566
|
+
return null;
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
function createMap(response, model) {
|
|
2570
|
+
return new Map(model);
|
|
2571
|
+
}
|
|
2572
|
+
function createSet(response, model) {
|
|
2573
|
+
return new Set(model);
|
|
2574
|
+
}
|
|
2575
|
+
function createBlob(response, model) {
|
|
2576
|
+
return new Blob(model.slice(1), {
|
|
2577
|
+
type: model[0]
|
|
2578
|
+
});
|
|
2579
|
+
}
|
|
2580
|
+
function createFormData(response, model) {
|
|
2581
|
+
var formData = new FormData();
|
|
2582
|
+
for (var i = 0; i < model.length; i++) {
|
|
2583
|
+
formData.append(model[i][0], model[i][1]);
|
|
2584
|
+
}
|
|
2585
|
+
return formData;
|
|
2586
|
+
}
|
|
2587
|
+
function extractIterator(response, model) {
|
|
2588
|
+
// $FlowFixMe[incompatible-use]: This uses raw Symbols because we're extracting from a native array.
|
|
2589
|
+
return model[Symbol.iterator]();
|
|
2590
|
+
}
|
|
2591
|
+
function createModel(response, model) {
|
|
2592
|
+
return model;
|
|
2593
|
+
}
|
|
2594
|
+
function parseModelString(response, parentObject, key, value) {
|
|
2595
|
+
if (value[0] === '$') {
|
|
2596
|
+
if (value === '$') {
|
|
2597
|
+
// A very common symbol.
|
|
2598
|
+
if (initializingHandler !== null && key === '0') {
|
|
2599
|
+
// We we already have an initializing handler and we're abound to enter
|
|
2600
|
+
// a new element, we need to shadow it because we're now in a new scope.
|
|
2601
|
+
// This is effectively the "begin" or "push" phase of Element parsing.
|
|
2602
|
+
// We'll pop later when we parse the array itself.
|
|
2603
|
+
initializingHandler = {
|
|
2604
|
+
parent: initializingHandler,
|
|
2605
|
+
chunk: null,
|
|
2606
|
+
value: null,
|
|
2607
|
+
deps: 0,
|
|
2608
|
+
errored: false
|
|
2609
|
+
};
|
|
2610
|
+
}
|
|
2611
|
+
return REACT_ELEMENT_TYPE;
|
|
2612
|
+
}
|
|
2613
|
+
switch (value[1]) {
|
|
2614
|
+
case '$':
|
|
2615
|
+
{
|
|
2616
|
+
// This was an escaped string value.
|
|
2617
|
+
return value.slice(1);
|
|
2618
|
+
}
|
|
2619
|
+
case 'L':
|
|
2620
|
+
{
|
|
2621
|
+
// Lazy node
|
|
2622
|
+
var id = parseInt(value.slice(2), 16);
|
|
2623
|
+
var chunk = getChunk(response, id);
|
|
2624
|
+
{
|
|
2625
|
+
if (initializingChunk !== null && isArray(initializingChunk._children)) {
|
|
2626
|
+
initializingChunk._children.push(chunk);
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
// We create a React.lazy wrapper around any lazy values.
|
|
2630
|
+
// When passed into React, we'll know how to suspend on this.
|
|
2631
|
+
return createLazyChunkWrapper(chunk);
|
|
2632
|
+
}
|
|
2633
|
+
case '@':
|
|
2634
|
+
{
|
|
2635
|
+
// Promise
|
|
2636
|
+
if (value.length === 2) {
|
|
2637
|
+
// Infinite promise that never resolves.
|
|
2638
|
+
return new Promise(function () {});
|
|
2639
|
+
}
|
|
2640
|
+
var _id = parseInt(value.slice(2), 16);
|
|
2641
|
+
var _chunk2 = getChunk(response, _id);
|
|
2642
|
+
{
|
|
2643
|
+
if (initializingChunk !== null && isArray(initializingChunk._children)) {
|
|
2644
|
+
initializingChunk._children.push(_chunk2);
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
return _chunk2;
|
|
2648
|
+
}
|
|
2649
|
+
case 'S':
|
|
2650
|
+
{
|
|
2651
|
+
// Symbol
|
|
2652
|
+
return Symbol.for(value.slice(2));
|
|
2653
|
+
}
|
|
2654
|
+
case 'F':
|
|
2655
|
+
{
|
|
2656
|
+
// Server Reference
|
|
2657
|
+
var ref = value.slice(2);
|
|
2658
|
+
return getOutlinedModel(response, ref, parentObject, key, loadServerReference);
|
|
2659
|
+
}
|
|
2660
|
+
case 'T':
|
|
2661
|
+
{
|
|
2662
|
+
// Temporary Reference
|
|
2663
|
+
var reference = '$' + value.slice(2);
|
|
2664
|
+
var temporaryReferences = response._tempRefs;
|
|
2665
|
+
if (temporaryReferences == null) {
|
|
2666
|
+
throw new Error('Missing a temporary reference set but the RSC response returned a temporary reference. ' + 'Pass a temporaryReference option with the set that was used with the reply.');
|
|
2667
|
+
}
|
|
2668
|
+
return readTemporaryReference(temporaryReferences, reference);
|
|
2669
|
+
}
|
|
2670
|
+
case 'Q':
|
|
2671
|
+
{
|
|
2672
|
+
// Map
|
|
2673
|
+
var _ref = value.slice(2);
|
|
2674
|
+
return getOutlinedModel(response, _ref, parentObject, key, createMap);
|
|
2675
|
+
}
|
|
2676
|
+
case 'W':
|
|
2677
|
+
{
|
|
2678
|
+
// Set
|
|
2679
|
+
var _ref2 = value.slice(2);
|
|
2680
|
+
return getOutlinedModel(response, _ref2, parentObject, key, createSet);
|
|
2681
|
+
}
|
|
2682
|
+
case 'B':
|
|
2683
|
+
{
|
|
2684
|
+
// Blob
|
|
2685
|
+
var _ref3 = value.slice(2);
|
|
2686
|
+
return getOutlinedModel(response, _ref3, parentObject, key, createBlob);
|
|
2687
|
+
}
|
|
2688
|
+
case 'K':
|
|
2689
|
+
{
|
|
2690
|
+
// FormData
|
|
2691
|
+
var _ref4 = value.slice(2);
|
|
2692
|
+
return getOutlinedModel(response, _ref4, parentObject, key, createFormData);
|
|
2693
|
+
}
|
|
2694
|
+
case 'Z':
|
|
2695
|
+
{
|
|
2696
|
+
// Error
|
|
2697
|
+
{
|
|
2698
|
+
var _ref5 = value.slice(2);
|
|
2699
|
+
return getOutlinedModel(response, _ref5, parentObject, key, resolveErrorDev);
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
case 'i':
|
|
2703
|
+
{
|
|
2704
|
+
// Iterator
|
|
2705
|
+
var _ref6 = value.slice(2);
|
|
2706
|
+
return getOutlinedModel(response, _ref6, parentObject, key, extractIterator);
|
|
2707
|
+
}
|
|
2708
|
+
case 'I':
|
|
2709
|
+
{
|
|
2710
|
+
// $Infinity
|
|
2711
|
+
return Infinity;
|
|
2712
|
+
}
|
|
2713
|
+
case '-':
|
|
2714
|
+
{
|
|
2715
|
+
// $-0 or $-Infinity
|
|
2716
|
+
if (value === '$-0') {
|
|
2717
|
+
return -0;
|
|
2718
|
+
} else {
|
|
2719
|
+
return -Infinity;
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
case 'N':
|
|
2723
|
+
{
|
|
2724
|
+
// $NaN
|
|
2725
|
+
return NaN;
|
|
2726
|
+
}
|
|
2727
|
+
case 'u':
|
|
2728
|
+
{
|
|
2729
|
+
// matches "$undefined"
|
|
2730
|
+
// Special encoding for `undefined` which can't be serialized as JSON otherwise.
|
|
2731
|
+
return undefined;
|
|
2732
|
+
}
|
|
2733
|
+
case 'D':
|
|
2734
|
+
{
|
|
2735
|
+
// Date
|
|
2736
|
+
return new Date(Date.parse(value.slice(2)));
|
|
2737
|
+
}
|
|
2738
|
+
case 'n':
|
|
2739
|
+
{
|
|
2740
|
+
// BigInt
|
|
2741
|
+
return BigInt(value.slice(2));
|
|
2742
|
+
}
|
|
2743
|
+
case 'E':
|
|
2744
|
+
{
|
|
2745
|
+
{
|
|
2746
|
+
// In DEV mode we allow indirect eval to produce functions for logging.
|
|
2747
|
+
// This should not compile to eval() because then it has local scope access.
|
|
2748
|
+
try {
|
|
2749
|
+
|
|
2750
|
+
return (0, eval)(value.slice(2));
|
|
2751
|
+
} catch (x) {
|
|
2752
|
+
// We currently use this to express functions so we fail parsing it,
|
|
2753
|
+
// let's just return a blank function as a place holder.
|
|
2754
|
+
return function () {};
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
// Fallthrough
|
|
2758
|
+
}
|
|
2759
|
+
case 'Y':
|
|
2760
|
+
{
|
|
2761
|
+
{
|
|
2762
|
+
// In DEV mode we encode omitted objects in logs as a getter that throws
|
|
2763
|
+
// so that when you try to access it on the client, you know why that
|
|
2764
|
+
// happened.
|
|
2765
|
+
Object.defineProperty(parentObject, key, {
|
|
2766
|
+
get: function () {
|
|
2767
|
+
// TODO: We should ideally throw here to indicate a difference.
|
|
2768
|
+
return 'This object has been omitted by React in the console log ' + 'to avoid sending too much data from the server. Try logging smaller ' + 'or more specific objects.';
|
|
2769
|
+
},
|
|
2770
|
+
enumerable: true,
|
|
2771
|
+
configurable: false
|
|
2772
|
+
});
|
|
2773
|
+
return null;
|
|
2774
|
+
}
|
|
2775
|
+
// Fallthrough
|
|
2776
|
+
}
|
|
2777
|
+
default:
|
|
2778
|
+
{
|
|
2779
|
+
// We assume that anything else is a reference ID.
|
|
2780
|
+
var _ref7 = value.slice(1);
|
|
2781
|
+
return getOutlinedModel(response, _ref7, parentObject, key, createModel);
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
return value;
|
|
2786
|
+
}
|
|
2787
|
+
function parseModelTuple(response, value) {
|
|
2788
|
+
var tuple = value;
|
|
2789
|
+
if (tuple[0] === REACT_ELEMENT_TYPE) {
|
|
2790
|
+
// TODO: Consider having React just directly accept these arrays as elements.
|
|
2791
|
+
// Or even change the ReactElement type to be an array.
|
|
2792
|
+
return createElement(response, tuple[1], tuple[2], tuple[3], tuple[4] , tuple[5] , tuple[6] );
|
|
2793
|
+
}
|
|
2794
|
+
return value;
|
|
2795
|
+
}
|
|
2796
|
+
function missingCall() {
|
|
2797
|
+
throw new Error('Trying to call a function from "use server" but the callServer option ' + 'was not implemented in your router runtime.');
|
|
2798
|
+
}
|
|
2799
|
+
function ResponseInstance(bundlerConfig, serverReferenceConfig, moduleLoading, callServer, encodeFormAction, nonce, temporaryReferences, findSourceMapURL, replayConsole, environmentName) {
|
|
2800
|
+
var chunks = new Map();
|
|
2801
|
+
this._bundlerConfig = bundlerConfig;
|
|
2802
|
+
this._serverReferenceConfig = serverReferenceConfig;
|
|
2803
|
+
this._moduleLoading = moduleLoading;
|
|
2804
|
+
this._callServer = callServer !== undefined ? callServer : missingCall;
|
|
2805
|
+
this._encodeFormAction = encodeFormAction;
|
|
2806
|
+
this._nonce = nonce;
|
|
2807
|
+
this._chunks = chunks;
|
|
2808
|
+
this._stringDecoder = createStringDecoder();
|
|
2809
|
+
this._fromJSON = null;
|
|
2810
|
+
this._rowState = 0;
|
|
2811
|
+
this._rowID = 0;
|
|
2812
|
+
this._rowTag = 0;
|
|
2813
|
+
this._rowLength = 0;
|
|
2814
|
+
this._buffer = [];
|
|
2815
|
+
this._closed = false;
|
|
2816
|
+
this._closedReason = null;
|
|
2817
|
+
this._tempRefs = temporaryReferences;
|
|
2818
|
+
{
|
|
2819
|
+
this._timeOrigin = 0;
|
|
2820
|
+
}
|
|
2821
|
+
{
|
|
2822
|
+
// TODO: The Flight Client can be used in a Client Environment too and we should really support
|
|
2823
|
+
// getting the owner there as well, but currently the owner of ReactComponentInfo is typed as only
|
|
2824
|
+
// supporting other ReactComponentInfo as owners (and not Fiber or Fizz's ComponentStackNode).
|
|
2825
|
+
// We need to update all the callsites consuming ReactComponentInfo owners to support those.
|
|
2826
|
+
// In the meantime we only check ReactSharedInteralsServer since we know that in an RSC environment
|
|
2827
|
+
// the only owners will be ReactComponentInfo.
|
|
2828
|
+
var rootOwner = ReactSharedInteralsServer === undefined || ReactSharedInteralsServer.A === null ? null : ReactSharedInteralsServer.A.getOwner();
|
|
2829
|
+
this._debugRootOwner = rootOwner;
|
|
2830
|
+
this._debugRootStack = rootOwner !== null ?
|
|
2831
|
+
// TODO: Consider passing the top frame in so we can avoid internals showing up.
|
|
2832
|
+
new Error('react-stack-top-frame') : null;
|
|
2833
|
+
var rootEnv = environmentName === undefined ? 'Server' : environmentName;
|
|
2834
|
+
if (supportsCreateTask) {
|
|
2835
|
+
// Any stacks that appear on the server need to be rooted somehow on the client
|
|
2836
|
+
// so we create a root Task for this response which will be the root owner for any
|
|
2837
|
+
// elements created by the server. We use the "use server" string to indicate that
|
|
2838
|
+
// this is where we enter the server from the client.
|
|
2839
|
+
// TODO: Make this string configurable.
|
|
2840
|
+
this._debugRootTask = console.createTask('"use ' + rootEnv.toLowerCase() + '"');
|
|
2841
|
+
}
|
|
2842
|
+
this._debugFindSourceMapURL = findSourceMapURL;
|
|
2843
|
+
this._replayConsole = replayConsole;
|
|
2844
|
+
this._rootEnvironmentName = rootEnv;
|
|
2845
|
+
}
|
|
2846
|
+
// Don't inline this call because it causes closure to outline the call above.
|
|
2847
|
+
this._fromJSON = createFromJSONCallback(this);
|
|
2848
|
+
}
|
|
2849
|
+
function createResponse(bundlerConfig, serverReferenceConfig, moduleLoading, callServer, encodeFormAction, nonce, temporaryReferences, findSourceMapURL, replayConsole, environmentName) {
|
|
2850
|
+
// $FlowFixMe[invalid-constructor]: the shapes are exact here but Flow doesn't like constructors
|
|
2851
|
+
return new ResponseInstance(bundlerConfig, serverReferenceConfig, moduleLoading, callServer, encodeFormAction, nonce, temporaryReferences, findSourceMapURL, replayConsole, environmentName);
|
|
2852
|
+
}
|
|
2853
|
+
function resolveModel(response, id, model) {
|
|
2854
|
+
var chunks = response._chunks;
|
|
2855
|
+
var chunk = chunks.get(id);
|
|
2856
|
+
if (!chunk) {
|
|
2857
|
+
chunks.set(id, createResolvedModelChunk(response, model));
|
|
2858
|
+
} else {
|
|
2859
|
+
resolveModelChunk(chunk, model);
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
function resolveText(response, id, text) {
|
|
2863
|
+
var chunks = response._chunks;
|
|
2864
|
+
var chunk = chunks.get(id);
|
|
2865
|
+
if (chunk && chunk.status !== PENDING) {
|
|
2866
|
+
// If we get more data to an already resolved ID, we assume that it's
|
|
2867
|
+
// a stream chunk since any other row shouldn't have more than one entry.
|
|
2868
|
+
var streamChunk = chunk;
|
|
2869
|
+
var controller = streamChunk.reason;
|
|
2870
|
+
controller.enqueueValue(text);
|
|
2871
|
+
return;
|
|
2872
|
+
}
|
|
2873
|
+
chunks.set(id, createInitializedTextChunk(response, text));
|
|
2874
|
+
}
|
|
2875
|
+
function resolveBuffer(response, id, buffer) {
|
|
2876
|
+
var chunks = response._chunks;
|
|
2877
|
+
var chunk = chunks.get(id);
|
|
2878
|
+
if (chunk && chunk.status !== PENDING) {
|
|
2879
|
+
// If we get more data to an already resolved ID, we assume that it's
|
|
2880
|
+
// a stream chunk since any other row shouldn't have more than one entry.
|
|
2881
|
+
var streamChunk = chunk;
|
|
2882
|
+
var controller = streamChunk.reason;
|
|
2883
|
+
controller.enqueueValue(buffer);
|
|
2884
|
+
return;
|
|
2885
|
+
}
|
|
2886
|
+
chunks.set(id, createInitializedBufferChunk(response, buffer));
|
|
2887
|
+
}
|
|
2888
|
+
function resolveModule(response, id, model) {
|
|
2889
|
+
var chunks = response._chunks;
|
|
2890
|
+
var chunk = chunks.get(id);
|
|
2891
|
+
var clientReferenceMetadata = parseModel(response, model);
|
|
2892
|
+
var clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata);
|
|
2893
|
+
|
|
2894
|
+
// TODO: Add an option to encode modules that are lazy loaded.
|
|
2895
|
+
// For now we preload all modules as early as possible since it's likely
|
|
2896
|
+
// that we'll need them.
|
|
2897
|
+
var promise = preloadModule(clientReference);
|
|
2898
|
+
if (promise) {
|
|
2899
|
+
var blockedChunk;
|
|
2900
|
+
if (!chunk) {
|
|
2901
|
+
// Technically, we should just treat promise as the chunk in this
|
|
2902
|
+
// case. Because it'll just behave as any other promise.
|
|
2903
|
+
blockedChunk = createBlockedChunk(response);
|
|
2904
|
+
chunks.set(id, blockedChunk);
|
|
2905
|
+
} else {
|
|
2906
|
+
// This can't actually happen because we don't have any forward
|
|
2907
|
+
// references to modules.
|
|
2908
|
+
blockedChunk = chunk;
|
|
2909
|
+
blockedChunk.status = BLOCKED;
|
|
2910
|
+
}
|
|
2911
|
+
promise.then(function () {
|
|
2912
|
+
return resolveModuleChunk(blockedChunk, clientReference);
|
|
2913
|
+
}, function (error) {
|
|
2914
|
+
return triggerErrorOnChunk(blockedChunk, error);
|
|
2915
|
+
});
|
|
2916
|
+
} else {
|
|
2917
|
+
if (!chunk) {
|
|
2918
|
+
chunks.set(id, createResolvedModuleChunk(response, clientReference));
|
|
2919
|
+
} else {
|
|
2920
|
+
// This can't actually happen because we don't have any forward
|
|
2921
|
+
// references to modules.
|
|
2922
|
+
resolveModuleChunk(chunk, clientReference);
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
function resolveStream(response, id, stream, controller) {
|
|
2927
|
+
var chunks = response._chunks;
|
|
2928
|
+
var chunk = chunks.get(id);
|
|
2929
|
+
if (!chunk) {
|
|
2930
|
+
chunks.set(id, createInitializedStreamChunk(response, stream, controller));
|
|
2931
|
+
return;
|
|
2932
|
+
}
|
|
2933
|
+
if (chunk.status !== PENDING) {
|
|
2934
|
+
// We already resolved. We didn't expect to see this.
|
|
2935
|
+
return;
|
|
2936
|
+
}
|
|
2937
|
+
var resolveListeners = chunk.value;
|
|
2938
|
+
var resolvedChunk = chunk;
|
|
2939
|
+
resolvedChunk.status = INITIALIZED;
|
|
2940
|
+
resolvedChunk.value = stream;
|
|
2941
|
+
resolvedChunk.reason = controller;
|
|
2942
|
+
if (resolveListeners !== null) {
|
|
2943
|
+
wakeChunk(resolveListeners, chunk.value);
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
function startReadableStream(response, id, type) {
|
|
2947
|
+
var controller = null;
|
|
2948
|
+
var stream = new ReadableStream({
|
|
2949
|
+
type: type,
|
|
2950
|
+
start: function (c) {
|
|
2951
|
+
controller = c;
|
|
2952
|
+
}
|
|
2953
|
+
});
|
|
2954
|
+
var previousBlockedChunk = null;
|
|
2955
|
+
var flightController = {
|
|
2956
|
+
enqueueValue: function (value) {
|
|
2957
|
+
if (previousBlockedChunk === null) {
|
|
2958
|
+
controller.enqueue(value);
|
|
2959
|
+
} else {
|
|
2960
|
+
// We're still waiting on a previous chunk so we can't enqueue quite yet.
|
|
2961
|
+
previousBlockedChunk.then(function () {
|
|
2962
|
+
controller.enqueue(value);
|
|
2963
|
+
});
|
|
2964
|
+
}
|
|
2965
|
+
},
|
|
2966
|
+
enqueueModel: function (json) {
|
|
2967
|
+
if (previousBlockedChunk === null) {
|
|
2968
|
+
// If we're not blocked on any other chunks, we can try to eagerly initialize
|
|
2969
|
+
// this as a fast-path to avoid awaiting them.
|
|
2970
|
+
var chunk = createResolvedModelChunk(response, json);
|
|
2971
|
+
initializeModelChunk(chunk);
|
|
2972
|
+
var initializedChunk = chunk;
|
|
2973
|
+
if (initializedChunk.status === INITIALIZED) {
|
|
2974
|
+
controller.enqueue(initializedChunk.value);
|
|
2975
|
+
} else {
|
|
2976
|
+
chunk.then(function (v) {
|
|
2977
|
+
return controller.enqueue(v);
|
|
2978
|
+
}, function (e) {
|
|
2979
|
+
return controller.error(e);
|
|
2980
|
+
});
|
|
2981
|
+
previousBlockedChunk = chunk;
|
|
2982
|
+
}
|
|
2983
|
+
} else {
|
|
2984
|
+
// We're still waiting on a previous chunk so we can't enqueue quite yet.
|
|
2985
|
+
var blockedChunk = previousBlockedChunk;
|
|
2986
|
+
var _chunk3 = createPendingChunk(response);
|
|
2987
|
+
_chunk3.then(function (v) {
|
|
2988
|
+
return controller.enqueue(v);
|
|
2989
|
+
}, function (e) {
|
|
2990
|
+
return controller.error(e);
|
|
2991
|
+
});
|
|
2992
|
+
previousBlockedChunk = _chunk3;
|
|
2993
|
+
blockedChunk.then(function () {
|
|
2994
|
+
if (previousBlockedChunk === _chunk3) {
|
|
2995
|
+
// We were still the last chunk so we can now clear the queue and return
|
|
2996
|
+
// to synchronous emitting.
|
|
2997
|
+
previousBlockedChunk = null;
|
|
2998
|
+
}
|
|
2999
|
+
resolveModelChunk(_chunk3, json);
|
|
3000
|
+
});
|
|
3001
|
+
}
|
|
3002
|
+
},
|
|
3003
|
+
close: function (json) {
|
|
3004
|
+
if (previousBlockedChunk === null) {
|
|
3005
|
+
controller.close();
|
|
3006
|
+
} else {
|
|
3007
|
+
var blockedChunk = previousBlockedChunk;
|
|
3008
|
+
// We shouldn't get any more enqueues after this so we can set it back to null.
|
|
3009
|
+
previousBlockedChunk = null;
|
|
3010
|
+
blockedChunk.then(function () {
|
|
3011
|
+
return controller.close();
|
|
3012
|
+
});
|
|
3013
|
+
}
|
|
3014
|
+
},
|
|
3015
|
+
error: function (error) {
|
|
3016
|
+
if (previousBlockedChunk === null) {
|
|
3017
|
+
// $FlowFixMe[incompatible-call]
|
|
3018
|
+
controller.error(error);
|
|
3019
|
+
} else {
|
|
3020
|
+
var blockedChunk = previousBlockedChunk;
|
|
3021
|
+
// We shouldn't get any more enqueues after this so we can set it back to null.
|
|
3022
|
+
previousBlockedChunk = null;
|
|
3023
|
+
blockedChunk.then(function () {
|
|
3024
|
+
return controller.error(error);
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
};
|
|
3029
|
+
resolveStream(response, id, stream, flightController);
|
|
3030
|
+
}
|
|
3031
|
+
function asyncIterator() {
|
|
3032
|
+
// Self referencing iterator.
|
|
3033
|
+
return this;
|
|
3034
|
+
}
|
|
3035
|
+
function createIterator(next) {
|
|
3036
|
+
var iterator = {
|
|
3037
|
+
next: next
|
|
3038
|
+
// TODO: Add return/throw as options for aborting.
|
|
3039
|
+
};
|
|
3040
|
+
// TODO: The iterator could inherit the AsyncIterator prototype which is not exposed as
|
|
3041
|
+
// a global but exists as a prototype of an AsyncGenerator. However, it's not needed
|
|
3042
|
+
// to satisfy the iterable protocol.
|
|
3043
|
+
iterator[ASYNC_ITERATOR] = asyncIterator;
|
|
3044
|
+
return iterator;
|
|
3045
|
+
}
|
|
3046
|
+
function startAsyncIterable(response, id, iterator) {
|
|
3047
|
+
var buffer = [];
|
|
3048
|
+
var closed = false;
|
|
3049
|
+
var nextWriteIndex = 0;
|
|
3050
|
+
var flightController = {
|
|
3051
|
+
enqueueValue: function (value) {
|
|
3052
|
+
if (nextWriteIndex === buffer.length) {
|
|
3053
|
+
buffer[nextWriteIndex] = createInitializedIteratorResultChunk(response, value, false);
|
|
3054
|
+
} else {
|
|
3055
|
+
var chunk = buffer[nextWriteIndex];
|
|
3056
|
+
var resolveListeners = chunk.value;
|
|
3057
|
+
var rejectListeners = chunk.reason;
|
|
3058
|
+
var initializedChunk = chunk;
|
|
3059
|
+
initializedChunk.status = INITIALIZED;
|
|
3060
|
+
initializedChunk.value = {
|
|
3061
|
+
done: false,
|
|
3062
|
+
value: value
|
|
3063
|
+
};
|
|
3064
|
+
if (resolveListeners !== null) {
|
|
3065
|
+
wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
3068
|
+
nextWriteIndex++;
|
|
3069
|
+
},
|
|
3070
|
+
enqueueModel: function (value) {
|
|
3071
|
+
if (nextWriteIndex === buffer.length) {
|
|
3072
|
+
buffer[nextWriteIndex] = createResolvedIteratorResultChunk(response, value, false);
|
|
3073
|
+
} else {
|
|
3074
|
+
resolveIteratorResultChunk(buffer[nextWriteIndex], value, false);
|
|
3075
|
+
}
|
|
3076
|
+
nextWriteIndex++;
|
|
3077
|
+
},
|
|
3078
|
+
close: function (value) {
|
|
3079
|
+
closed = true;
|
|
3080
|
+
if (nextWriteIndex === buffer.length) {
|
|
3081
|
+
buffer[nextWriteIndex] = createResolvedIteratorResultChunk(response, value, true);
|
|
3082
|
+
} else {
|
|
3083
|
+
resolveIteratorResultChunk(buffer[nextWriteIndex], value, true);
|
|
3084
|
+
}
|
|
3085
|
+
nextWriteIndex++;
|
|
3086
|
+
while (nextWriteIndex < buffer.length) {
|
|
3087
|
+
// In generators, any extra reads from the iterator have the value undefined.
|
|
3088
|
+
resolveIteratorResultChunk(buffer[nextWriteIndex++], '"$undefined"', true);
|
|
3089
|
+
}
|
|
3090
|
+
},
|
|
3091
|
+
error: function (error) {
|
|
3092
|
+
closed = true;
|
|
3093
|
+
if (nextWriteIndex === buffer.length) {
|
|
3094
|
+
buffer[nextWriteIndex] = createPendingChunk(response);
|
|
3095
|
+
}
|
|
3096
|
+
while (nextWriteIndex < buffer.length) {
|
|
3097
|
+
triggerErrorOnChunk(buffer[nextWriteIndex++], error);
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
};
|
|
3101
|
+
var iterable = _defineProperty({}, ASYNC_ITERATOR, function () {
|
|
3102
|
+
var nextReadIndex = 0;
|
|
3103
|
+
return createIterator(function (arg) {
|
|
3104
|
+
if (arg !== undefined) {
|
|
3105
|
+
throw new Error('Values cannot be passed to next() of AsyncIterables passed to Client Components.');
|
|
3106
|
+
}
|
|
3107
|
+
if (nextReadIndex === buffer.length) {
|
|
3108
|
+
if (closed) {
|
|
3109
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
|
3110
|
+
return new ReactPromise(INITIALIZED, {
|
|
3111
|
+
done: true,
|
|
3112
|
+
value: undefined
|
|
3113
|
+
}, null, response);
|
|
3114
|
+
}
|
|
3115
|
+
buffer[nextReadIndex] = createPendingChunk(response);
|
|
3116
|
+
}
|
|
3117
|
+
return buffer[nextReadIndex++];
|
|
3118
|
+
});
|
|
3119
|
+
});
|
|
3120
|
+
// TODO: If it's a single shot iterator we can optimize memory by cleaning up the buffer after
|
|
3121
|
+
// reading through the end, but currently we favor code size over this optimization.
|
|
3122
|
+
resolveStream(response, id, iterator ? iterable[ASYNC_ITERATOR]() : iterable, flightController);
|
|
3123
|
+
}
|
|
3124
|
+
function stopStream(response, id, row) {
|
|
3125
|
+
var chunks = response._chunks;
|
|
3126
|
+
var chunk = chunks.get(id);
|
|
3127
|
+
if (!chunk || chunk.status !== INITIALIZED) {
|
|
3128
|
+
// We didn't expect not to have an existing stream;
|
|
3129
|
+
return;
|
|
3130
|
+
}
|
|
3131
|
+
var streamChunk = chunk;
|
|
3132
|
+
var controller = streamChunk.reason;
|
|
3133
|
+
controller.close(row === '' ? '"$undefined"' : row);
|
|
3134
|
+
}
|
|
3135
|
+
function resolveErrorDev(response, errorInfo) {
|
|
3136
|
+
var name = errorInfo.name;
|
|
3137
|
+
var message = errorInfo.message;
|
|
3138
|
+
var stack = errorInfo.stack;
|
|
3139
|
+
var env = errorInfo.env;
|
|
3140
|
+
var error;
|
|
3141
|
+
var callStack = buildFakeCallStack(response, stack, env,
|
|
3142
|
+
// $FlowFixMe[incompatible-use]
|
|
3143
|
+
Error.bind(null, message || 'An error occurred in the Server Components render but no message was provided'));
|
|
3144
|
+
var rootTask = getRootTask(response, env);
|
|
3145
|
+
if (rootTask != null) {
|
|
3146
|
+
error = rootTask.run(callStack);
|
|
3147
|
+
} else {
|
|
3148
|
+
error = callStack();
|
|
3149
|
+
}
|
|
3150
|
+
error.name = name;
|
|
3151
|
+
error.environmentName = env;
|
|
3152
|
+
return error;
|
|
3153
|
+
}
|
|
3154
|
+
function resolvePostponeDev(response, id, reason, stack, env) {
|
|
3155
|
+
var postponeInstance;
|
|
3156
|
+
var callStack = buildFakeCallStack(response, stack, env,
|
|
3157
|
+
// $FlowFixMe[incompatible-use]
|
|
3158
|
+
Error.bind(null, reason || ''));
|
|
3159
|
+
var rootTask = response._debugRootTask;
|
|
3160
|
+
if (rootTask != null) {
|
|
3161
|
+
postponeInstance = rootTask.run(callStack);
|
|
3162
|
+
} else {
|
|
3163
|
+
postponeInstance = callStack();
|
|
3164
|
+
}
|
|
3165
|
+
postponeInstance.$$typeof = REACT_POSTPONE_TYPE;
|
|
3166
|
+
var chunks = response._chunks;
|
|
3167
|
+
var chunk = chunks.get(id);
|
|
3168
|
+
if (!chunk) {
|
|
3169
|
+
chunks.set(id, createErrorChunk(response, postponeInstance));
|
|
3170
|
+
} else {
|
|
3171
|
+
triggerErrorOnChunk(chunk, postponeInstance);
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
function resolveHint(response, code, model) {
|
|
3175
|
+
var hintModel = parseModel(response, model);
|
|
3176
|
+
dispatchHint(code, hintModel);
|
|
3177
|
+
}
|
|
3178
|
+
var supportsCreateTask = !!console.createTask;
|
|
3179
|
+
var fakeFunctionCache = new Map() ;
|
|
3180
|
+
var fakeFunctionIdx = 0;
|
|
3181
|
+
function createFakeFunction(name, filename, sourceMap, line, col, environmentName) {
|
|
3182
|
+
// This creates a fake copy of a Server Module. It represents a module that has already
|
|
3183
|
+
// executed on the server but we re-execute a blank copy for its stack frames on the client.
|
|
3184
|
+
|
|
3185
|
+
var comment = '/* This module was rendered by a Server Component. Turn on Source Maps to see the server source. */';
|
|
3186
|
+
if (!name) {
|
|
3187
|
+
// An eval:ed function with no name gets the name "eval". We give it something more descriptive.
|
|
3188
|
+
name = '<anonymous>';
|
|
3189
|
+
}
|
|
3190
|
+
var encodedName = JSON.stringify(name);
|
|
3191
|
+
// We generate code where the call is at the line and column of the server executed code.
|
|
3192
|
+
// This allows us to use the original source map as the source map of this fake file to
|
|
3193
|
+
// point to the original source.
|
|
3194
|
+
var code;
|
|
3195
|
+
if (line <= 1) {
|
|
3196
|
+
var minSize = encodedName.length + 7;
|
|
3197
|
+
code = '({' + encodedName + ':_=>' + ' '.repeat(col < minSize ? 0 : col - minSize) + '_()})\n' + comment;
|
|
3198
|
+
} else {
|
|
3199
|
+
code = comment + '\n'.repeat(line - 2) + '({' + encodedName + ':_=>\n' + ' '.repeat(col < 1 ? 0 : col - 1) + '_()})';
|
|
3200
|
+
}
|
|
3201
|
+
if (filename.startsWith('/')) {
|
|
3202
|
+
// If the filename starts with `/` we assume that it is a file system file
|
|
3203
|
+
// rather than relative to the current host. Since on the server fully qualified
|
|
3204
|
+
// stack traces use the file path.
|
|
3205
|
+
// TODO: What does this look like on Windows?
|
|
3206
|
+
filename = 'file://' + filename;
|
|
3207
|
+
}
|
|
3208
|
+
if (sourceMap) {
|
|
3209
|
+
// We use the prefix rsc://React/ to separate these from other files listed in
|
|
3210
|
+
// the Chrome DevTools. We need a "host name" and not just a protocol because
|
|
3211
|
+
// otherwise the group name becomes the root folder. Ideally we don't want to
|
|
3212
|
+
// show these at all but there's two reasons to assign a fake URL.
|
|
3213
|
+
// 1) A printed stack trace string needs a unique URL to be able to source map it.
|
|
3214
|
+
// 2) If source maps are disabled or fails, you should at least be able to tell
|
|
3215
|
+
// which file it was.
|
|
3216
|
+
code += '\n//# sourceURL=rsc://React/' + encodeURIComponent(environmentName) + '/' + encodeURI(filename) + '?' + fakeFunctionIdx++;
|
|
3217
|
+
code += '\n//# sourceMappingURL=' + sourceMap;
|
|
3218
|
+
} else if (filename) {
|
|
3219
|
+
code += '\n//# sourceURL=' + encodeURI(filename);
|
|
3220
|
+
} else {
|
|
3221
|
+
code += '\n//# sourceURL=<anonymous>';
|
|
3222
|
+
}
|
|
3223
|
+
var fn;
|
|
3224
|
+
try {
|
|
3225
|
+
|
|
3226
|
+
fn = (0, eval)(code)[name];
|
|
3227
|
+
} catch (x) {
|
|
3228
|
+
// If eval fails, such as if in an environment that doesn't support it,
|
|
3229
|
+
// we fallback to creating a function here. It'll still have the right
|
|
3230
|
+
// name but it'll lose line/column number and file name.
|
|
3231
|
+
fn = function (_) {
|
|
3232
|
+
return _();
|
|
3233
|
+
};
|
|
3234
|
+
}
|
|
3235
|
+
return fn;
|
|
3236
|
+
}
|
|
3237
|
+
function buildFakeCallStack(response, stack, environmentName, innerCall) {
|
|
3238
|
+
var callStack = innerCall;
|
|
3239
|
+
for (var i = 0; i < stack.length; i++) {
|
|
3240
|
+
var frame = stack[i];
|
|
3241
|
+
var frameKey = frame.join('-') + '-' + environmentName;
|
|
3242
|
+
var fn = fakeFunctionCache.get(frameKey);
|
|
3243
|
+
if (fn === undefined) {
|
|
3244
|
+
var name = frame[0],
|
|
3245
|
+
filename = frame[1],
|
|
3246
|
+
line = frame[2],
|
|
3247
|
+
col = frame[3];
|
|
3248
|
+
var findSourceMapURL = response._debugFindSourceMapURL;
|
|
3249
|
+
var sourceMap = findSourceMapURL ? findSourceMapURL(filename, environmentName) : null;
|
|
3250
|
+
fn = createFakeFunction(name, filename, sourceMap, line, col, environmentName);
|
|
3251
|
+
// TODO: This cache should technically live on the response since the _debugFindSourceMapURL
|
|
3252
|
+
// function is an input and can vary by response.
|
|
3253
|
+
fakeFunctionCache.set(frameKey, fn);
|
|
3254
|
+
}
|
|
3255
|
+
callStack = fn.bind(null, callStack);
|
|
3256
|
+
}
|
|
3257
|
+
return callStack;
|
|
3258
|
+
}
|
|
3259
|
+
function getRootTask(response, childEnvironmentName) {
|
|
3260
|
+
var rootTask = response._debugRootTask;
|
|
3261
|
+
if (!rootTask) {
|
|
3262
|
+
return null;
|
|
3263
|
+
}
|
|
3264
|
+
if (response._rootEnvironmentName !== childEnvironmentName) {
|
|
3265
|
+
// If the root most owner component is itself in a different environment than the requested
|
|
3266
|
+
// environment then we create an extra task to indicate that we're transitioning into it.
|
|
3267
|
+
// Like if one environment just requests another environment.
|
|
3268
|
+
var createTaskFn = console.createTask.bind(console, '"use ' + childEnvironmentName.toLowerCase() + '"');
|
|
3269
|
+
return rootTask.run(createTaskFn);
|
|
3270
|
+
}
|
|
3271
|
+
return rootTask;
|
|
3272
|
+
}
|
|
3273
|
+
function initializeFakeTask(response, debugInfo, childEnvironmentName) {
|
|
3274
|
+
if (!supportsCreateTask) {
|
|
3275
|
+
return null;
|
|
3276
|
+
}
|
|
3277
|
+
var componentInfo = debugInfo; // Refined
|
|
3278
|
+
if (debugInfo.stack == null) {
|
|
3279
|
+
// If this is an error, we should've really already initialized the task.
|
|
3280
|
+
// If it's null, we can't initialize a task.
|
|
3281
|
+
return null;
|
|
3282
|
+
}
|
|
3283
|
+
var stack = debugInfo.stack;
|
|
3284
|
+
var env = componentInfo.env == null ? response._rootEnvironmentName : componentInfo.env;
|
|
3285
|
+
if (env !== childEnvironmentName) {
|
|
3286
|
+
// This is the boundary between two environments so we'll annotate the task name.
|
|
3287
|
+
// That is unusual so we don't cache it.
|
|
3288
|
+
var ownerTask = componentInfo.owner == null ? null : initializeFakeTask(response, componentInfo.owner, env);
|
|
3289
|
+
return buildFakeTask(response, ownerTask, stack, '"use ' + childEnvironmentName.toLowerCase() + '"', env);
|
|
3290
|
+
} else {
|
|
3291
|
+
var cachedEntry = componentInfo.debugTask;
|
|
3292
|
+
if (cachedEntry !== undefined) {
|
|
3293
|
+
return cachedEntry;
|
|
3294
|
+
}
|
|
3295
|
+
var _ownerTask = componentInfo.owner == null ? null : initializeFakeTask(response, componentInfo.owner, env);
|
|
3296
|
+
// $FlowFixMe[cannot-write]: We consider this part of initialization.
|
|
3297
|
+
return componentInfo.debugTask = buildFakeTask(response, _ownerTask, stack, getServerComponentTaskName(componentInfo), env);
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
function buildFakeTask(response, ownerTask, stack, taskName, env) {
|
|
3301
|
+
var createTaskFn = console.createTask.bind(console, taskName);
|
|
3302
|
+
var callStack = buildFakeCallStack(response, stack, env, createTaskFn);
|
|
3303
|
+
if (ownerTask === null) {
|
|
3304
|
+
var rootTask = getRootTask(response, env);
|
|
3305
|
+
if (rootTask != null) {
|
|
3306
|
+
return rootTask.run(callStack);
|
|
3307
|
+
} else {
|
|
3308
|
+
return callStack();
|
|
3309
|
+
}
|
|
3310
|
+
} else {
|
|
3311
|
+
return ownerTask.run(callStack);
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
var createFakeJSXCallStack = {
|
|
3315
|
+
'react-stack-bottom-frame': function (response, stack, environmentName) {
|
|
3316
|
+
var callStackForError = buildFakeCallStack(response, stack, environmentName, fakeJSXCallSite);
|
|
3317
|
+
return callStackForError();
|
|
3318
|
+
}
|
|
3319
|
+
};
|
|
3320
|
+
var createFakeJSXCallStackInDEV = // We use this technique to trick minifiers to preserve the function name.
|
|
3321
|
+
createFakeJSXCallStack['react-stack-bottom-frame'].bind(createFakeJSXCallStack) ;
|
|
3322
|
+
|
|
3323
|
+
/** @noinline */
|
|
3324
|
+
function fakeJSXCallSite() {
|
|
3325
|
+
// This extra call frame represents the JSX creation function. We always pop this frame
|
|
3326
|
+
// off before presenting so it needs to be part of the stack.
|
|
3327
|
+
return new Error('react-stack-top-frame');
|
|
3328
|
+
}
|
|
3329
|
+
function initializeFakeStack(response, debugInfo) {
|
|
3330
|
+
var cachedEntry = debugInfo.debugStack;
|
|
3331
|
+
if (cachedEntry !== undefined) {
|
|
3332
|
+
return;
|
|
3333
|
+
}
|
|
3334
|
+
if (debugInfo.stack != null) {
|
|
3335
|
+
var stack = debugInfo.stack;
|
|
3336
|
+
var env = debugInfo.env == null ? '' : debugInfo.env;
|
|
3337
|
+
// $FlowFixMe[cannot-write]
|
|
3338
|
+
debugInfo.debugStack = createFakeJSXCallStackInDEV(response, stack, env);
|
|
3339
|
+
}
|
|
3340
|
+
if (debugInfo.owner != null) {
|
|
3341
|
+
// Initialize any owners not yet initialized.
|
|
3342
|
+
initializeFakeStack(response, debugInfo.owner);
|
|
3343
|
+
}
|
|
3344
|
+
}
|
|
3345
|
+
function resolveDebugInfo(response, id, debugInfo) {
|
|
3346
|
+
// We eagerly initialize the fake task because this resolving happens outside any
|
|
3347
|
+
// render phase so we're not inside a user space stack at this point. If we waited
|
|
3348
|
+
// to initialize it when we need it, we might be inside user code.
|
|
3349
|
+
var env = debugInfo.env === undefined ? response._rootEnvironmentName : debugInfo.env;
|
|
3350
|
+
if (debugInfo.stack !== undefined) {
|
|
3351
|
+
var componentInfoOrAsyncInfo =
|
|
3352
|
+
// $FlowFixMe[incompatible-type]
|
|
3353
|
+
debugInfo;
|
|
3354
|
+
initializeFakeTask(response, componentInfoOrAsyncInfo, env);
|
|
3355
|
+
}
|
|
3356
|
+
if (debugInfo.owner === null && response._debugRootOwner != null) {
|
|
3357
|
+
// $FlowFixMe[prop-missing] By narrowing `owner` to `null`, we narrowed `debugInfo` to `ReactComponentInfo`
|
|
3358
|
+
var componentInfo = debugInfo;
|
|
3359
|
+
// $FlowFixMe[cannot-write]
|
|
3360
|
+
componentInfo.owner = response._debugRootOwner;
|
|
3361
|
+
// We override the stack if we override the owner since the stack where the root JSX
|
|
3362
|
+
// was created on the server isn't very useful but where the request was made is.
|
|
3363
|
+
// $FlowFixMe[cannot-write]
|
|
3364
|
+
componentInfo.debugStack = response._debugRootStack;
|
|
3365
|
+
} else if (debugInfo.stack !== undefined) {
|
|
3366
|
+
var _componentInfoOrAsyncInfo =
|
|
3367
|
+
// $FlowFixMe[incompatible-type]
|
|
3368
|
+
debugInfo;
|
|
3369
|
+
initializeFakeStack(response, _componentInfoOrAsyncInfo);
|
|
3370
|
+
}
|
|
3371
|
+
{
|
|
3372
|
+
if (typeof debugInfo.time === 'number') {
|
|
3373
|
+
// Adjust the time to the current environment's time space.
|
|
3374
|
+
// Since this might be a deduped object, we clone it to avoid
|
|
3375
|
+
// applying the adjustment twice.
|
|
3376
|
+
debugInfo = {
|
|
3377
|
+
time: debugInfo.time + response._timeOrigin
|
|
3378
|
+
};
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
var chunk = getChunk(response, id);
|
|
3382
|
+
var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
|
|
3383
|
+
chunkDebugInfo.push(debugInfo);
|
|
3384
|
+
}
|
|
3385
|
+
var currentOwnerInDEV = null;
|
|
3386
|
+
function getCurrentStackInDEV() {
|
|
3387
|
+
{
|
|
3388
|
+
var owner = currentOwnerInDEV;
|
|
3389
|
+
if (owner === null) {
|
|
3390
|
+
return '';
|
|
3391
|
+
}
|
|
3392
|
+
return getOwnerStackByComponentInfoInDev(owner);
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
var replayConsoleWithCallStack = {
|
|
3396
|
+
'react-stack-bottom-frame': function (response, methodName, stackTrace, owner, env, args) {
|
|
3397
|
+
// There really shouldn't be anything else on the stack atm.
|
|
3398
|
+
var prevStack = ReactSharedInternals.getCurrentStack;
|
|
3399
|
+
ReactSharedInternals.getCurrentStack = getCurrentStackInDEV;
|
|
3400
|
+
currentOwnerInDEV = owner === null ? response._debugRootOwner : owner;
|
|
3401
|
+
try {
|
|
3402
|
+
var callStack = buildFakeCallStack(response, stackTrace, env, bindToConsole(methodName, args, env));
|
|
3403
|
+
if (owner != null) {
|
|
3404
|
+
var task = initializeFakeTask(response, owner, env);
|
|
3405
|
+
initializeFakeStack(response, owner);
|
|
3406
|
+
if (task !== null) {
|
|
3407
|
+
task.run(callStack);
|
|
3408
|
+
return;
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
var rootTask = getRootTask(response, env);
|
|
3412
|
+
if (rootTask != null) {
|
|
3413
|
+
rootTask.run(callStack);
|
|
3414
|
+
return;
|
|
3415
|
+
}
|
|
3416
|
+
callStack();
|
|
3417
|
+
} finally {
|
|
3418
|
+
currentOwnerInDEV = null;
|
|
3419
|
+
ReactSharedInternals.getCurrentStack = prevStack;
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
};
|
|
3423
|
+
var replayConsoleWithCallStackInDEV = // We use this technique to trick minifiers to preserve the function name.
|
|
3424
|
+
replayConsoleWithCallStack['react-stack-bottom-frame'].bind(replayConsoleWithCallStack) ;
|
|
3425
|
+
function resolveConsoleEntry(response, value) {
|
|
3426
|
+
if (!response._replayConsole) {
|
|
3427
|
+
return;
|
|
3428
|
+
}
|
|
3429
|
+
var payload = parseModel(response, value);
|
|
3430
|
+
var methodName = payload[0];
|
|
3431
|
+
var stackTrace = payload[1];
|
|
3432
|
+
var owner = payload[2];
|
|
3433
|
+
var env = payload[3];
|
|
3434
|
+
var args = payload.slice(4);
|
|
3435
|
+
replayConsoleWithCallStackInDEV(response, methodName, stackTrace, owner, env, args);
|
|
3436
|
+
}
|
|
3437
|
+
function mergeBuffer(buffer, lastChunk) {
|
|
3438
|
+
var l = buffer.length;
|
|
3439
|
+
// Count the bytes we'll need
|
|
3440
|
+
var byteLength = lastChunk.length;
|
|
3441
|
+
for (var i = 0; i < l; i++) {
|
|
3442
|
+
byteLength += buffer[i].byteLength;
|
|
3443
|
+
}
|
|
3444
|
+
// Allocate enough contiguous space
|
|
3445
|
+
var result = new Uint8Array(byteLength);
|
|
3446
|
+
var offset = 0;
|
|
3447
|
+
// Copy all the buffers into it.
|
|
3448
|
+
for (var _i2 = 0; _i2 < l; _i2++) {
|
|
3449
|
+
var chunk = buffer[_i2];
|
|
3450
|
+
result.set(chunk, offset);
|
|
3451
|
+
offset += chunk.byteLength;
|
|
3452
|
+
}
|
|
3453
|
+
result.set(lastChunk, offset);
|
|
3454
|
+
return result;
|
|
3455
|
+
}
|
|
3456
|
+
function resolveTypedArray(response, id, buffer, lastChunk, constructor, bytesPerElement) {
|
|
3457
|
+
// If the view fits into one original buffer, we just reuse that buffer instead of
|
|
3458
|
+
// copying it out to a separate copy. This means that it's not always possible to
|
|
3459
|
+
// transfer these values to other threads without copying first since they may
|
|
3460
|
+
// share array buffer. For this to work, it must also have bytes aligned to a
|
|
3461
|
+
// multiple of a size of the type.
|
|
3462
|
+
var chunk = buffer.length === 0 && lastChunk.byteOffset % bytesPerElement === 0 ? lastChunk : mergeBuffer(buffer, lastChunk);
|
|
3463
|
+
// TODO: The transfer protocol of RSC is little-endian. If the client isn't little-endian
|
|
3464
|
+
// we should convert it instead. In practice big endian isn't really Web compatible so it's
|
|
3465
|
+
// somewhat safe to assume that browsers aren't going to run it, but maybe there's some SSR
|
|
3466
|
+
// server that's affected.
|
|
3467
|
+
var view = new constructor(chunk.buffer, chunk.byteOffset, chunk.byteLength / bytesPerElement);
|
|
3468
|
+
resolveBuffer(response, id, view);
|
|
3469
|
+
}
|
|
3470
|
+
function flushComponentPerformance(response, root, trackIdx,
|
|
3471
|
+
// Next available track
|
|
3472
|
+
trackTime,
|
|
3473
|
+
// The time after which it is available,
|
|
3474
|
+
parentEndTime) {
|
|
3475
|
+
// Write performance.measure() entries for Server Components in tree order.
|
|
3476
|
+
// This must be done at the end to collect the end time from the whole tree.
|
|
3477
|
+
if (!isArray(root._children)) {
|
|
3478
|
+
// We have already written this chunk. If this was a cycle, then this will
|
|
3479
|
+
// be -Infinity and it won't contribute to the parent end time.
|
|
3480
|
+
// If this was already emitted by another sibling then we reused the same
|
|
3481
|
+
// chunk in two places. We should extend the current end time as if it was
|
|
3482
|
+
// rendered as part of this tree.
|
|
3483
|
+
var previousResult = root._children;
|
|
3484
|
+
var previousEndTime = previousResult.endTime;
|
|
3485
|
+
if (parentEndTime > -Infinity && parentEndTime < previousEndTime && previousResult.component !== null) {
|
|
3486
|
+
// Log a placeholder for the deduped value under this child starting
|
|
3487
|
+
// from the end of the self time of the parent and spanning until the
|
|
3488
|
+
// the deduped end.
|
|
3489
|
+
logDedupedComponentRender(previousResult.component, trackIdx, parentEndTime, previousEndTime);
|
|
3490
|
+
}
|
|
3491
|
+
// Since we didn't bump the track this time, we just return the same track.
|
|
3492
|
+
previousResult.track = trackIdx;
|
|
3493
|
+
return previousResult;
|
|
3494
|
+
}
|
|
3495
|
+
var children = root._children;
|
|
3496
|
+
if (root.status === RESOLVED_MODEL) {
|
|
3497
|
+
// If the model is not initialized by now, do that now so we can find its
|
|
3498
|
+
// children. This part is a little sketchy since it significantly changes
|
|
3499
|
+
// the performance characteristics of the app by profiling.
|
|
3500
|
+
initializeModelChunk(root);
|
|
3501
|
+
}
|
|
3502
|
+
|
|
3503
|
+
// First find the start time of the first component to know if it was running
|
|
3504
|
+
// in parallel with the previous.
|
|
3505
|
+
var debugInfo = root._debugInfo;
|
|
3506
|
+
if (debugInfo) {
|
|
3507
|
+
for (var i = 1; i < debugInfo.length; i++) {
|
|
3508
|
+
var info = debugInfo[i];
|
|
3509
|
+
if (typeof info.name === 'string') {
|
|
3510
|
+
// $FlowFixMe: Refined.
|
|
3511
|
+
var startTimeInfo = debugInfo[i - 1];
|
|
3512
|
+
if (typeof startTimeInfo.time === 'number') {
|
|
3513
|
+
var startTime = startTimeInfo.time;
|
|
3514
|
+
if (startTime < trackTime) {
|
|
3515
|
+
// The start time of this component is before the end time of the previous
|
|
3516
|
+
// component on this track so we need to bump the next one to a parallel track.
|
|
3517
|
+
trackIdx++;
|
|
3518
|
+
}
|
|
3519
|
+
trackTime = startTime;
|
|
3520
|
+
break;
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3524
|
+
for (var _i3 = debugInfo.length - 1; _i3 >= 0; _i3--) {
|
|
3525
|
+
var _info = debugInfo[_i3];
|
|
3526
|
+
if (typeof _info.time === 'number') {
|
|
3527
|
+
if (_info.time > parentEndTime) {
|
|
3528
|
+
parentEndTime = _info.time;
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
var result = {
|
|
3534
|
+
track: trackIdx,
|
|
3535
|
+
endTime: -Infinity,
|
|
3536
|
+
component: null
|
|
3537
|
+
};
|
|
3538
|
+
root._children = result;
|
|
3539
|
+
var childrenEndTime = -Infinity;
|
|
3540
|
+
var childTrackIdx = trackIdx;
|
|
3541
|
+
var childTrackTime = trackTime;
|
|
3542
|
+
for (var _i4 = 0; _i4 < children.length; _i4++) {
|
|
3543
|
+
var childResult = flushComponentPerformance(response, children[_i4], childTrackIdx, childTrackTime, parentEndTime);
|
|
3544
|
+
if (childResult.component !== null) {
|
|
3545
|
+
result.component = childResult.component;
|
|
3546
|
+
}
|
|
3547
|
+
childTrackIdx = childResult.track;
|
|
3548
|
+
var childEndTime = childResult.endTime;
|
|
3549
|
+
childTrackTime = childEndTime;
|
|
3550
|
+
if (childEndTime > childrenEndTime) {
|
|
3551
|
+
childrenEndTime = childEndTime;
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
if (debugInfo) {
|
|
3555
|
+
var endTime = 0;
|
|
3556
|
+
var isLastComponent = true;
|
|
3557
|
+
for (var _i5 = debugInfo.length - 1; _i5 >= 0; _i5--) {
|
|
3558
|
+
var _info2 = debugInfo[_i5];
|
|
3559
|
+
if (typeof _info2.time === 'number') {
|
|
3560
|
+
endTime = _info2.time;
|
|
3561
|
+
if (endTime > childrenEndTime) {
|
|
3562
|
+
childrenEndTime = endTime;
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
if (typeof _info2.name === 'string' && _i5 > 0) {
|
|
3566
|
+
// $FlowFixMe: Refined.
|
|
3567
|
+
var componentInfo = _info2;
|
|
3568
|
+
var _startTimeInfo = debugInfo[_i5 - 1];
|
|
3569
|
+
if (typeof _startTimeInfo.time === 'number') {
|
|
3570
|
+
var _startTime = _startTimeInfo.time;
|
|
3571
|
+
if (isLastComponent && root.status === ERRORED && root.reason !== response._closedReason) {
|
|
3572
|
+
// If this is the last component to render before this chunk rejected, then conceptually
|
|
3573
|
+
// this component errored. If this was a cancellation then it wasn't this component that
|
|
3574
|
+
// errored.
|
|
3575
|
+
logComponentErrored(componentInfo, trackIdx, _startTime, endTime, childrenEndTime, response._rootEnvironmentName, root.reason);
|
|
3576
|
+
} else {
|
|
3577
|
+
logComponentRender(componentInfo, trackIdx, _startTime, endTime, childrenEndTime, response._rootEnvironmentName);
|
|
3578
|
+
}
|
|
3579
|
+
// Track the root most component of the result for deduping logging.
|
|
3580
|
+
result.component = componentInfo;
|
|
3581
|
+
}
|
|
3582
|
+
isLastComponent = false;
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
result.endTime = childrenEndTime;
|
|
3587
|
+
return result;
|
|
3588
|
+
}
|
|
3589
|
+
function processFullBinaryRow(response, id, tag, buffer, chunk) {
|
|
3590
|
+
switch (tag) {
|
|
3591
|
+
case 65 /* "A" */:
|
|
3592
|
+
// We must always clone to extract it into a separate buffer instead of just a view.
|
|
3593
|
+
resolveBuffer(response, id, mergeBuffer(buffer, chunk).buffer);
|
|
3594
|
+
return;
|
|
3595
|
+
case 79 /* "O" */:
|
|
3596
|
+
resolveTypedArray(response, id, buffer, chunk, Int8Array, 1);
|
|
3597
|
+
return;
|
|
3598
|
+
case 111 /* "o" */:
|
|
3599
|
+
resolveBuffer(response, id, buffer.length === 0 ? chunk : mergeBuffer(buffer, chunk));
|
|
3600
|
+
return;
|
|
3601
|
+
case 85 /* "U" */:
|
|
3602
|
+
resolveTypedArray(response, id, buffer, chunk, Uint8ClampedArray, 1);
|
|
3603
|
+
return;
|
|
3604
|
+
case 83 /* "S" */:
|
|
3605
|
+
resolveTypedArray(response, id, buffer, chunk, Int16Array, 2);
|
|
3606
|
+
return;
|
|
3607
|
+
case 115 /* "s" */:
|
|
3608
|
+
resolveTypedArray(response, id, buffer, chunk, Uint16Array, 2);
|
|
3609
|
+
return;
|
|
3610
|
+
case 76 /* "L" */:
|
|
3611
|
+
resolveTypedArray(response, id, buffer, chunk, Int32Array, 4);
|
|
3612
|
+
return;
|
|
3613
|
+
case 108 /* "l" */:
|
|
3614
|
+
resolveTypedArray(response, id, buffer, chunk, Uint32Array, 4);
|
|
3615
|
+
return;
|
|
3616
|
+
case 71 /* "G" */:
|
|
3617
|
+
resolveTypedArray(response, id, buffer, chunk, Float32Array, 4);
|
|
3618
|
+
return;
|
|
3619
|
+
case 103 /* "g" */:
|
|
3620
|
+
resolveTypedArray(response, id, buffer, chunk, Float64Array, 8);
|
|
3621
|
+
return;
|
|
3622
|
+
case 77 /* "M" */:
|
|
3623
|
+
resolveTypedArray(response, id, buffer, chunk, BigInt64Array, 8);
|
|
3624
|
+
return;
|
|
3625
|
+
case 109 /* "m" */:
|
|
3626
|
+
resolveTypedArray(response, id, buffer, chunk, BigUint64Array, 8);
|
|
3627
|
+
return;
|
|
3628
|
+
case 86 /* "V" */:
|
|
3629
|
+
resolveTypedArray(response, id, buffer, chunk, DataView, 1);
|
|
3630
|
+
return;
|
|
3631
|
+
}
|
|
3632
|
+
var stringDecoder = response._stringDecoder;
|
|
3633
|
+
var row = '';
|
|
3634
|
+
for (var i = 0; i < buffer.length; i++) {
|
|
3635
|
+
row += readPartialStringChunk(stringDecoder, buffer[i]);
|
|
3636
|
+
}
|
|
3637
|
+
row += readFinalStringChunk(stringDecoder, chunk);
|
|
3638
|
+
processFullStringRow(response, id, tag, row);
|
|
3639
|
+
}
|
|
3640
|
+
function processFullStringRow(response, id, tag, row) {
|
|
3641
|
+
switch (tag) {
|
|
3642
|
+
case 73 /* "I" */:
|
|
3643
|
+
{
|
|
3644
|
+
resolveModule(response, id, row);
|
|
3645
|
+
return;
|
|
3646
|
+
}
|
|
3647
|
+
case 72 /* "H" */:
|
|
3648
|
+
{
|
|
3649
|
+
var code = row[0];
|
|
3650
|
+
resolveHint(response, code, row.slice(1));
|
|
3651
|
+
return;
|
|
3652
|
+
}
|
|
3653
|
+
case 69 /* "E" */:
|
|
3654
|
+
{
|
|
3655
|
+
var errorInfo = JSON.parse(row);
|
|
3656
|
+
var error;
|
|
3657
|
+
{
|
|
3658
|
+
error = resolveErrorDev(response, errorInfo);
|
|
3659
|
+
}
|
|
3660
|
+
error.digest = errorInfo.digest;
|
|
3661
|
+
var errorWithDigest = error;
|
|
3662
|
+
var chunks = response._chunks;
|
|
3663
|
+
var chunk = chunks.get(id);
|
|
3664
|
+
if (!chunk) {
|
|
3665
|
+
chunks.set(id, createErrorChunk(response, errorWithDigest));
|
|
3666
|
+
} else {
|
|
3667
|
+
triggerErrorOnChunk(chunk, errorWithDigest);
|
|
3668
|
+
}
|
|
3669
|
+
return;
|
|
3670
|
+
}
|
|
3671
|
+
case 84 /* "T" */:
|
|
3672
|
+
{
|
|
3673
|
+
resolveText(response, id, row);
|
|
3674
|
+
return;
|
|
3675
|
+
}
|
|
3676
|
+
case 78 /* "N" */:
|
|
3677
|
+
{
|
|
3678
|
+
{
|
|
3679
|
+
// Track the time origin for future debug info. We track it relative
|
|
3680
|
+
// to the current environment's time space.
|
|
3681
|
+
var timeOrigin = +row;
|
|
3682
|
+
response._timeOrigin = timeOrigin -
|
|
3683
|
+
// $FlowFixMe[prop-missing]
|
|
3684
|
+
performance.timeOrigin;
|
|
3685
|
+
return;
|
|
3686
|
+
}
|
|
3687
|
+
// Fallthrough to share the error with Debug and Console entries.
|
|
3688
|
+
}
|
|
3689
|
+
case 68 /* "D" */:
|
|
3690
|
+
{
|
|
3691
|
+
{
|
|
3692
|
+
var _chunk4 = createResolvedModelChunk(response, row);
|
|
3693
|
+
initializeModelChunk(_chunk4);
|
|
3694
|
+
var initializedChunk = _chunk4;
|
|
3695
|
+
if (initializedChunk.status === INITIALIZED) {
|
|
3696
|
+
resolveDebugInfo(response, id, initializedChunk.value);
|
|
3697
|
+
} else {
|
|
3698
|
+
// TODO: This is not going to resolve in the right order if there's more than one.
|
|
3699
|
+
_chunk4.then(function (v) {
|
|
3700
|
+
return resolveDebugInfo(response, id, v);
|
|
3701
|
+
}, function (e) {
|
|
3702
|
+
// Ignore debug info errors for now. Unnecessary noise.
|
|
3703
|
+
});
|
|
3704
|
+
}
|
|
3705
|
+
return;
|
|
3706
|
+
}
|
|
3707
|
+
// Fallthrough to share the error with Console entries.
|
|
3708
|
+
}
|
|
3709
|
+
case 87 /* "W" */:
|
|
3710
|
+
{
|
|
3711
|
+
{
|
|
3712
|
+
resolveConsoleEntry(response, row);
|
|
3713
|
+
return;
|
|
3714
|
+
}
|
|
3715
|
+
}
|
|
3716
|
+
case 82 /* "R" */:
|
|
3717
|
+
{
|
|
3718
|
+
startReadableStream(response, id, undefined);
|
|
3719
|
+
return;
|
|
3720
|
+
}
|
|
3721
|
+
// Fallthrough
|
|
3722
|
+
case 114 /* "r" */:
|
|
3723
|
+
{
|
|
3724
|
+
startReadableStream(response, id, 'bytes');
|
|
3725
|
+
return;
|
|
3726
|
+
}
|
|
3727
|
+
// Fallthrough
|
|
3728
|
+
case 88 /* "X" */:
|
|
3729
|
+
{
|
|
3730
|
+
startAsyncIterable(response, id, false);
|
|
3731
|
+
return;
|
|
3732
|
+
}
|
|
3733
|
+
// Fallthrough
|
|
3734
|
+
case 120 /* "x" */:
|
|
3735
|
+
{
|
|
3736
|
+
startAsyncIterable(response, id, true);
|
|
3737
|
+
return;
|
|
3738
|
+
}
|
|
3739
|
+
// Fallthrough
|
|
3740
|
+
case 67 /* "C" */:
|
|
3741
|
+
{
|
|
3742
|
+
stopStream(response, id, row);
|
|
3743
|
+
return;
|
|
3744
|
+
}
|
|
3745
|
+
// Fallthrough
|
|
3746
|
+
case 80 /* "P" */:
|
|
3747
|
+
{
|
|
3748
|
+
{
|
|
3749
|
+
{
|
|
3750
|
+
var postponeInfo = JSON.parse(row);
|
|
3751
|
+
resolvePostponeDev(response, id, postponeInfo.reason, postponeInfo.stack, postponeInfo.env);
|
|
3752
|
+
}
|
|
3753
|
+
return;
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
// Fallthrough
|
|
3757
|
+
default:
|
|
3758
|
+
/* """ "{" "[" "t" "f" "n" "0" - "9" */{
|
|
3759
|
+
// We assume anything else is JSON.
|
|
3760
|
+
resolveModel(response, id, row);
|
|
3761
|
+
return;
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3764
|
+
}
|
|
3765
|
+
function processBinaryChunk(response, chunk) {
|
|
3766
|
+
var i = 0;
|
|
3767
|
+
var rowState = response._rowState;
|
|
3768
|
+
var rowID = response._rowID;
|
|
3769
|
+
var rowTag = response._rowTag;
|
|
3770
|
+
var rowLength = response._rowLength;
|
|
3771
|
+
var buffer = response._buffer;
|
|
3772
|
+
var chunkLength = chunk.length;
|
|
3773
|
+
while (i < chunkLength) {
|
|
3774
|
+
var lastIdx = -1;
|
|
3775
|
+
switch (rowState) {
|
|
3776
|
+
case ROW_ID:
|
|
3777
|
+
{
|
|
3778
|
+
var byte = chunk[i++];
|
|
3779
|
+
if (byte === 58 /* ":" */) {
|
|
3780
|
+
// Finished the rowID, next we'll parse the tag.
|
|
3781
|
+
rowState = ROW_TAG;
|
|
3782
|
+
} else {
|
|
3783
|
+
rowID = rowID << 4 | (byte > 96 ? byte - 87 : byte - 48);
|
|
3784
|
+
}
|
|
3785
|
+
continue;
|
|
3786
|
+
}
|
|
3787
|
+
case ROW_TAG:
|
|
3788
|
+
{
|
|
3789
|
+
var resolvedRowTag = chunk[i];
|
|
3790
|
+
if (resolvedRowTag === 84 /* "T" */ || resolvedRowTag === 65 /* "A" */ || resolvedRowTag === 79 /* "O" */ || resolvedRowTag === 111 /* "o" */ || resolvedRowTag === 85 /* "U" */ || resolvedRowTag === 83 /* "S" */ || resolvedRowTag === 115 /* "s" */ || resolvedRowTag === 76 /* "L" */ || resolvedRowTag === 108 /* "l" */ || resolvedRowTag === 71 /* "G" */ || resolvedRowTag === 103 /* "g" */ || resolvedRowTag === 77 /* "M" */ || resolvedRowTag === 109 /* "m" */ || resolvedRowTag === 86 /* "V" */) {
|
|
3791
|
+
rowTag = resolvedRowTag;
|
|
3792
|
+
rowState = ROW_LENGTH;
|
|
3793
|
+
i++;
|
|
3794
|
+
} else if (resolvedRowTag > 64 && resolvedRowTag < 91 /* "A"-"Z" */ || resolvedRowTag === 35 /* "#" */ || resolvedRowTag === 114 /* "r" */ || resolvedRowTag === 120 /* "x" */) {
|
|
3795
|
+
rowTag = resolvedRowTag;
|
|
3796
|
+
rowState = ROW_CHUNK_BY_NEWLINE;
|
|
3797
|
+
i++;
|
|
3798
|
+
} else {
|
|
3799
|
+
rowTag = 0;
|
|
3800
|
+
rowState = ROW_CHUNK_BY_NEWLINE;
|
|
3801
|
+
// This was an unknown tag so it was probably part of the data.
|
|
3802
|
+
}
|
|
3803
|
+
continue;
|
|
3804
|
+
}
|
|
3805
|
+
case ROW_LENGTH:
|
|
3806
|
+
{
|
|
3807
|
+
var _byte = chunk[i++];
|
|
3808
|
+
if (_byte === 44 /* "," */) {
|
|
3809
|
+
// Finished the rowLength, next we'll buffer up to that length.
|
|
3810
|
+
rowState = ROW_CHUNK_BY_LENGTH;
|
|
3811
|
+
} else {
|
|
3812
|
+
rowLength = rowLength << 4 | (_byte > 96 ? _byte - 87 : _byte - 48);
|
|
3813
|
+
}
|
|
3814
|
+
continue;
|
|
3815
|
+
}
|
|
3816
|
+
case ROW_CHUNK_BY_NEWLINE:
|
|
3817
|
+
{
|
|
3818
|
+
// We're looking for a newline
|
|
3819
|
+
lastIdx = chunk.indexOf(10 /* "\n" */, i);
|
|
3820
|
+
break;
|
|
3821
|
+
}
|
|
3822
|
+
case ROW_CHUNK_BY_LENGTH:
|
|
3823
|
+
{
|
|
3824
|
+
// We're looking for the remaining byte length
|
|
3825
|
+
lastIdx = i + rowLength;
|
|
3826
|
+
if (lastIdx > chunk.length) {
|
|
3827
|
+
lastIdx = -1;
|
|
3828
|
+
}
|
|
3829
|
+
break;
|
|
3830
|
+
}
|
|
3831
|
+
}
|
|
3832
|
+
var offset = chunk.byteOffset + i;
|
|
3833
|
+
if (lastIdx > -1) {
|
|
3834
|
+
// We found the last chunk of the row
|
|
3835
|
+
var length = lastIdx - i;
|
|
3836
|
+
var lastChunk = new Uint8Array(chunk.buffer, offset, length);
|
|
3837
|
+
processFullBinaryRow(response, rowID, rowTag, buffer, lastChunk);
|
|
3838
|
+
// Reset state machine for a new row
|
|
3839
|
+
i = lastIdx;
|
|
3840
|
+
if (rowState === ROW_CHUNK_BY_NEWLINE) {
|
|
3841
|
+
// If we're trailing by a newline we need to skip it.
|
|
3842
|
+
i++;
|
|
3843
|
+
}
|
|
3844
|
+
rowState = ROW_ID;
|
|
3845
|
+
rowTag = 0;
|
|
3846
|
+
rowID = 0;
|
|
3847
|
+
rowLength = 0;
|
|
3848
|
+
buffer.length = 0;
|
|
3849
|
+
} else {
|
|
3850
|
+
// The rest of this row is in a future chunk. We stash the rest of the
|
|
3851
|
+
// current chunk until we can process the full row.
|
|
3852
|
+
var _length = chunk.byteLength - i;
|
|
3853
|
+
var remainingSlice = new Uint8Array(chunk.buffer, offset, _length);
|
|
3854
|
+
buffer.push(remainingSlice);
|
|
3855
|
+
// Update how many bytes we're still waiting for. If we're looking for
|
|
3856
|
+
// a newline, this doesn't hurt since we'll just ignore it.
|
|
3857
|
+
rowLength -= remainingSlice.byteLength;
|
|
3858
|
+
break;
|
|
3859
|
+
}
|
|
3860
|
+
}
|
|
3861
|
+
response._rowState = rowState;
|
|
3862
|
+
response._rowID = rowID;
|
|
3863
|
+
response._rowTag = rowTag;
|
|
3864
|
+
response._rowLength = rowLength;
|
|
3865
|
+
}
|
|
3866
|
+
function parseModel(response, json) {
|
|
3867
|
+
return JSON.parse(json, response._fromJSON);
|
|
3868
|
+
}
|
|
3869
|
+
function createFromJSONCallback(response) {
|
|
3870
|
+
// $FlowFixMe[missing-this-annot]
|
|
3871
|
+
return function (key, value) {
|
|
3872
|
+
if (typeof value === 'string') {
|
|
3873
|
+
// We can't use .bind here because we need the "this" value.
|
|
3874
|
+
return parseModelString(response, this, key, value);
|
|
3875
|
+
}
|
|
3876
|
+
if (typeof value === 'object' && value !== null) {
|
|
3877
|
+
return parseModelTuple(response, value);
|
|
3878
|
+
}
|
|
3879
|
+
return value;
|
|
3880
|
+
};
|
|
3881
|
+
}
|
|
3882
|
+
function close(response) {
|
|
3883
|
+
// In case there are any remaining unresolved chunks, they won't
|
|
3884
|
+
// be resolved now. So we need to issue an error to those.
|
|
3885
|
+
// Ideally we should be able to early bail out if we kept a
|
|
3886
|
+
// ref count of pending chunks.
|
|
3887
|
+
reportGlobalError(response, new Error('Connection closed.'));
|
|
3888
|
+
}
|
|
3889
|
+
function getCurrentOwnerInDEV() {
|
|
3890
|
+
return currentOwnerInDEV;
|
|
3891
|
+
}
|
|
3892
|
+
function injectIntoDevTools() {
|
|
3893
|
+
var internals = {
|
|
3894
|
+
bundleType: 1 ,
|
|
3895
|
+
// Might add PROFILE later.
|
|
3896
|
+
version: ReactVersion,
|
|
3897
|
+
rendererPackageName: rendererPackageName,
|
|
3898
|
+
currentDispatcherRef: ReactSharedInternals,
|
|
3899
|
+
// Enables DevTools to detect reconciler version rather than renderer version
|
|
3900
|
+
// which may not match for third party renderers.
|
|
3901
|
+
reconcilerVersion: ReactVersion,
|
|
3902
|
+
getCurrentComponentInfo: getCurrentOwnerInDEV
|
|
3903
|
+
};
|
|
3904
|
+
return injectInternals(internals);
|
|
3905
|
+
}
|
|
3906
|
+
|
|
3907
|
+
function createResponseFromOptions(options) {
|
|
3908
|
+
return createResponse(options && options.moduleBaseURL ? options.moduleBaseURL : '', null, null, options && options.callServer ? options.callServer : undefined, undefined,
|
|
3909
|
+
// encodeFormAction
|
|
3910
|
+
undefined,
|
|
3911
|
+
// nonce
|
|
3912
|
+
options && options.temporaryReferences ? options.temporaryReferences : undefined, options && options.findSourceMapURL ? options.findSourceMapURL : undefined, options ? options.replayConsoleLogs !== false : true ,
|
|
3913
|
+
// defaults to true
|
|
3914
|
+
options && options.environmentName ? options.environmentName : undefined);
|
|
3915
|
+
}
|
|
3916
|
+
function startReadingFromStream(response, stream) {
|
|
3917
|
+
var reader = stream.getReader();
|
|
3918
|
+
function progress(_ref) {
|
|
3919
|
+
var done = _ref.done,
|
|
3920
|
+
value = _ref.value;
|
|
3921
|
+
if (done) {
|
|
3922
|
+
close(response);
|
|
3923
|
+
return;
|
|
3924
|
+
}
|
|
3925
|
+
var buffer = value;
|
|
3926
|
+
processBinaryChunk(response, buffer);
|
|
3927
|
+
return reader.read().then(progress).catch(error);
|
|
3928
|
+
}
|
|
3929
|
+
function error(e) {
|
|
3930
|
+
reportGlobalError(response, e);
|
|
3931
|
+
}
|
|
3932
|
+
reader.read().then(progress).catch(error);
|
|
3933
|
+
}
|
|
3934
|
+
function createFromReadableStream(stream, options) {
|
|
3935
|
+
var response = createResponseFromOptions(options);
|
|
3936
|
+
startReadingFromStream(response, stream);
|
|
3937
|
+
return getRoot(response);
|
|
3938
|
+
}
|
|
3939
|
+
function createFromFetch(promiseForResponse, options) {
|
|
3940
|
+
var response = createResponseFromOptions(options);
|
|
3941
|
+
promiseForResponse.then(function (r) {
|
|
3942
|
+
startReadingFromStream(response, r.body);
|
|
3943
|
+
}, function (e) {
|
|
3944
|
+
reportGlobalError(response, e);
|
|
3945
|
+
});
|
|
3946
|
+
return getRoot(response);
|
|
3947
|
+
}
|
|
3948
|
+
function encodeReply(value, options) /* We don't use URLSearchParams yet but maybe */{
|
|
3949
|
+
return new Promise(function (resolve, reject) {
|
|
3950
|
+
var abort = processReply(value, '', options && options.temporaryReferences ? options.temporaryReferences : undefined, resolve, reject);
|
|
3951
|
+
if (options && options.signal) {
|
|
3952
|
+
var signal = options.signal;
|
|
3953
|
+
if (signal.aborted) {
|
|
3954
|
+
abort(signal.reason);
|
|
3955
|
+
} else {
|
|
3956
|
+
var listener = function () {
|
|
3957
|
+
abort(signal.reason);
|
|
3958
|
+
signal.removeEventListener('abort', listener);
|
|
3959
|
+
};
|
|
3960
|
+
signal.addEventListener('abort', listener);
|
|
3961
|
+
}
|
|
3962
|
+
}
|
|
3963
|
+
});
|
|
3964
|
+
}
|
|
3965
|
+
{
|
|
3966
|
+
injectIntoDevTools();
|
|
3967
|
+
}
|
|
3968
|
+
|
|
3969
|
+
export { createFromFetch, createFromReadableStream, createServerReference, createTemporaryReferenceSet, encodeReply, registerServerReference };
|