react-server-dom-webpack 18.3.0-next-fa4314841-20230502 → 19.0.0-canary-05797cceb-20240328
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/cjs/react-server-dom-webpack-client.browser.development.js +1768 -1188
- package/cjs/react-server-dom-webpack-client.browser.production.js +1739 -0
- package/cjs/react-server-dom-webpack-client.browser.production.min.js +40 -34
- package/cjs/react-server-dom-webpack-client.browser.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-client.edge.development.js +1755 -221
- package/cjs/react-server-dom-webpack-client.edge.production.js +1986 -0
- package/cjs/react-server-dom-webpack-client.edge.production.min.js +45 -28
- package/cjs/react-server-dom-webpack-client.edge.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-client.node.development.js +1743 -239
- package/cjs/react-server-dom-webpack-client.node.production.js +1942 -0
- package/cjs/react-server-dom-webpack-client.node.production.min.js +44 -28
- package/cjs/react-server-dom-webpack-client.node.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +1702 -194
- package/cjs/react-server-dom-webpack-client.node.unbundled.production.js +1895 -0
- package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +43 -26
- package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-node-register.js +12 -18
- package/cjs/react-server-dom-webpack-node-register.js.map +1 -0
- package/cjs/react-server-dom-webpack-plugin.js +22 -19
- package/cjs/react-server-dom-webpack-plugin.js.map +1 -0
- package/cjs/react-server-dom-webpack-server.browser.development.js +1588 -808
- package/cjs/react-server-dom-webpack-server.browser.production.js +3257 -0
- package/cjs/react-server-dom-webpack-server.browser.production.min.js +80 -62
- package/cjs/react-server-dom-webpack-server.browser.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-server.edge.development.js +1583 -811
- package/cjs/react-server-dom-webpack-server.edge.production.js +3261 -0
- package/cjs/react-server-dom-webpack-server.edge.production.min.js +82 -62
- package/cjs/react-server-dom-webpack-server.edge.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-server.node.development.js +1575 -805
- package/cjs/react-server-dom-webpack-server.node.production.js +3464 -0
- package/cjs/react-server-dom-webpack-server.node.production.min.js +85 -67
- package/cjs/react-server-dom-webpack-server.node.production.min.js.map +1 -0
- package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1526 -761
- package/cjs/react-server-dom-webpack-server.node.unbundled.production.js +3391 -0
- package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +82 -65
- package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js.map +1 -0
- package/esm/react-server-dom-webpack-node-loader.production.min.js +19 -12
- package/package.json +7 -13
- package/umd/react-server-dom-webpack-client.browser.development.js +1770 -1189
- package/umd/react-server-dom-webpack-client.browser.production.min.js +26 -20
- package/umd/react-server-dom-webpack-server.browser.development.js +1589 -808
- package/umd/react-server-dom-webpack-server.browser.production.min.js +55 -42
@@ -18,6 +18,9 @@ var util = require('util');
|
|
18
18
|
var ReactDOM = require('react-dom');
|
19
19
|
var React = require('react');
|
20
20
|
|
21
|
+
// -----------------------------------------------------------------------------
|
22
|
+
var enableBinaryFlight = false;
|
23
|
+
|
21
24
|
function createStringDecoder() {
|
22
25
|
return new util.TextDecoder();
|
23
26
|
}
|
@@ -31,14 +34,76 @@ function readFinalStringChunk(decoder, buffer) {
|
|
31
34
|
return decoder.decode(buffer);
|
32
35
|
}
|
33
36
|
|
34
|
-
|
35
|
-
|
37
|
+
// This flips color using ANSI, then sets a color styling, then resets.
|
38
|
+
var badgeFormat = '\x1b[0m\x1b[7m%c%s\x1b[0m%c '; // Same badge styling as DevTools.
|
39
|
+
|
40
|
+
var badgeStyle = // We use a fixed background if light-dark is not supported, otherwise
|
41
|
+
// we use a transparent background.
|
42
|
+
'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';
|
43
|
+
var resetStyle = '';
|
44
|
+
var pad = ' ';
|
45
|
+
function printToConsole(methodName, args, badgeName) {
|
46
|
+
var offset = 0;
|
47
|
+
|
48
|
+
switch (methodName) {
|
49
|
+
case 'dir':
|
50
|
+
case 'dirxml':
|
51
|
+
case 'groupEnd':
|
52
|
+
case 'table':
|
53
|
+
{
|
54
|
+
// These methods cannot be colorized because they don't take a formatting string.
|
55
|
+
// eslint-disable-next-line react-internal/no-production-logging
|
56
|
+
console[methodName].apply(console, args);
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
|
60
|
+
case 'assert':
|
61
|
+
{
|
62
|
+
// assert takes formatting options as the second argument.
|
63
|
+
offset = 1;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
var newArgs = args.slice(0);
|
68
|
+
|
69
|
+
if (typeof newArgs[offset] === 'string') {
|
70
|
+
newArgs.splice(offset, 1, badgeFormat + newArgs[offset], badgeStyle, pad + badgeName + pad, resetStyle);
|
71
|
+
} else {
|
72
|
+
newArgs.splice(offset, 0, badgeFormat, badgeStyle, pad + badgeName + pad, resetStyle);
|
73
|
+
} // eslint-disable-next-line react-internal/no-production-logging
|
74
|
+
|
75
|
+
|
76
|
+
console[methodName].apply(console, newArgs);
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
|
80
|
+
// This is the parsed shape of the wire format which is why it is
|
81
|
+
// condensed to only the essentialy information
|
82
|
+
var ID = 0;
|
83
|
+
var CHUNKS = 1;
|
84
|
+
var NAME = 2; // export const ASYNC = 3;
|
85
|
+
// This logic is correct because currently only include the 4th tuple member
|
86
|
+
// when the module is async. If that changes we will need to actually assert
|
87
|
+
// the value is true. We don't index into the 4th slot because flow does not
|
88
|
+
// like the potential out of bounds access
|
89
|
+
|
90
|
+
function isAsyncImport(metadata) {
|
91
|
+
return metadata.length === 4;
|
36
92
|
}
|
37
93
|
|
38
|
-
//
|
94
|
+
// The reason this function needs to defined here in this file instead of just
|
95
|
+
// being exported directly from the WebpackDestination... file is because the
|
96
|
+
// ClientReferenceMetadata is opaque and we can't unwrap it there.
|
97
|
+
// This should get inlined and we could also just implement an unwrapping function
|
98
|
+
// though that risks it getting used in places it shouldn't be. This is unfortunate
|
99
|
+
// but currently it seems to be the best option we have.
|
100
|
+
|
101
|
+
function prepareDestinationForModule(moduleLoading, nonce, metadata) {
|
102
|
+
prepareDestinationWithChunks(moduleLoading, metadata[CHUNKS], nonce);
|
103
|
+
}
|
39
104
|
function resolveClientReference(bundlerConfig, metadata) {
|
40
|
-
var moduleExports = bundlerConfig[metadata
|
41
|
-
var resolvedModuleData = moduleExports[metadata
|
105
|
+
var moduleExports = bundlerConfig[metadata[ID]];
|
106
|
+
var resolvedModuleData = moduleExports[metadata[NAME]];
|
42
107
|
var name;
|
43
108
|
|
44
109
|
if (resolvedModuleData) {
|
@@ -49,15 +114,16 @@ function resolveClientReference(bundlerConfig, metadata) {
|
|
49
114
|
resolvedModuleData = moduleExports['*'];
|
50
115
|
|
51
116
|
if (!resolvedModuleData) {
|
52
|
-
throw new Error('Could not find the module "' + metadata
|
117
|
+
throw new Error('Could not find the module "' + metadata[ID] + '" in the React SSR Manifest. ' + 'This is probably a bug in the React Server Components bundler.');
|
53
118
|
}
|
54
119
|
|
55
|
-
name = metadata
|
120
|
+
name = metadata[NAME];
|
56
121
|
}
|
57
122
|
|
58
123
|
return {
|
59
124
|
specifier: resolvedModuleData.specifier,
|
60
|
-
name: name
|
125
|
+
name: name,
|
126
|
+
async: isAsyncImport(metadata)
|
61
127
|
};
|
62
128
|
}
|
63
129
|
var asyncModuleCache = new Map();
|
@@ -73,6 +139,17 @@ function preloadModule(metadata) {
|
|
73
139
|
} else {
|
74
140
|
// $FlowFixMe[unsupported-syntax]
|
75
141
|
var modulePromise = import(metadata.specifier);
|
142
|
+
|
143
|
+
if (metadata.async) {
|
144
|
+
// If the module is async, it must have been a CJS module.
|
145
|
+
// CJS modules are accessed through the default export in
|
146
|
+
// Node.js so we have to get the default export to get the
|
147
|
+
// full module exports.
|
148
|
+
modulePromise = modulePromise.then(function (value) {
|
149
|
+
return value.default;
|
150
|
+
});
|
151
|
+
}
|
152
|
+
|
76
153
|
modulePromise.then(function (value) {
|
77
154
|
var fulfilledThenable = modulePromise;
|
78
155
|
fulfilledThenable.status = 'fulfilled';
|
@@ -104,90 +181,1237 @@ function requireModule(metadata) {
|
|
104
181
|
return moduleExports;
|
105
182
|
}
|
106
183
|
|
107
|
-
if (metadata.name === '') {
|
108
|
-
// This is a placeholder value that represents that the caller accessed the
|
109
|
-
// default property of this if it was an ESM interop module.
|
110
|
-
return moduleExports.default;
|
184
|
+
if (metadata.name === '') {
|
185
|
+
// This is a placeholder value that represents that the caller accessed the
|
186
|
+
// default property of this if it was an ESM interop module.
|
187
|
+
return moduleExports.default;
|
188
|
+
}
|
189
|
+
|
190
|
+
return moduleExports[metadata.name];
|
191
|
+
}
|
192
|
+
|
193
|
+
function prepareDestinationWithChunks(moduleLoading, // Chunks are double-indexed [..., idx, filenamex, idy, filenamey, ...]
|
194
|
+
chunks, nonce) {
|
195
|
+
if (moduleLoading !== null) {
|
196
|
+
for (var i = 1; i < chunks.length; i += 2) {
|
197
|
+
preinitScriptForSSR(moduleLoading.prefix + chunks[i], nonce, moduleLoading.crossOrigin);
|
198
|
+
}
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
var ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
203
|
+
|
204
|
+
function getCrossOriginString(input) {
|
205
|
+
if (typeof input === 'string') {
|
206
|
+
return input === 'use-credentials' ? input : '';
|
207
|
+
}
|
208
|
+
|
209
|
+
return undefined;
|
210
|
+
}
|
211
|
+
|
212
|
+
// This client file is in the shared folder because it applies to both SSR and browser contexts.
|
213
|
+
var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
|
214
|
+
function dispatchHint(code, model) {
|
215
|
+
var dispatcher = ReactDOMCurrentDispatcher.current;
|
216
|
+
|
217
|
+
switch (code) {
|
218
|
+
case 'D':
|
219
|
+
{
|
220
|
+
var refined = refineModel(code, model);
|
221
|
+
var href = refined;
|
222
|
+
dispatcher.prefetchDNS(href);
|
223
|
+
return;
|
224
|
+
}
|
225
|
+
|
226
|
+
case 'C':
|
227
|
+
{
|
228
|
+
var _refined = refineModel(code, model);
|
229
|
+
|
230
|
+
if (typeof _refined === 'string') {
|
231
|
+
var _href = _refined;
|
232
|
+
dispatcher.preconnect(_href);
|
233
|
+
} else {
|
234
|
+
var _href2 = _refined[0];
|
235
|
+
var crossOrigin = _refined[1];
|
236
|
+
dispatcher.preconnect(_href2, crossOrigin);
|
237
|
+
}
|
238
|
+
|
239
|
+
return;
|
240
|
+
}
|
241
|
+
|
242
|
+
case 'L':
|
243
|
+
{
|
244
|
+
var _refined2 = refineModel(code, model);
|
245
|
+
|
246
|
+
var _href3 = _refined2[0];
|
247
|
+
var as = _refined2[1];
|
248
|
+
|
249
|
+
if (_refined2.length === 3) {
|
250
|
+
var options = _refined2[2];
|
251
|
+
dispatcher.preload(_href3, as, options);
|
252
|
+
} else {
|
253
|
+
dispatcher.preload(_href3, as);
|
254
|
+
}
|
255
|
+
|
256
|
+
return;
|
257
|
+
}
|
258
|
+
|
259
|
+
case 'm':
|
260
|
+
{
|
261
|
+
var _refined3 = refineModel(code, model);
|
262
|
+
|
263
|
+
if (typeof _refined3 === 'string') {
|
264
|
+
var _href4 = _refined3;
|
265
|
+
dispatcher.preloadModule(_href4);
|
266
|
+
} else {
|
267
|
+
var _href5 = _refined3[0];
|
268
|
+
var _options = _refined3[1];
|
269
|
+
dispatcher.preloadModule(_href5, _options);
|
270
|
+
}
|
271
|
+
|
272
|
+
return;
|
273
|
+
}
|
274
|
+
|
275
|
+
case 'S':
|
276
|
+
{
|
277
|
+
var _refined4 = refineModel(code, model);
|
278
|
+
|
279
|
+
if (typeof _refined4 === 'string') {
|
280
|
+
var _href6 = _refined4;
|
281
|
+
dispatcher.preinitStyle(_href6);
|
282
|
+
} else {
|
283
|
+
var _href7 = _refined4[0];
|
284
|
+
var precedence = _refined4[1] === 0 ? undefined : _refined4[1];
|
285
|
+
|
286
|
+
var _options2 = _refined4.length === 3 ? _refined4[2] : undefined;
|
287
|
+
|
288
|
+
dispatcher.preinitStyle(_href7, precedence, _options2);
|
289
|
+
}
|
290
|
+
|
291
|
+
return;
|
292
|
+
}
|
293
|
+
|
294
|
+
case 'X':
|
295
|
+
{
|
296
|
+
var _refined5 = refineModel(code, model);
|
297
|
+
|
298
|
+
if (typeof _refined5 === 'string') {
|
299
|
+
var _href8 = _refined5;
|
300
|
+
dispatcher.preinitScript(_href8);
|
301
|
+
} else {
|
302
|
+
var _href9 = _refined5[0];
|
303
|
+
var _options3 = _refined5[1];
|
304
|
+
dispatcher.preinitScript(_href9, _options3);
|
305
|
+
}
|
306
|
+
|
307
|
+
return;
|
308
|
+
}
|
309
|
+
|
310
|
+
case 'M':
|
311
|
+
{
|
312
|
+
var _refined6 = refineModel(code, model);
|
313
|
+
|
314
|
+
if (typeof _refined6 === 'string') {
|
315
|
+
var _href10 = _refined6;
|
316
|
+
dispatcher.preinitModuleScript(_href10);
|
317
|
+
} else {
|
318
|
+
var _href11 = _refined6[0];
|
319
|
+
var _options4 = _refined6[1];
|
320
|
+
dispatcher.preinitModuleScript(_href11, _options4);
|
321
|
+
}
|
322
|
+
|
323
|
+
return;
|
324
|
+
}
|
325
|
+
}
|
326
|
+
} // Flow is having trouble refining the HintModels so we help it a bit.
|
327
|
+
// This should be compiled out in the production build.
|
328
|
+
|
329
|
+
function refineModel(code, model) {
|
330
|
+
return model;
|
331
|
+
}
|
332
|
+
function preinitScriptForSSR(href, nonce, crossOrigin) {
|
333
|
+
var dispatcher = ReactDOMCurrentDispatcher.current;
|
334
|
+
|
335
|
+
if (dispatcher) {
|
336
|
+
dispatcher.preinitScript(href, {
|
337
|
+
crossOrigin: getCrossOriginString(crossOrigin),
|
338
|
+
nonce: nonce
|
339
|
+
});
|
340
|
+
}
|
341
|
+
}
|
342
|
+
|
343
|
+
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
344
|
+
|
345
|
+
function error(format) {
|
346
|
+
{
|
347
|
+
{
|
348
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
349
|
+
args[_key2 - 1] = arguments[_key2];
|
350
|
+
}
|
351
|
+
|
352
|
+
printWarning('error', format, args);
|
353
|
+
}
|
354
|
+
}
|
355
|
+
}
|
356
|
+
|
357
|
+
function printWarning(level, format, args) {
|
358
|
+
// When changing this logic, you might want to also
|
359
|
+
// update consoleWithStackDev.www.js as well.
|
360
|
+
{
|
361
|
+
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
362
|
+
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
363
|
+
|
364
|
+
if (stack !== '') {
|
365
|
+
format += '%s';
|
366
|
+
args = args.concat([stack]);
|
367
|
+
} // eslint-disable-next-line react-internal/safe-string-coercion
|
368
|
+
|
369
|
+
|
370
|
+
var argsWithFormat = args.map(function (item) {
|
371
|
+
return String(item);
|
372
|
+
}); // Careful: RN currently depends on this prefix
|
373
|
+
|
374
|
+
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
375
|
+
// breaks IE9: https://github.com/facebook/react/issues/13610
|
376
|
+
// eslint-disable-next-line react-internal/no-production-logging
|
377
|
+
|
378
|
+
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
379
|
+
}
|
380
|
+
}
|
381
|
+
|
382
|
+
// ATTENTION
|
383
|
+
// When adding new symbols to this file,
|
384
|
+
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
|
385
|
+
// The Symbol used to tag the ReactElement-like types.
|
386
|
+
var REACT_ELEMENT_TYPE = Symbol.for('react.element');
|
387
|
+
var REACT_PROVIDER_TYPE = Symbol.for('react.provider'); // TODO: Delete with enableRenderableContext
|
388
|
+
var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
|
389
|
+
var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
|
390
|
+
var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
|
391
|
+
var REACT_MEMO_TYPE = Symbol.for('react.memo');
|
392
|
+
var REACT_LAZY_TYPE = Symbol.for('react.lazy');
|
393
|
+
var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
|
394
|
+
var FAUX_ITERATOR_SYMBOL = '@@iterator';
|
395
|
+
function getIteratorFn(maybeIterable) {
|
396
|
+
if (maybeIterable === null || typeof maybeIterable !== 'object') {
|
397
|
+
return null;
|
398
|
+
}
|
399
|
+
|
400
|
+
var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
|
401
|
+
|
402
|
+
if (typeof maybeIterator === 'function') {
|
403
|
+
return maybeIterator;
|
404
|
+
}
|
405
|
+
|
406
|
+
return null;
|
407
|
+
}
|
408
|
+
|
409
|
+
var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
|
410
|
+
|
411
|
+
function isArray(a) {
|
412
|
+
return isArrayImpl(a);
|
413
|
+
}
|
414
|
+
|
415
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
416
|
+
|
417
|
+
// in case they error.
|
418
|
+
|
419
|
+
var jsxPropsParents = new WeakMap();
|
420
|
+
var jsxChildrenParents = new WeakMap();
|
421
|
+
|
422
|
+
function isObjectPrototype(object) {
|
423
|
+
if (!object) {
|
424
|
+
return false;
|
425
|
+
}
|
426
|
+
|
427
|
+
var ObjectPrototype = Object.prototype;
|
428
|
+
|
429
|
+
if (object === ObjectPrototype) {
|
430
|
+
return true;
|
431
|
+
} // It might be an object from a different Realm which is
|
432
|
+
// still just a plain simple object.
|
433
|
+
|
434
|
+
|
435
|
+
if (getPrototypeOf(object)) {
|
436
|
+
return false;
|
437
|
+
}
|
438
|
+
|
439
|
+
var names = Object.getOwnPropertyNames(object);
|
440
|
+
|
441
|
+
for (var i = 0; i < names.length; i++) {
|
442
|
+
if (!(names[i] in ObjectPrototype)) {
|
443
|
+
return false;
|
444
|
+
}
|
445
|
+
}
|
446
|
+
|
447
|
+
return true;
|
448
|
+
}
|
449
|
+
|
450
|
+
function isSimpleObject(object) {
|
451
|
+
if (!isObjectPrototype(getPrototypeOf(object))) {
|
452
|
+
return false;
|
453
|
+
}
|
454
|
+
|
455
|
+
var names = Object.getOwnPropertyNames(object);
|
456
|
+
|
457
|
+
for (var i = 0; i < names.length; i++) {
|
458
|
+
var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
|
459
|
+
|
460
|
+
if (!descriptor) {
|
461
|
+
return false;
|
462
|
+
}
|
463
|
+
|
464
|
+
if (!descriptor.enumerable) {
|
465
|
+
if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
|
466
|
+
// React adds key and ref getters to props objects to issue warnings.
|
467
|
+
// Those getters will not be transferred to the client, but that's ok,
|
468
|
+
// so we'll special case them.
|
469
|
+
continue;
|
470
|
+
}
|
471
|
+
|
472
|
+
return false;
|
473
|
+
}
|
474
|
+
}
|
475
|
+
|
476
|
+
return true;
|
477
|
+
}
|
478
|
+
function objectName(object) {
|
479
|
+
// $FlowFixMe[method-unbinding]
|
480
|
+
var name = Object.prototype.toString.call(object);
|
481
|
+
return name.replace(/^\[object (.*)\]$/, function (m, p0) {
|
482
|
+
return p0;
|
483
|
+
});
|
484
|
+
}
|
485
|
+
|
486
|
+
function describeKeyForErrorMessage(key) {
|
487
|
+
var encodedKey = JSON.stringify(key);
|
488
|
+
return '"' + key + '"' === encodedKey ? key : encodedKey;
|
489
|
+
}
|
490
|
+
|
491
|
+
function describeValueForErrorMessage(value) {
|
492
|
+
switch (typeof value) {
|
493
|
+
case 'string':
|
494
|
+
{
|
495
|
+
return JSON.stringify(value.length <= 10 ? value : value.slice(0, 10) + '...');
|
496
|
+
}
|
497
|
+
|
498
|
+
case 'object':
|
499
|
+
{
|
500
|
+
if (isArray(value)) {
|
501
|
+
return '[...]';
|
502
|
+
}
|
503
|
+
|
504
|
+
if (value !== null && value.$$typeof === CLIENT_REFERENCE_TAG) {
|
505
|
+
return describeClientReference();
|
506
|
+
}
|
507
|
+
|
508
|
+
var name = objectName(value);
|
509
|
+
|
510
|
+
if (name === 'Object') {
|
511
|
+
return '{...}';
|
512
|
+
}
|
513
|
+
|
514
|
+
return name;
|
515
|
+
}
|
516
|
+
|
517
|
+
case 'function':
|
518
|
+
{
|
519
|
+
if (value.$$typeof === CLIENT_REFERENCE_TAG) {
|
520
|
+
return describeClientReference();
|
521
|
+
}
|
522
|
+
|
523
|
+
var _name = value.displayName || value.name;
|
524
|
+
|
525
|
+
return _name ? 'function ' + _name : 'function';
|
526
|
+
}
|
527
|
+
|
528
|
+
default:
|
529
|
+
// eslint-disable-next-line react-internal/safe-string-coercion
|
530
|
+
return String(value);
|
531
|
+
}
|
532
|
+
}
|
533
|
+
|
534
|
+
function describeElementType(type) {
|
535
|
+
if (typeof type === 'string') {
|
536
|
+
return type;
|
537
|
+
}
|
538
|
+
|
539
|
+
switch (type) {
|
540
|
+
case REACT_SUSPENSE_TYPE:
|
541
|
+
return 'Suspense';
|
542
|
+
|
543
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
544
|
+
return 'SuspenseList';
|
545
|
+
}
|
546
|
+
|
547
|
+
if (typeof type === 'object') {
|
548
|
+
switch (type.$$typeof) {
|
549
|
+
case REACT_FORWARD_REF_TYPE:
|
550
|
+
return describeElementType(type.render);
|
551
|
+
|
552
|
+
case REACT_MEMO_TYPE:
|
553
|
+
return describeElementType(type.type);
|
554
|
+
|
555
|
+
case REACT_LAZY_TYPE:
|
556
|
+
{
|
557
|
+
var lazyComponent = type;
|
558
|
+
var payload = lazyComponent._payload;
|
559
|
+
var init = lazyComponent._init;
|
560
|
+
|
561
|
+
try {
|
562
|
+
// Lazy may contain any component type so we recursively resolve it.
|
563
|
+
return describeElementType(init(payload));
|
564
|
+
} catch (x) {}
|
565
|
+
}
|
566
|
+
}
|
567
|
+
}
|
568
|
+
|
569
|
+
return '';
|
570
|
+
}
|
571
|
+
|
572
|
+
var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
|
573
|
+
|
574
|
+
function describeClientReference(ref) {
|
575
|
+
return 'client';
|
576
|
+
}
|
577
|
+
|
578
|
+
function describeObjectForErrorMessage(objectOrArray, expandedName) {
|
579
|
+
var objKind = objectName(objectOrArray);
|
580
|
+
|
581
|
+
if (objKind !== 'Object' && objKind !== 'Array') {
|
582
|
+
return objKind;
|
583
|
+
}
|
584
|
+
|
585
|
+
var str = '';
|
586
|
+
var start = -1;
|
587
|
+
var length = 0;
|
588
|
+
|
589
|
+
if (isArray(objectOrArray)) {
|
590
|
+
if (jsxChildrenParents.has(objectOrArray)) {
|
591
|
+
// Print JSX Children
|
592
|
+
var type = jsxChildrenParents.get(objectOrArray);
|
593
|
+
str = '<' + describeElementType(type) + '>';
|
594
|
+
var array = objectOrArray;
|
595
|
+
|
596
|
+
for (var i = 0; i < array.length; i++) {
|
597
|
+
var value = array[i];
|
598
|
+
var substr = void 0;
|
599
|
+
|
600
|
+
if (typeof value === 'string') {
|
601
|
+
substr = value;
|
602
|
+
} else if (typeof value === 'object' && value !== null) {
|
603
|
+
substr = '{' + describeObjectForErrorMessage(value) + '}';
|
604
|
+
} else {
|
605
|
+
substr = '{' + describeValueForErrorMessage(value) + '}';
|
606
|
+
}
|
607
|
+
|
608
|
+
if ('' + i === expandedName) {
|
609
|
+
start = str.length;
|
610
|
+
length = substr.length;
|
611
|
+
str += substr;
|
612
|
+
} else if (substr.length < 15 && str.length + substr.length < 40) {
|
613
|
+
str += substr;
|
614
|
+
} else {
|
615
|
+
str += '{...}';
|
616
|
+
}
|
617
|
+
}
|
618
|
+
|
619
|
+
str += '</' + describeElementType(type) + '>';
|
620
|
+
} else {
|
621
|
+
// Print Array
|
622
|
+
str = '[';
|
623
|
+
var _array = objectOrArray;
|
624
|
+
|
625
|
+
for (var _i = 0; _i < _array.length; _i++) {
|
626
|
+
if (_i > 0) {
|
627
|
+
str += ', ';
|
628
|
+
}
|
629
|
+
|
630
|
+
var _value = _array[_i];
|
631
|
+
|
632
|
+
var _substr = void 0;
|
633
|
+
|
634
|
+
if (typeof _value === 'object' && _value !== null) {
|
635
|
+
_substr = describeObjectForErrorMessage(_value);
|
636
|
+
} else {
|
637
|
+
_substr = describeValueForErrorMessage(_value);
|
638
|
+
}
|
639
|
+
|
640
|
+
if ('' + _i === expandedName) {
|
641
|
+
start = str.length;
|
642
|
+
length = _substr.length;
|
643
|
+
str += _substr;
|
644
|
+
} else if (_substr.length < 10 && str.length + _substr.length < 40) {
|
645
|
+
str += _substr;
|
646
|
+
} else {
|
647
|
+
str += '...';
|
648
|
+
}
|
649
|
+
}
|
650
|
+
|
651
|
+
str += ']';
|
652
|
+
}
|
653
|
+
} else {
|
654
|
+
if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
|
655
|
+
str = '<' + describeElementType(objectOrArray.type) + '/>';
|
656
|
+
} else if (objectOrArray.$$typeof === CLIENT_REFERENCE_TAG) {
|
657
|
+
return describeClientReference();
|
658
|
+
} else if (jsxPropsParents.has(objectOrArray)) {
|
659
|
+
// Print JSX
|
660
|
+
var _type = jsxPropsParents.get(objectOrArray);
|
661
|
+
|
662
|
+
str = '<' + (describeElementType(_type) || '...');
|
663
|
+
var object = objectOrArray;
|
664
|
+
var names = Object.keys(object);
|
665
|
+
|
666
|
+
for (var _i2 = 0; _i2 < names.length; _i2++) {
|
667
|
+
str += ' ';
|
668
|
+
var name = names[_i2];
|
669
|
+
str += describeKeyForErrorMessage(name) + '=';
|
670
|
+
var _value2 = object[name];
|
671
|
+
|
672
|
+
var _substr2 = void 0;
|
673
|
+
|
674
|
+
if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
|
675
|
+
_substr2 = describeObjectForErrorMessage(_value2);
|
676
|
+
} else {
|
677
|
+
_substr2 = describeValueForErrorMessage(_value2);
|
678
|
+
}
|
679
|
+
|
680
|
+
if (typeof _value2 !== 'string') {
|
681
|
+
_substr2 = '{' + _substr2 + '}';
|
682
|
+
}
|
683
|
+
|
684
|
+
if (name === expandedName) {
|
685
|
+
start = str.length;
|
686
|
+
length = _substr2.length;
|
687
|
+
str += _substr2;
|
688
|
+
} else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
|
689
|
+
str += _substr2;
|
690
|
+
} else {
|
691
|
+
str += '...';
|
692
|
+
}
|
693
|
+
}
|
694
|
+
|
695
|
+
str += '>';
|
696
|
+
} else {
|
697
|
+
// Print Object
|
698
|
+
str = '{';
|
699
|
+
var _object = objectOrArray;
|
700
|
+
|
701
|
+
var _names = Object.keys(_object);
|
702
|
+
|
703
|
+
for (var _i3 = 0; _i3 < _names.length; _i3++) {
|
704
|
+
if (_i3 > 0) {
|
705
|
+
str += ', ';
|
706
|
+
}
|
707
|
+
|
708
|
+
var _name2 = _names[_i3];
|
709
|
+
str += describeKeyForErrorMessage(_name2) + ': ';
|
710
|
+
var _value3 = _object[_name2];
|
711
|
+
|
712
|
+
var _substr3 = void 0;
|
713
|
+
|
714
|
+
if (typeof _value3 === 'object' && _value3 !== null) {
|
715
|
+
_substr3 = describeObjectForErrorMessage(_value3);
|
716
|
+
} else {
|
717
|
+
_substr3 = describeValueForErrorMessage(_value3);
|
718
|
+
}
|
719
|
+
|
720
|
+
if (_name2 === expandedName) {
|
721
|
+
start = str.length;
|
722
|
+
length = _substr3.length;
|
723
|
+
str += _substr3;
|
724
|
+
} else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
|
725
|
+
str += _substr3;
|
726
|
+
} else {
|
727
|
+
str += '...';
|
728
|
+
}
|
729
|
+
}
|
730
|
+
|
731
|
+
str += '}';
|
732
|
+
}
|
733
|
+
}
|
734
|
+
|
735
|
+
if (expandedName === undefined) {
|
736
|
+
return str;
|
737
|
+
}
|
738
|
+
|
739
|
+
if (start > -1 && length > 0) {
|
740
|
+
var highlight = ' '.repeat(start) + '^'.repeat(length);
|
741
|
+
return '\n ' + str + '\n ' + highlight;
|
742
|
+
}
|
743
|
+
|
744
|
+
return '\n ' + str;
|
745
|
+
}
|
746
|
+
|
747
|
+
function writeTemporaryReference(set, object) {
|
748
|
+
// We always create a new entry regardless if we've already written the same
|
749
|
+
// object. This ensures that we always generate a deterministic encoding of
|
750
|
+
// each slot in the reply for cacheability.
|
751
|
+
var newId = set.length;
|
752
|
+
set.push(object);
|
753
|
+
return newId;
|
754
|
+
}
|
755
|
+
function readTemporaryReference(set, id) {
|
756
|
+
if (id < 0 || id >= set.length) {
|
757
|
+
throw new Error("The RSC response contained a reference that doesn't exist in the temporary reference set. " + 'Always pass the matching set that was used to create the reply when parsing its response.');
|
758
|
+
}
|
759
|
+
|
760
|
+
return set[id];
|
761
|
+
}
|
762
|
+
|
763
|
+
var ObjectPrototype = Object.prototype;
|
764
|
+
var knownServerReferences = new WeakMap(); // Serializable values
|
765
|
+
// Thenable<ReactServerValue>
|
766
|
+
|
767
|
+
function serializeByValueID(id) {
|
768
|
+
return '$' + id.toString(16);
|
769
|
+
}
|
770
|
+
|
771
|
+
function serializePromiseID(id) {
|
772
|
+
return '$@' + id.toString(16);
|
773
|
+
}
|
774
|
+
|
775
|
+
function serializeServerReferenceID(id) {
|
776
|
+
return '$F' + id.toString(16);
|
777
|
+
}
|
778
|
+
|
779
|
+
function serializeTemporaryReferenceID(id) {
|
780
|
+
return '$T' + id.toString(16);
|
781
|
+
}
|
782
|
+
|
783
|
+
function serializeFormDataReference(id) {
|
784
|
+
// Why K? F is "Function". D is "Date". What else?
|
785
|
+
return '$K' + id.toString(16);
|
786
|
+
}
|
787
|
+
|
788
|
+
function serializeNumber(number) {
|
789
|
+
if (Number.isFinite(number)) {
|
790
|
+
if (number === 0 && 1 / number === -Infinity) {
|
791
|
+
return '$-0';
|
792
|
+
} else {
|
793
|
+
return number;
|
794
|
+
}
|
795
|
+
} else {
|
796
|
+
if (number === Infinity) {
|
797
|
+
return '$Infinity';
|
798
|
+
} else if (number === -Infinity) {
|
799
|
+
return '$-Infinity';
|
800
|
+
} else {
|
801
|
+
return '$NaN';
|
802
|
+
}
|
803
|
+
}
|
804
|
+
}
|
805
|
+
|
806
|
+
function serializeUndefined() {
|
807
|
+
return '$undefined';
|
808
|
+
}
|
809
|
+
|
810
|
+
function serializeDateFromDateJSON(dateJSON) {
|
811
|
+
// JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
|
812
|
+
// We need only tack on a $D prefix.
|
813
|
+
return '$D' + dateJSON;
|
814
|
+
}
|
815
|
+
|
816
|
+
function serializeBigInt(n) {
|
817
|
+
return '$n' + n.toString(10);
|
818
|
+
}
|
819
|
+
|
820
|
+
function serializeMapID(id) {
|
821
|
+
return '$Q' + id.toString(16);
|
822
|
+
}
|
823
|
+
|
824
|
+
function serializeSetID(id) {
|
825
|
+
return '$W' + id.toString(16);
|
826
|
+
}
|
827
|
+
|
828
|
+
function escapeStringValue(value) {
|
829
|
+
if (value[0] === '$') {
|
830
|
+
// We need to escape $ prefixed strings since we use those to encode
|
831
|
+
// references to IDs and as special symbol values.
|
832
|
+
return '$' + value;
|
833
|
+
} else {
|
834
|
+
return value;
|
835
|
+
}
|
836
|
+
}
|
837
|
+
|
838
|
+
function processReply(root, formFieldPrefix, temporaryReferences, resolve, reject) {
|
839
|
+
var nextPartId = 1;
|
840
|
+
var pendingParts = 0;
|
841
|
+
var formData = null;
|
842
|
+
|
843
|
+
function resolveToJSON(key, value) {
|
844
|
+
var parent = this; // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
|
845
|
+
|
846
|
+
{
|
847
|
+
// $FlowFixMe[incompatible-use]
|
848
|
+
var originalValue = parent[key];
|
849
|
+
|
850
|
+
if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
|
851
|
+
if (objectName(originalValue) !== 'Object') {
|
852
|
+
error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
|
853
|
+
} else {
|
854
|
+
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));
|
855
|
+
}
|
856
|
+
}
|
857
|
+
}
|
858
|
+
|
859
|
+
if (value === null) {
|
860
|
+
return null;
|
861
|
+
}
|
862
|
+
|
863
|
+
if (typeof value === 'object') {
|
864
|
+
switch (value.$$typeof) {
|
865
|
+
case REACT_ELEMENT_TYPE:
|
866
|
+
{
|
867
|
+
if (temporaryReferences === undefined) {
|
868
|
+
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) ));
|
869
|
+
}
|
870
|
+
|
871
|
+
return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
|
872
|
+
}
|
873
|
+
|
874
|
+
case REACT_LAZY_TYPE:
|
875
|
+
{
|
876
|
+
// Resolve lazy as if it wasn't here. In the future this will be encoded as a Promise.
|
877
|
+
var lazy = value;
|
878
|
+
var payload = lazy._payload;
|
879
|
+
var init = lazy._init;
|
880
|
+
|
881
|
+
if (formData === null) {
|
882
|
+
// Upgrade to use FormData to allow us to stream this value.
|
883
|
+
formData = new FormData();
|
884
|
+
}
|
885
|
+
|
886
|
+
pendingParts++;
|
887
|
+
|
888
|
+
try {
|
889
|
+
var resolvedModel = init(payload); // We always outline this as a separate part even though we could inline it
|
890
|
+
// because it ensures a more deterministic encoding.
|
891
|
+
|
892
|
+
var lazyId = nextPartId++;
|
893
|
+
var partJSON = JSON.stringify(resolvedModel, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
894
|
+
|
895
|
+
var data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
|
896
|
+
|
897
|
+
data.append(formFieldPrefix + lazyId, partJSON);
|
898
|
+
return serializeByValueID(lazyId);
|
899
|
+
} catch (x) {
|
900
|
+
if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
|
901
|
+
// Suspended
|
902
|
+
pendingParts++;
|
903
|
+
|
904
|
+
var _lazyId = nextPartId++;
|
905
|
+
|
906
|
+
var thenable = x;
|
907
|
+
|
908
|
+
var retry = function () {
|
909
|
+
// While the first promise resolved, its value isn't necessarily what we'll
|
910
|
+
// resolve into because we might suspend again.
|
911
|
+
try {
|
912
|
+
var _partJSON = JSON.stringify(value, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
913
|
+
|
914
|
+
|
915
|
+
var _data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
|
916
|
+
|
917
|
+
_data.append(formFieldPrefix + _lazyId, _partJSON);
|
918
|
+
|
919
|
+
pendingParts--;
|
920
|
+
|
921
|
+
if (pendingParts === 0) {
|
922
|
+
resolve(_data);
|
923
|
+
}
|
924
|
+
} catch (reason) {
|
925
|
+
reject(reason);
|
926
|
+
}
|
927
|
+
};
|
928
|
+
|
929
|
+
thenable.then(retry, retry);
|
930
|
+
return serializeByValueID(_lazyId);
|
931
|
+
} else {
|
932
|
+
// In the future we could consider serializing this as an error
|
933
|
+
// that throws on the server instead.
|
934
|
+
reject(x);
|
935
|
+
return null;
|
936
|
+
}
|
937
|
+
} finally {
|
938
|
+
pendingParts--;
|
939
|
+
}
|
940
|
+
}
|
941
|
+
} // $FlowFixMe[method-unbinding]
|
942
|
+
|
943
|
+
|
944
|
+
if (typeof value.then === 'function') {
|
945
|
+
// We assume that any object with a .then property is a "Thenable" type,
|
946
|
+
// or a Promise type. Either of which can be represented by a Promise.
|
947
|
+
if (formData === null) {
|
948
|
+
// Upgrade to use FormData to allow us to stream this value.
|
949
|
+
formData = new FormData();
|
950
|
+
}
|
951
|
+
|
952
|
+
pendingParts++;
|
953
|
+
var promiseId = nextPartId++;
|
954
|
+
var _thenable = value;
|
955
|
+
|
956
|
+
_thenable.then(function (partValue) {
|
957
|
+
try {
|
958
|
+
var _partJSON2 = JSON.stringify(partValue, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
959
|
+
|
960
|
+
|
961
|
+
var _data2 = formData; // eslint-disable-next-line react-internal/safe-string-coercion
|
962
|
+
|
963
|
+
_data2.append(formFieldPrefix + promiseId, _partJSON2);
|
964
|
+
|
965
|
+
pendingParts--;
|
966
|
+
|
967
|
+
if (pendingParts === 0) {
|
968
|
+
resolve(_data2);
|
969
|
+
}
|
970
|
+
} catch (reason) {
|
971
|
+
reject(reason);
|
972
|
+
}
|
973
|
+
}, function (reason) {
|
974
|
+
// In the future we could consider serializing this as an error
|
975
|
+
// that throws on the server instead.
|
976
|
+
reject(reason);
|
977
|
+
});
|
978
|
+
|
979
|
+
return serializePromiseID(promiseId);
|
980
|
+
}
|
981
|
+
|
982
|
+
if (isArray(value)) {
|
983
|
+
// $FlowFixMe[incompatible-return]
|
984
|
+
return value;
|
985
|
+
} // TODO: Should we the Object.prototype.toString.call() to test for cross-realm objects?
|
986
|
+
|
987
|
+
|
988
|
+
if (value instanceof FormData) {
|
989
|
+
if (formData === null) {
|
990
|
+
// Upgrade to use FormData to allow us to use rich objects as its values.
|
991
|
+
formData = new FormData();
|
992
|
+
}
|
993
|
+
|
994
|
+
var _data3 = formData;
|
995
|
+
var refId = nextPartId++; // Copy all the form fields with a prefix for this reference.
|
996
|
+
// These must come first in the form order because we assume that all the
|
997
|
+
// fields are available before this is referenced.
|
998
|
+
|
999
|
+
var prefix = formFieldPrefix + refId + '_'; // $FlowFixMe[prop-missing]: FormData has forEach.
|
1000
|
+
|
1001
|
+
value.forEach(function (originalValue, originalKey) {
|
1002
|
+
_data3.append(prefix + originalKey, originalValue);
|
1003
|
+
});
|
1004
|
+
return serializeFormDataReference(refId);
|
1005
|
+
}
|
1006
|
+
|
1007
|
+
if (value instanceof Map) {
|
1008
|
+
var _partJSON3 = JSON.stringify(Array.from(value), resolveToJSON);
|
1009
|
+
|
1010
|
+
if (formData === null) {
|
1011
|
+
formData = new FormData();
|
1012
|
+
}
|
1013
|
+
|
1014
|
+
var mapId = nextPartId++;
|
1015
|
+
formData.append(formFieldPrefix + mapId, _partJSON3);
|
1016
|
+
return serializeMapID(mapId);
|
1017
|
+
}
|
1018
|
+
|
1019
|
+
if (value instanceof Set) {
|
1020
|
+
var _partJSON4 = JSON.stringify(Array.from(value), resolveToJSON);
|
1021
|
+
|
1022
|
+
if (formData === null) {
|
1023
|
+
formData = new FormData();
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
var setId = nextPartId++;
|
1027
|
+
formData.append(formFieldPrefix + setId, _partJSON4);
|
1028
|
+
return serializeSetID(setId);
|
1029
|
+
}
|
1030
|
+
|
1031
|
+
var iteratorFn = getIteratorFn(value);
|
1032
|
+
|
1033
|
+
if (iteratorFn) {
|
1034
|
+
return Array.from(value);
|
1035
|
+
} // Verify that this is a simple plain object.
|
1036
|
+
|
1037
|
+
|
1038
|
+
var proto = getPrototypeOf(value);
|
1039
|
+
|
1040
|
+
if (proto !== ObjectPrototype && (proto === null || getPrototypeOf(proto) !== null)) {
|
1041
|
+
if (temporaryReferences === undefined) {
|
1042
|
+
throw new Error('Only plain objects, and a few built-ins, can be passed to Server Actions. ' + 'Classes or null prototypes are not supported.');
|
1043
|
+
} // We can serialize class instances as temporary references.
|
1044
|
+
|
1045
|
+
|
1046
|
+
return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
|
1047
|
+
}
|
1048
|
+
|
1049
|
+
{
|
1050
|
+
if (value.$$typeof === (REACT_PROVIDER_TYPE)) {
|
1051
|
+
error('React Context Providers cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
|
1052
|
+
} else if (objectName(value) !== 'Object') {
|
1053
|
+
error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
|
1054
|
+
} else if (!isSimpleObject(value)) {
|
1055
|
+
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));
|
1056
|
+
} else if (Object.getOwnPropertySymbols) {
|
1057
|
+
var symbols = Object.getOwnPropertySymbols(value);
|
1058
|
+
|
1059
|
+
if (symbols.length > 0) {
|
1060
|
+
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));
|
1061
|
+
}
|
1062
|
+
}
|
1063
|
+
} // $FlowFixMe[incompatible-return]
|
1064
|
+
|
1065
|
+
|
1066
|
+
return value;
|
1067
|
+
}
|
1068
|
+
|
1069
|
+
if (typeof value === 'string') {
|
1070
|
+
// TODO: Maybe too clever. If we support URL there's no similar trick.
|
1071
|
+
if (value[value.length - 1] === 'Z') {
|
1072
|
+
// Possibly a Date, whose toJSON automatically calls toISOString
|
1073
|
+
// $FlowFixMe[incompatible-use]
|
1074
|
+
var _originalValue = parent[key];
|
1075
|
+
|
1076
|
+
if (_originalValue instanceof Date) {
|
1077
|
+
return serializeDateFromDateJSON(value);
|
1078
|
+
}
|
1079
|
+
}
|
1080
|
+
|
1081
|
+
return escapeStringValue(value);
|
1082
|
+
}
|
1083
|
+
|
1084
|
+
if (typeof value === 'boolean') {
|
1085
|
+
return value;
|
1086
|
+
}
|
1087
|
+
|
1088
|
+
if (typeof value === 'number') {
|
1089
|
+
return serializeNumber(value);
|
1090
|
+
}
|
1091
|
+
|
1092
|
+
if (typeof value === 'undefined') {
|
1093
|
+
return serializeUndefined();
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
if (typeof value === 'function') {
|
1097
|
+
var metaData = knownServerReferences.get(value);
|
1098
|
+
|
1099
|
+
if (metaData !== undefined) {
|
1100
|
+
var metaDataJSON = JSON.stringify(metaData, resolveToJSON);
|
1101
|
+
|
1102
|
+
if (formData === null) {
|
1103
|
+
// Upgrade to use FormData to allow us to stream this value.
|
1104
|
+
formData = new FormData();
|
1105
|
+
} // The reference to this function came from the same client so we can pass it back.
|
1106
|
+
|
1107
|
+
|
1108
|
+
var _refId = nextPartId++; // eslint-disable-next-line react-internal/safe-string-coercion
|
1109
|
+
|
1110
|
+
|
1111
|
+
formData.set(formFieldPrefix + _refId, metaDataJSON);
|
1112
|
+
return serializeServerReferenceID(_refId);
|
1113
|
+
}
|
1114
|
+
|
1115
|
+
if (temporaryReferences === undefined) {
|
1116
|
+
throw new Error('Client Functions cannot be passed directly to Server Functions. ' + 'Only Functions passed from the Server can be passed back again.');
|
1117
|
+
}
|
1118
|
+
|
1119
|
+
return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
|
1120
|
+
}
|
1121
|
+
|
1122
|
+
if (typeof value === 'symbol') {
|
1123
|
+
if (temporaryReferences === undefined) {
|
1124
|
+
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) ));
|
1125
|
+
}
|
1126
|
+
|
1127
|
+
return serializeTemporaryReferenceID(writeTemporaryReference(temporaryReferences, value));
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
if (typeof value === 'bigint') {
|
1131
|
+
return serializeBigInt(value);
|
1132
|
+
}
|
1133
|
+
|
1134
|
+
throw new Error("Type " + typeof value + " is not supported as an argument to a Server Function.");
|
1135
|
+
} // $FlowFixMe[incompatible-type] it's not going to be undefined because we'll encode it.
|
1136
|
+
|
1137
|
+
|
1138
|
+
var json = JSON.stringify(root, resolveToJSON);
|
1139
|
+
|
1140
|
+
if (formData === null) {
|
1141
|
+
// If it's a simple data structure, we just use plain JSON.
|
1142
|
+
resolve(json);
|
1143
|
+
} else {
|
1144
|
+
// Otherwise, we use FormData to let us stream in the result.
|
1145
|
+
formData.set(formFieldPrefix + '0', json);
|
1146
|
+
|
1147
|
+
if (pendingParts === 0) {
|
1148
|
+
// $FlowFixMe[incompatible-call] this has already been refined.
|
1149
|
+
resolve(formData);
|
1150
|
+
}
|
1151
|
+
}
|
1152
|
+
}
|
1153
|
+
var boundCache = new WeakMap();
|
1154
|
+
|
1155
|
+
function encodeFormData(reference) {
|
1156
|
+
var resolve, reject; // We need to have a handle on the thenable so that we can synchronously set
|
1157
|
+
// its status from processReply, when it can complete synchronously.
|
1158
|
+
|
1159
|
+
var thenable = new Promise(function (res, rej) {
|
1160
|
+
resolve = res;
|
1161
|
+
reject = rej;
|
1162
|
+
});
|
1163
|
+
processReply(reference, '', undefined, // TODO: This means React Elements can't be used as state in progressive enhancement.
|
1164
|
+
function (body) {
|
1165
|
+
if (typeof body === 'string') {
|
1166
|
+
var data = new FormData();
|
1167
|
+
data.append('0', body);
|
1168
|
+
body = data;
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
var fulfilled = thenable;
|
1172
|
+
fulfilled.status = 'fulfilled';
|
1173
|
+
fulfilled.value = body;
|
1174
|
+
resolve(body);
|
1175
|
+
}, function (e) {
|
1176
|
+
var rejected = thenable;
|
1177
|
+
rejected.status = 'rejected';
|
1178
|
+
rejected.reason = e;
|
1179
|
+
reject(e);
|
1180
|
+
});
|
1181
|
+
return thenable;
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
function defaultEncodeFormAction(identifierPrefix) {
|
1185
|
+
var reference = knownServerReferences.get(this);
|
1186
|
+
|
1187
|
+
if (!reference) {
|
1188
|
+
throw new Error('Tried to encode a Server Action from a different instance than the encoder is from. ' + 'This is a bug in React.');
|
1189
|
+
}
|
1190
|
+
|
1191
|
+
var data = null;
|
1192
|
+
var name;
|
1193
|
+
var boundPromise = reference.bound;
|
1194
|
+
|
1195
|
+
if (boundPromise !== null) {
|
1196
|
+
var thenable = boundCache.get(reference);
|
1197
|
+
|
1198
|
+
if (!thenable) {
|
1199
|
+
thenable = encodeFormData(reference);
|
1200
|
+
boundCache.set(reference, thenable);
|
1201
|
+
}
|
1202
|
+
|
1203
|
+
if (thenable.status === 'rejected') {
|
1204
|
+
throw thenable.reason;
|
1205
|
+
} else if (thenable.status !== 'fulfilled') {
|
1206
|
+
throw thenable;
|
1207
|
+
}
|
1208
|
+
|
1209
|
+
var encodedFormData = thenable.value; // This is hacky but we need the identifier prefix to be added to
|
1210
|
+
// all fields but the suspense cache would break since we might get
|
1211
|
+
// a new identifier each time. So we just append it at the end instead.
|
1212
|
+
|
1213
|
+
var prefixedData = new FormData(); // $FlowFixMe[prop-missing]
|
1214
|
+
|
1215
|
+
encodedFormData.forEach(function (value, key) {
|
1216
|
+
prefixedData.append('$ACTION_' + identifierPrefix + ':' + key, value);
|
1217
|
+
});
|
1218
|
+
data = prefixedData; // We encode the name of the prefix containing the data.
|
1219
|
+
|
1220
|
+
name = '$ACTION_REF_' + identifierPrefix;
|
1221
|
+
} else {
|
1222
|
+
// This is the simple case so we can just encode the ID.
|
1223
|
+
name = '$ACTION_ID_' + reference.id;
|
1224
|
+
}
|
1225
|
+
|
1226
|
+
return {
|
1227
|
+
name: name,
|
1228
|
+
method: 'POST',
|
1229
|
+
encType: 'multipart/form-data',
|
1230
|
+
data: data
|
1231
|
+
};
|
1232
|
+
}
|
1233
|
+
|
1234
|
+
function customEncodeFormAction(proxy, identifierPrefix, encodeFormAction) {
|
1235
|
+
var reference = knownServerReferences.get(proxy);
|
1236
|
+
|
1237
|
+
if (!reference) {
|
1238
|
+
throw new Error('Tried to encode a Server Action from a different instance than the encoder is from. ' + 'This is a bug in React.');
|
1239
|
+
}
|
1240
|
+
|
1241
|
+
var boundPromise = reference.bound;
|
1242
|
+
|
1243
|
+
if (boundPromise === null) {
|
1244
|
+
boundPromise = Promise.resolve([]);
|
111
1245
|
}
|
112
1246
|
|
113
|
-
return
|
1247
|
+
return encodeFormAction(reference.id, boundPromise);
|
114
1248
|
}
|
115
1249
|
|
116
|
-
|
1250
|
+
function isSignatureEqual(referenceId, numberOfBoundArgs) {
|
1251
|
+
var reference = knownServerReferences.get(this);
|
117
1252
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
var dispatcher = ReactDOMCurrentDispatcher.current;
|
1253
|
+
if (!reference) {
|
1254
|
+
throw new Error('Tried to encode a Server Action from a different instance than the encoder is from. ' + 'This is a bug in React.');
|
1255
|
+
}
|
122
1256
|
|
123
|
-
if (
|
124
|
-
|
1257
|
+
if (reference.id !== referenceId) {
|
1258
|
+
// These are different functions.
|
1259
|
+
return false;
|
1260
|
+
} // Now check if the number of bound arguments is the same.
|
125
1261
|
|
126
|
-
if (typeof model === 'string') {
|
127
|
-
href = model;
|
128
|
-
} else {
|
129
|
-
href = model[0];
|
130
|
-
options = model[1];
|
131
|
-
}
|
132
1262
|
|
133
|
-
|
134
|
-
case 'D':
|
135
|
-
{
|
136
|
-
// $FlowFixMe[prop-missing] options are not refined to their types by code
|
137
|
-
dispatcher.prefetchDNS(href, options);
|
138
|
-
return;
|
139
|
-
}
|
1263
|
+
var boundPromise = reference.bound;
|
140
1264
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
1265
|
+
if (boundPromise === null) {
|
1266
|
+
// No bound arguments.
|
1267
|
+
return numberOfBoundArgs === 0;
|
1268
|
+
} // Unwrap the bound arguments array by suspending, if necessary. As with
|
1269
|
+
// encodeFormData, this means isSignatureEqual can only be called while React
|
1270
|
+
// is rendering.
|
147
1271
|
|
148
|
-
case 'L':
|
149
|
-
{
|
150
|
-
// $FlowFixMe[prop-missing] options are not refined to their types by code
|
151
|
-
// $FlowFixMe[incompatible-call] options are not refined to their types by code
|
152
|
-
dispatcher.preload(href, options);
|
153
|
-
return;
|
154
|
-
}
|
155
1272
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
1273
|
+
switch (boundPromise.status) {
|
1274
|
+
case 'fulfilled':
|
1275
|
+
{
|
1276
|
+
var boundArgs = boundPromise.value;
|
1277
|
+
return boundArgs.length === numberOfBoundArgs;
|
1278
|
+
}
|
1279
|
+
|
1280
|
+
case 'pending':
|
1281
|
+
{
|
1282
|
+
throw boundPromise;
|
1283
|
+
}
|
1284
|
+
|
1285
|
+
case 'rejected':
|
1286
|
+
{
|
1287
|
+
throw boundPromise.reason;
|
1288
|
+
}
|
1289
|
+
|
1290
|
+
default:
|
1291
|
+
{
|
1292
|
+
if (typeof boundPromise.status === 'string') ; else {
|
1293
|
+
var pendingThenable = boundPromise;
|
1294
|
+
pendingThenable.status = 'pending';
|
1295
|
+
pendingThenable.then(function (boundArgs) {
|
1296
|
+
var fulfilledThenable = boundPromise;
|
1297
|
+
fulfilledThenable.status = 'fulfilled';
|
1298
|
+
fulfilledThenable.value = boundArgs;
|
1299
|
+
}, function (error) {
|
1300
|
+
var rejectedThenable = boundPromise;
|
1301
|
+
rejectedThenable.status = 'rejected';
|
1302
|
+
rejectedThenable.reason = error;
|
1303
|
+
});
|
162
1304
|
}
|
163
|
-
|
1305
|
+
|
1306
|
+
throw boundPromise;
|
1307
|
+
}
|
164
1308
|
}
|
165
1309
|
}
|
166
1310
|
|
167
|
-
|
1311
|
+
function registerServerReference(proxy, reference, encodeFormAction) {
|
1312
|
+
// Expose encoder for use by SSR, as well as a special bind that can be used to
|
1313
|
+
// keep server capabilities.
|
1314
|
+
{
|
1315
|
+
// Only expose this in builds that would actually use it. Not needed on the client.
|
1316
|
+
var $$FORM_ACTION = encodeFormAction === undefined ? defaultEncodeFormAction : function (identifierPrefix) {
|
1317
|
+
return customEncodeFormAction(this, identifierPrefix, encodeFormAction);
|
1318
|
+
};
|
1319
|
+
Object.defineProperties(proxy, {
|
1320
|
+
$$FORM_ACTION: {
|
1321
|
+
value: $$FORM_ACTION
|
1322
|
+
},
|
1323
|
+
$$IS_SIGNATURE_EQUAL: {
|
1324
|
+
value: isSignatureEqual
|
1325
|
+
},
|
1326
|
+
bind: {
|
1327
|
+
value: bind
|
1328
|
+
}
|
1329
|
+
});
|
1330
|
+
}
|
168
1331
|
|
169
|
-
|
170
|
-
//
|
171
|
-
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
|
172
|
-
// The Symbol used to tag the ReactElement-like types.
|
173
|
-
var REACT_ELEMENT_TYPE = Symbol.for('react.element');
|
174
|
-
var REACT_LAZY_TYPE = Symbol.for('react.lazy');
|
175
|
-
var REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for('react.default_value');
|
1332
|
+
knownServerReferences.set(proxy, reference);
|
1333
|
+
} // $FlowFixMe[method-unbinding]
|
176
1334
|
|
177
|
-
var
|
1335
|
+
var FunctionBind = Function.prototype.bind; // $FlowFixMe[method-unbinding]
|
1336
|
+
|
1337
|
+
var ArraySlice = Array.prototype.slice;
|
1338
|
+
|
1339
|
+
function bind() {
|
1340
|
+
// $FlowFixMe[unsupported-syntax]
|
1341
|
+
var newFn = FunctionBind.apply(this, arguments);
|
1342
|
+
var reference = knownServerReferences.get(this);
|
1343
|
+
|
1344
|
+
if (reference) {
|
1345
|
+
{
|
1346
|
+
var thisBind = arguments[0];
|
1347
|
+
|
1348
|
+
if (thisBind != null) {
|
1349
|
+
// This doesn't warn in browser environments since it's not instrumented outside
|
1350
|
+
// usedWithSSR. This makes this an SSR only warning which we don't generally do.
|
1351
|
+
// TODO: Consider a DEV only instrumentation in the browser.
|
1352
|
+
error('Cannot bind "this" of a Server Action. Pass null or undefined as the first argument to .bind().');
|
1353
|
+
}
|
1354
|
+
}
|
1355
|
+
|
1356
|
+
var args = ArraySlice.call(arguments, 1);
|
1357
|
+
var boundPromise = null;
|
1358
|
+
|
1359
|
+
if (reference.bound !== null) {
|
1360
|
+
boundPromise = Promise.resolve(reference.bound).then(function (boundArgs) {
|
1361
|
+
return boundArgs.concat(args);
|
1362
|
+
});
|
1363
|
+
} else {
|
1364
|
+
boundPromise = Promise.resolve(args);
|
1365
|
+
} // Expose encoder for use by SSR, as well as a special bind that can be used to
|
1366
|
+
// keep server capabilities.
|
1367
|
+
|
1368
|
+
|
1369
|
+
{
|
1370
|
+
// Only expose this in builds that would actually use it. Not needed on the client.
|
1371
|
+
Object.defineProperties(newFn, {
|
1372
|
+
$$FORM_ACTION: {
|
1373
|
+
value: this.$$FORM_ACTION
|
1374
|
+
},
|
1375
|
+
$$IS_SIGNATURE_EQUAL: {
|
1376
|
+
value: isSignatureEqual
|
1377
|
+
},
|
1378
|
+
bind: {
|
1379
|
+
value: bind
|
1380
|
+
}
|
1381
|
+
});
|
1382
|
+
}
|
178
1383
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
|
1384
|
+
knownServerReferences.set(newFn, {
|
1385
|
+
id: reference.id,
|
1386
|
+
bound: boundPromise
|
1387
|
+
});
|
184
1388
|
}
|
185
1389
|
|
186
|
-
return
|
1390
|
+
return newFn;
|
1391
|
+
}
|
1392
|
+
|
1393
|
+
function createServerReference$1(id, callServer, encodeFormAction) {
|
1394
|
+
var proxy = function () {
|
1395
|
+
// $FlowFixMe[method-unbinding]
|
1396
|
+
var args = Array.prototype.slice.call(arguments);
|
1397
|
+
return callServer(id, args);
|
1398
|
+
};
|
1399
|
+
|
1400
|
+
registerServerReference(proxy, {
|
1401
|
+
id: id,
|
1402
|
+
bound: null
|
1403
|
+
}, encodeFormAction);
|
1404
|
+
return proxy;
|
187
1405
|
}
|
188
1406
|
|
1407
|
+
var ROW_ID = 0;
|
1408
|
+
var ROW_TAG = 1;
|
1409
|
+
var ROW_LENGTH = 2;
|
1410
|
+
var ROW_CHUNK_BY_NEWLINE = 3;
|
1411
|
+
var ROW_CHUNK_BY_LENGTH = 4;
|
189
1412
|
var PENDING = 'pending';
|
190
1413
|
var BLOCKED = 'blocked';
|
1414
|
+
var CYCLIC = 'cyclic';
|
191
1415
|
var RESOLVED_MODEL = 'resolved_model';
|
192
1416
|
var RESOLVED_MODULE = 'resolved_module';
|
193
1417
|
var INITIALIZED = 'fulfilled';
|
@@ -198,6 +1422,10 @@ function Chunk(status, value, reason, response) {
|
|
198
1422
|
this.value = value;
|
199
1423
|
this.reason = reason;
|
200
1424
|
this._response = response;
|
1425
|
+
|
1426
|
+
{
|
1427
|
+
this._debugInfo = null;
|
1428
|
+
}
|
201
1429
|
} // We subclass Promise.prototype so that we get other methods like .catch
|
202
1430
|
|
203
1431
|
|
@@ -225,6 +1453,7 @@ Chunk.prototype.then = function (resolve, reject) {
|
|
225
1453
|
|
226
1454
|
case PENDING:
|
227
1455
|
case BLOCKED:
|
1456
|
+
case CYCLIC:
|
228
1457
|
if (resolve) {
|
229
1458
|
if (chunk.value === null) {
|
230
1459
|
chunk.value = [];
|
@@ -269,6 +1498,7 @@ function readChunk(chunk) {
|
|
269
1498
|
|
270
1499
|
case PENDING:
|
271
1500
|
case BLOCKED:
|
1501
|
+
case CYCLIC:
|
272
1502
|
// eslint-disable-next-line no-throw-literal
|
273
1503
|
throw chunk;
|
274
1504
|
|
@@ -312,6 +1542,7 @@ function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
|
|
312
1542
|
|
313
1543
|
case PENDING:
|
314
1544
|
case BLOCKED:
|
1545
|
+
case CYCLIC:
|
315
1546
|
chunk.value = resolveListeners;
|
316
1547
|
chunk.reason = rejectListeners;
|
317
1548
|
break;
|
@@ -351,6 +1582,11 @@ function createResolvedModuleChunk(response, value) {
|
|
351
1582
|
return new Chunk(RESOLVED_MODULE, value, null, response);
|
352
1583
|
}
|
353
1584
|
|
1585
|
+
function createInitializedTextChunk(response, value) {
|
1586
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
1587
|
+
return new Chunk(INITIALIZED, value, null, response);
|
1588
|
+
}
|
1589
|
+
|
354
1590
|
function resolveModelChunk(chunk, value) {
|
355
1591
|
if (chunk.status !== PENDING) {
|
356
1592
|
// We already resolved. We didn't expect to see this.
|
@@ -399,9 +1635,17 @@ function initializeModelChunk(chunk) {
|
|
399
1635
|
var prevBlocked = initializingChunkBlockedModel;
|
400
1636
|
initializingChunk = chunk;
|
401
1637
|
initializingChunkBlockedModel = null;
|
1638
|
+
var resolvedModel = chunk.value; // We go to the CYCLIC state until we've fully resolved this.
|
1639
|
+
// We do this before parsing in case we try to initialize the same chunk
|
1640
|
+
// while parsing the model. Such as in a cyclic reference.
|
1641
|
+
|
1642
|
+
var cyclicChunk = chunk;
|
1643
|
+
cyclicChunk.status = CYCLIC;
|
1644
|
+
cyclicChunk.value = null;
|
1645
|
+
cyclicChunk.reason = null;
|
402
1646
|
|
403
1647
|
try {
|
404
|
-
var value = parseModel(chunk._response,
|
1648
|
+
var value = parseModel(chunk._response, resolvedModel);
|
405
1649
|
|
406
1650
|
if (initializingChunkBlockedModel !== null && initializingChunkBlockedModel.deps > 0) {
|
407
1651
|
initializingChunkBlockedModel.value = value; // We discovered new dependencies on modules that are not yet resolved.
|
@@ -412,9 +1656,14 @@ function initializeModelChunk(chunk) {
|
|
412
1656
|
blockedChunk.value = null;
|
413
1657
|
blockedChunk.reason = null;
|
414
1658
|
} else {
|
1659
|
+
var resolveListeners = cyclicChunk.value;
|
415
1660
|
var initializedChunk = chunk;
|
416
1661
|
initializedChunk.status = INITIALIZED;
|
417
1662
|
initializedChunk.value = value;
|
1663
|
+
|
1664
|
+
if (resolveListeners !== null) {
|
1665
|
+
wakeChunk(resolveListeners, value);
|
1666
|
+
}
|
418
1667
|
}
|
419
1668
|
} catch (error) {
|
420
1669
|
var erroredChunk = chunk;
|
@@ -453,17 +1702,20 @@ function reportGlobalError(response, error) {
|
|
453
1702
|
}
|
454
1703
|
|
455
1704
|
function createElement(type, key, props) {
|
456
|
-
var element
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
1705
|
+
var element;
|
1706
|
+
|
1707
|
+
{
|
1708
|
+
element = {
|
1709
|
+
// This tag allows us to uniquely identify this as a React Element
|
1710
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
1711
|
+
type: type,
|
1712
|
+
key: key,
|
1713
|
+
ref: null,
|
1714
|
+
props: props,
|
1715
|
+
// Record the component responsible for creating this element.
|
1716
|
+
_owner: null
|
1717
|
+
};
|
1718
|
+
}
|
467
1719
|
|
468
1720
|
{
|
469
1721
|
// We don't really need to add any of these but keeping them for good measure.
|
@@ -476,17 +1728,12 @@ function createElement(type, key, props) {
|
|
476
1728
|
writable: true,
|
477
1729
|
value: true // This element has already been validated on the server.
|
478
1730
|
|
479
|
-
});
|
480
|
-
|
481
|
-
|
482
|
-
enumerable: false,
|
483
|
-
writable: false,
|
484
|
-
value: null
|
485
|
-
});
|
486
|
-
Object.defineProperty(element, '_source', {
|
1731
|
+
}); // debugInfo contains Server Component debug information.
|
1732
|
+
|
1733
|
+
Object.defineProperty(element, '_debugInfo', {
|
487
1734
|
configurable: false,
|
488
1735
|
enumerable: false,
|
489
|
-
writable:
|
1736
|
+
writable: true,
|
490
1737
|
value: null
|
491
1738
|
});
|
492
1739
|
}
|
@@ -500,6 +1747,13 @@ function createLazyChunkWrapper(chunk) {
|
|
500
1747
|
_payload: chunk,
|
501
1748
|
_init: readChunk
|
502
1749
|
};
|
1750
|
+
|
1751
|
+
{
|
1752
|
+
// Ensure we have a live array to track future debug info.
|
1753
|
+
var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
|
1754
|
+
lazyType._debugInfo = chunkDebugInfo;
|
1755
|
+
}
|
1756
|
+
|
503
1757
|
return lazyType;
|
504
1758
|
}
|
505
1759
|
|
@@ -515,15 +1769,18 @@ function getChunk(response, id) {
|
|
515
1769
|
return chunk;
|
516
1770
|
}
|
517
1771
|
|
518
|
-
function createModelResolver(chunk, parentObject, key) {
|
1772
|
+
function createModelResolver(chunk, parentObject, key, cyclic) {
|
519
1773
|
var blocked;
|
520
1774
|
|
521
1775
|
if (initializingChunkBlockedModel) {
|
522
1776
|
blocked = initializingChunkBlockedModel;
|
523
|
-
|
1777
|
+
|
1778
|
+
if (!cyclic) {
|
1779
|
+
blocked.deps++;
|
1780
|
+
}
|
524
1781
|
} else {
|
525
1782
|
blocked = initializingChunkBlockedModel = {
|
526
|
-
deps: 1,
|
1783
|
+
deps: cyclic ? 0 : 1,
|
527
1784
|
value: null
|
528
1785
|
};
|
529
1786
|
}
|
@@ -579,10 +1836,32 @@ function createServerReferenceProxy(response, metaData) {
|
|
579
1836
|
});
|
580
1837
|
};
|
581
1838
|
|
582
|
-
|
1839
|
+
registerServerReference(proxy, metaData, response._encodeFormAction);
|
583
1840
|
return proxy;
|
584
1841
|
}
|
585
1842
|
|
1843
|
+
function getOutlinedModel(response, id) {
|
1844
|
+
var chunk = getChunk(response, id);
|
1845
|
+
|
1846
|
+
switch (chunk.status) {
|
1847
|
+
case RESOLVED_MODEL:
|
1848
|
+
initializeModelChunk(chunk);
|
1849
|
+
break;
|
1850
|
+
} // The status might have changed after initialization.
|
1851
|
+
|
1852
|
+
|
1853
|
+
switch (chunk.status) {
|
1854
|
+
case INITIALIZED:
|
1855
|
+
{
|
1856
|
+
return chunk.value;
|
1857
|
+
}
|
1858
|
+
// We always encode it first in the stream so it won't be pending.
|
1859
|
+
|
1860
|
+
default:
|
1861
|
+
throw chunk.reason;
|
1862
|
+
}
|
1863
|
+
}
|
1864
|
+
|
586
1865
|
function parseModelString(response, parentObject, key, value) {
|
587
1866
|
if (value[0] === '$') {
|
588
1867
|
if (value === '$') {
|
@@ -610,6 +1889,11 @@ function parseModelString(response, parentObject, key, value) {
|
|
610
1889
|
case '@':
|
611
1890
|
{
|
612
1891
|
// Promise
|
1892
|
+
if (value.length === 2) {
|
1893
|
+
// Infinite promise that never resolves.
|
1894
|
+
return new Promise(function () {});
|
1895
|
+
}
|
1896
|
+
|
613
1897
|
var _id = parseInt(value.slice(2), 16);
|
614
1898
|
|
615
1899
|
var _chunk = getChunk(response, _id);
|
@@ -623,37 +1907,46 @@ function parseModelString(response, parentObject, key, value) {
|
|
623
1907
|
return Symbol.for(value.slice(2));
|
624
1908
|
}
|
625
1909
|
|
626
|
-
case 'P':
|
627
|
-
{
|
628
|
-
// Server Context Provider
|
629
|
-
return getOrCreateServerContext(value.slice(2)).Provider;
|
630
|
-
}
|
631
|
-
|
632
1910
|
case 'F':
|
633
1911
|
{
|
634
1912
|
// Server Reference
|
635
1913
|
var _id2 = parseInt(value.slice(2), 16);
|
636
1914
|
|
637
|
-
var
|
638
|
-
|
639
|
-
|
640
|
-
case RESOLVED_MODEL:
|
641
|
-
initializeModelChunk(_chunk2);
|
642
|
-
break;
|
643
|
-
} // The status might have changed after initialization.
|
1915
|
+
var metadata = getOutlinedModel(response, _id2);
|
1916
|
+
return createServerReferenceProxy(response, metadata);
|
1917
|
+
}
|
644
1918
|
|
1919
|
+
case 'T':
|
1920
|
+
{
|
1921
|
+
// Temporary Reference
|
1922
|
+
var _id3 = parseInt(value.slice(2), 16);
|
645
1923
|
|
646
|
-
|
647
|
-
case INITIALIZED:
|
648
|
-
{
|
649
|
-
var metadata = _chunk2.value;
|
650
|
-
return createServerReferenceProxy(response, metadata);
|
651
|
-
}
|
652
|
-
// We always encode it first in the stream so it won't be pending.
|
1924
|
+
var temporaryReferences = response._tempRefs;
|
653
1925
|
|
654
|
-
|
655
|
-
|
1926
|
+
if (temporaryReferences == null) {
|
1927
|
+
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.');
|
656
1928
|
}
|
1929
|
+
|
1930
|
+
return readTemporaryReference(temporaryReferences, _id3);
|
1931
|
+
}
|
1932
|
+
|
1933
|
+
case 'Q':
|
1934
|
+
{
|
1935
|
+
// Map
|
1936
|
+
var _id4 = parseInt(value.slice(2), 16);
|
1937
|
+
|
1938
|
+
var data = getOutlinedModel(response, _id4);
|
1939
|
+
return new Map(data);
|
1940
|
+
}
|
1941
|
+
|
1942
|
+
case 'W':
|
1943
|
+
{
|
1944
|
+
// Set
|
1945
|
+
var _id5 = parseInt(value.slice(2), 16);
|
1946
|
+
|
1947
|
+
var _data = getOutlinedModel(response, _id5);
|
1948
|
+
|
1949
|
+
return new Set(_data);
|
657
1950
|
}
|
658
1951
|
|
659
1952
|
case 'I':
|
@@ -697,38 +1990,78 @@ function parseModelString(response, parentObject, key, value) {
|
|
697
1990
|
return BigInt(value.slice(2));
|
698
1991
|
}
|
699
1992
|
|
1993
|
+
case 'E':
|
1994
|
+
{
|
1995
|
+
{
|
1996
|
+
// In DEV mode we allow indirect eval to produce functions for logging.
|
1997
|
+
// This should not compile to eval() because then it has local scope access.
|
1998
|
+
try {
|
1999
|
+
// eslint-disable-next-line no-eval
|
2000
|
+
return (0, eval)(value.slice(2));
|
2001
|
+
} catch (x) {
|
2002
|
+
// We currently use this to express functions so we fail parsing it,
|
2003
|
+
// let's just return a blank function as a place holder.
|
2004
|
+
return function () {};
|
2005
|
+
}
|
2006
|
+
} // Fallthrough
|
2007
|
+
|
2008
|
+
}
|
2009
|
+
|
700
2010
|
default:
|
701
2011
|
{
|
702
2012
|
// We assume that anything else is a reference ID.
|
703
|
-
var
|
2013
|
+
var _id6 = parseInt(value.slice(1), 16);
|
704
2014
|
|
705
|
-
var
|
2015
|
+
var _chunk2 = getChunk(response, _id6);
|
706
2016
|
|
707
|
-
switch (
|
2017
|
+
switch (_chunk2.status) {
|
708
2018
|
case RESOLVED_MODEL:
|
709
|
-
initializeModelChunk(
|
2019
|
+
initializeModelChunk(_chunk2);
|
710
2020
|
break;
|
711
2021
|
|
712
2022
|
case RESOLVED_MODULE:
|
713
|
-
initializeModuleChunk(
|
2023
|
+
initializeModuleChunk(_chunk2);
|
714
2024
|
break;
|
715
2025
|
} // The status might have changed after initialization.
|
716
2026
|
|
717
2027
|
|
718
|
-
switch (
|
2028
|
+
switch (_chunk2.status) {
|
719
2029
|
case INITIALIZED:
|
720
|
-
|
2030
|
+
var chunkValue = _chunk2.value;
|
2031
|
+
|
2032
|
+
if (_chunk2._debugInfo) {
|
2033
|
+
// If we have a direct reference to an object that was rendered by a synchronous
|
2034
|
+
// server component, it might have some debug info about how it was rendered.
|
2035
|
+
// We forward this to the underlying object. This might be a React Element or
|
2036
|
+
// an Array fragment.
|
2037
|
+
// If this was a string / number return value we lose the debug info. We choose
|
2038
|
+
// that tradeoff to allow sync server components to return plain values and not
|
2039
|
+
// use them as React Nodes necessarily. We could otherwise wrap them in a Lazy.
|
2040
|
+
if (typeof chunkValue === 'object' && chunkValue !== null && (Array.isArray(chunkValue) || chunkValue.$$typeof === REACT_ELEMENT_TYPE) && !chunkValue._debugInfo) {
|
2041
|
+
// We should maybe use a unique symbol for arrays but this is a React owned array.
|
2042
|
+
// $FlowFixMe[prop-missing]: This should be added to elements.
|
2043
|
+
Object.defineProperty(chunkValue, '_debugInfo', {
|
2044
|
+
configurable: false,
|
2045
|
+
enumerable: false,
|
2046
|
+
writable: true,
|
2047
|
+
value: _chunk2._debugInfo
|
2048
|
+
});
|
2049
|
+
}
|
2050
|
+
}
|
2051
|
+
|
2052
|
+
return chunkValue;
|
721
2053
|
|
722
2054
|
case PENDING:
|
723
2055
|
case BLOCKED:
|
2056
|
+
case CYCLIC:
|
724
2057
|
var parentChunk = initializingChunk;
|
725
2058
|
|
726
|
-
|
2059
|
+
_chunk2.then(createModelResolver(parentChunk, parentObject, key, _chunk2.status === CYCLIC), createModelReject(parentChunk));
|
727
2060
|
|
728
2061
|
return null;
|
729
2062
|
|
730
2063
|
default:
|
731
|
-
throw
|
2064
|
+
throw _chunk2.reason;
|
732
2065
|
}
|
733
2066
|
}
|
734
2067
|
}
|
@@ -736,6 +2069,7 @@ function parseModelString(response, parentObject, key, value) {
|
|
736
2069
|
|
737
2070
|
return value;
|
738
2071
|
}
|
2072
|
+
|
739
2073
|
function parseModelTuple(response, value) {
|
740
2074
|
var tuple = value;
|
741
2075
|
|
@@ -752,15 +2086,29 @@ function missingCall() {
|
|
752
2086
|
throw new Error('Trying to call a function from "use server" but the callServer option ' + 'was not implemented in your router runtime.');
|
753
2087
|
}
|
754
2088
|
|
755
|
-
function createResponse
|
2089
|
+
function createResponse(bundlerConfig, moduleLoading, callServer, encodeFormAction, nonce, temporaryReferences) {
|
756
2090
|
var chunks = new Map();
|
757
2091
|
var response = {
|
758
2092
|
_bundlerConfig: bundlerConfig,
|
2093
|
+
_moduleLoading: moduleLoading,
|
759
2094
|
_callServer: callServer !== undefined ? callServer : missingCall,
|
760
|
-
|
761
|
-
|
2095
|
+
_encodeFormAction: encodeFormAction,
|
2096
|
+
_nonce: nonce,
|
2097
|
+
_chunks: chunks,
|
2098
|
+
_stringDecoder: createStringDecoder(),
|
2099
|
+
_fromJSON: null,
|
2100
|
+
_rowState: 0,
|
2101
|
+
_rowID: 0,
|
2102
|
+
_rowTag: 0,
|
2103
|
+
_rowLength: 0,
|
2104
|
+
_buffer: [],
|
2105
|
+
_tempRefs: temporaryReferences
|
2106
|
+
}; // Don't inline this call because it causes closure to outline the call above.
|
2107
|
+
|
2108
|
+
response._fromJSON = createFromJSONCallback(response);
|
762
2109
|
return response;
|
763
2110
|
}
|
2111
|
+
|
764
2112
|
function resolveModel(response, id, model) {
|
765
2113
|
var chunks = response._chunks;
|
766
2114
|
var chunk = chunks.get(id);
|
@@ -771,11 +2119,20 @@ function resolveModel(response, id, model) {
|
|
771
2119
|
resolveModelChunk(chunk, model);
|
772
2120
|
}
|
773
2121
|
}
|
2122
|
+
|
2123
|
+
function resolveText(response, id, text) {
|
2124
|
+
var chunks = response._chunks; // We assume that we always reference large strings after they've been
|
2125
|
+
// emitted.
|
2126
|
+
|
2127
|
+
chunks.set(id, createInitializedTextChunk(response, text));
|
2128
|
+
}
|
2129
|
+
|
774
2130
|
function resolveModule(response, id, model) {
|
775
2131
|
var chunks = response._chunks;
|
776
2132
|
var chunk = chunks.get(id);
|
777
2133
|
var clientReferenceMetadata = parseModel(response, model);
|
778
|
-
var clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata);
|
2134
|
+
var clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata);
|
2135
|
+
prepareDestinationForModule(response._moduleLoading, response._nonce, clientReferenceMetadata); // TODO: Add an option to encode modules that are lazy loaded.
|
779
2136
|
// For now we preload all modules as early as possible since it's likely
|
780
2137
|
// that we'll need them.
|
781
2138
|
|
@@ -811,6 +2168,7 @@ function resolveModule(response, id, model) {
|
|
811
2168
|
}
|
812
2169
|
}
|
813
2170
|
}
|
2171
|
+
|
814
2172
|
function resolveErrorDev(response, id, digest, message, stack) {
|
815
2173
|
|
816
2174
|
|
@@ -827,47 +2185,64 @@ function resolveErrorDev(response, id, digest, message, stack) {
|
|
827
2185
|
triggerErrorOnChunk(chunk, errorWithDigest);
|
828
2186
|
}
|
829
2187
|
}
|
2188
|
+
|
830
2189
|
function resolveHint(response, code, model) {
|
831
2190
|
var hintModel = parseModel(response, model);
|
832
2191
|
dispatchHint(code, hintModel);
|
833
2192
|
}
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
2193
|
+
|
2194
|
+
function resolveDebugInfo(response, id, debugInfo) {
|
2195
|
+
|
2196
|
+
var chunk = getChunk(response, id);
|
2197
|
+
var chunkDebugInfo = chunk._debugInfo || (chunk._debugInfo = []);
|
2198
|
+
chunkDebugInfo.push(debugInfo);
|
840
2199
|
}
|
841
2200
|
|
842
|
-
function
|
843
|
-
|
844
|
-
|
2201
|
+
function resolveConsoleEntry(response, value) {
|
2202
|
+
|
2203
|
+
var payload = parseModel(response, value);
|
2204
|
+
var methodName = payload[0]; // TODO: Restore the fake stack before logging.
|
2205
|
+
// const stackTrace = payload[1];
|
2206
|
+
|
2207
|
+
var env = payload[2];
|
2208
|
+
var args = payload.slice(3);
|
2209
|
+
printToConsole(methodName, args, env);
|
2210
|
+
}
|
2211
|
+
|
2212
|
+
function processFullRow(response, id, tag, buffer, chunk) {
|
2213
|
+
|
2214
|
+
var stringDecoder = response._stringDecoder;
|
2215
|
+
var row = '';
|
2216
|
+
|
2217
|
+
for (var i = 0; i < buffer.length; i++) {
|
2218
|
+
row += readPartialStringChunk(stringDecoder, buffer[i]);
|
845
2219
|
}
|
846
2220
|
|
847
|
-
|
848
|
-
var id = parseInt(row.slice(0, colon), 16);
|
849
|
-
var tag = row[colon + 1]; // When tags that are not text are added, check them here before
|
850
|
-
// parsing the row as text.
|
851
|
-
// switch (tag) {
|
852
|
-
// }
|
2221
|
+
row += readFinalStringChunk(stringDecoder, chunk);
|
853
2222
|
|
854
2223
|
switch (tag) {
|
855
|
-
case
|
2224
|
+
case 73
|
2225
|
+
/* "I" */
|
2226
|
+
:
|
856
2227
|
{
|
857
|
-
resolveModule(response, id, row
|
2228
|
+
resolveModule(response, id, row);
|
858
2229
|
return;
|
859
2230
|
}
|
860
2231
|
|
861
|
-
case
|
2232
|
+
case 72
|
2233
|
+
/* "H" */
|
2234
|
+
:
|
862
2235
|
{
|
863
|
-
var code = row[
|
864
|
-
resolveHint(response, code, row.slice(
|
2236
|
+
var code = row[0];
|
2237
|
+
resolveHint(response, code, row.slice(1));
|
865
2238
|
return;
|
866
2239
|
}
|
867
2240
|
|
868
|
-
case
|
2241
|
+
case 69
|
2242
|
+
/* "E" */
|
2243
|
+
:
|
869
2244
|
{
|
870
|
-
var errorInfo = JSON.parse(row
|
2245
|
+
var errorInfo = JSON.parse(row);
|
871
2246
|
|
872
2247
|
{
|
873
2248
|
resolveErrorDev(response, id, errorInfo.digest, errorInfo.message, errorInfo.stack);
|
@@ -876,42 +2251,186 @@ function processFullRow(response, row) {
|
|
876
2251
|
return;
|
877
2252
|
}
|
878
2253
|
|
2254
|
+
case 84
|
2255
|
+
/* "T" */
|
2256
|
+
:
|
2257
|
+
{
|
2258
|
+
resolveText(response, id, row);
|
2259
|
+
return;
|
2260
|
+
}
|
2261
|
+
|
2262
|
+
case 68
|
2263
|
+
/* "D" */
|
2264
|
+
:
|
2265
|
+
{
|
2266
|
+
{
|
2267
|
+
var debugInfo = JSON.parse(row);
|
2268
|
+
resolveDebugInfo(response, id, debugInfo);
|
2269
|
+
return;
|
2270
|
+
} // Fallthrough to share the error with Console entries.
|
2271
|
+
|
2272
|
+
}
|
2273
|
+
|
2274
|
+
case 87
|
2275
|
+
/* "W" */
|
2276
|
+
:
|
2277
|
+
{
|
2278
|
+
{
|
2279
|
+
resolveConsoleEntry(response, row);
|
2280
|
+
return;
|
2281
|
+
}
|
2282
|
+
}
|
2283
|
+
|
2284
|
+
case 80
|
2285
|
+
/* "P" */
|
2286
|
+
:
|
2287
|
+
// Fallthrough
|
2288
|
+
|
879
2289
|
default:
|
2290
|
+
/* """ "{" "[" "t" "f" "n" "0" - "9" */
|
880
2291
|
{
|
881
2292
|
// We assume anything else is JSON.
|
882
|
-
resolveModel(response, id, row
|
2293
|
+
resolveModel(response, id, row);
|
883
2294
|
return;
|
884
2295
|
}
|
885
2296
|
}
|
886
2297
|
}
|
887
2298
|
|
888
|
-
function
|
889
|
-
var
|
2299
|
+
function processBinaryChunk(response, chunk) {
|
2300
|
+
var i = 0;
|
2301
|
+
var rowState = response._rowState;
|
2302
|
+
var rowID = response._rowID;
|
2303
|
+
var rowTag = response._rowTag;
|
2304
|
+
var rowLength = response._rowLength;
|
2305
|
+
var buffer = response._buffer;
|
2306
|
+
var chunkLength = chunk.length;
|
2307
|
+
|
2308
|
+
while (i < chunkLength) {
|
2309
|
+
var lastIdx = -1;
|
2310
|
+
|
2311
|
+
switch (rowState) {
|
2312
|
+
case ROW_ID:
|
2313
|
+
{
|
2314
|
+
var byte = chunk[i++];
|
2315
|
+
|
2316
|
+
if (byte === 58
|
2317
|
+
/* ":" */
|
2318
|
+
) {
|
2319
|
+
// Finished the rowID, next we'll parse the tag.
|
2320
|
+
rowState = ROW_TAG;
|
2321
|
+
} else {
|
2322
|
+
rowID = rowID << 4 | (byte > 96 ? byte - 87 : byte - 48);
|
2323
|
+
}
|
890
2324
|
|
891
|
-
|
892
|
-
|
893
|
-
processFullRow(response, fullrow);
|
894
|
-
response._partialRow = '';
|
895
|
-
offset = linebreak + 1;
|
896
|
-
linebreak = chunk.indexOf('\n', offset);
|
897
|
-
}
|
2325
|
+
continue;
|
2326
|
+
}
|
898
2327
|
|
899
|
-
|
900
|
-
|
901
|
-
|
2328
|
+
case ROW_TAG:
|
2329
|
+
{
|
2330
|
+
var resolvedRowTag = chunk[i];
|
2331
|
+
|
2332
|
+
if (resolvedRowTag === 84
|
2333
|
+
/* "T" */
|
2334
|
+
|| enableBinaryFlight
|
2335
|
+
/* "V" */
|
2336
|
+
) {
|
2337
|
+
rowTag = resolvedRowTag;
|
2338
|
+
rowState = ROW_LENGTH;
|
2339
|
+
i++;
|
2340
|
+
} else if (resolvedRowTag > 64 && resolvedRowTag < 91
|
2341
|
+
/* "A"-"Z" */
|
2342
|
+
) {
|
2343
|
+
rowTag = resolvedRowTag;
|
2344
|
+
rowState = ROW_CHUNK_BY_NEWLINE;
|
2345
|
+
i++;
|
2346
|
+
} else {
|
2347
|
+
rowTag = 0;
|
2348
|
+
rowState = ROW_CHUNK_BY_NEWLINE; // This was an unknown tag so it was probably part of the data.
|
2349
|
+
}
|
902
2350
|
|
903
|
-
|
904
|
-
|
2351
|
+
continue;
|
2352
|
+
}
|
2353
|
+
|
2354
|
+
case ROW_LENGTH:
|
2355
|
+
{
|
2356
|
+
var _byte = chunk[i++];
|
2357
|
+
|
2358
|
+
if (_byte === 44
|
2359
|
+
/* "," */
|
2360
|
+
) {
|
2361
|
+
// Finished the rowLength, next we'll buffer up to that length.
|
2362
|
+
rowState = ROW_CHUNK_BY_LENGTH;
|
2363
|
+
} else {
|
2364
|
+
rowLength = rowLength << 4 | (_byte > 96 ? _byte - 87 : _byte - 48);
|
2365
|
+
}
|
2366
|
+
|
2367
|
+
continue;
|
2368
|
+
}
|
2369
|
+
|
2370
|
+
case ROW_CHUNK_BY_NEWLINE:
|
2371
|
+
{
|
2372
|
+
// We're looking for a newline
|
2373
|
+
lastIdx = chunk.indexOf(10
|
2374
|
+
/* "\n" */
|
2375
|
+
, i);
|
2376
|
+
break;
|
2377
|
+
}
|
2378
|
+
|
2379
|
+
case ROW_CHUNK_BY_LENGTH:
|
2380
|
+
{
|
2381
|
+
// We're looking for the remaining byte length
|
2382
|
+
lastIdx = i + rowLength;
|
2383
|
+
|
2384
|
+
if (lastIdx > chunk.length) {
|
2385
|
+
lastIdx = -1;
|
2386
|
+
}
|
2387
|
+
|
2388
|
+
break;
|
2389
|
+
}
|
2390
|
+
}
|
2391
|
+
|
2392
|
+
var offset = chunk.byteOffset + i;
|
2393
|
+
|
2394
|
+
if (lastIdx > -1) {
|
2395
|
+
// We found the last chunk of the row
|
2396
|
+
var length = lastIdx - i;
|
2397
|
+
var lastChunk = new Uint8Array(chunk.buffer, offset, length);
|
2398
|
+
processFullRow(response, rowID, rowTag, buffer, lastChunk); // Reset state machine for a new row
|
2399
|
+
|
2400
|
+
i = lastIdx;
|
2401
|
+
|
2402
|
+
if (rowState === ROW_CHUNK_BY_NEWLINE) {
|
2403
|
+
// If we're trailing by a newline we need to skip it.
|
2404
|
+
i++;
|
2405
|
+
}
|
2406
|
+
|
2407
|
+
rowState = ROW_ID;
|
2408
|
+
rowTag = 0;
|
2409
|
+
rowID = 0;
|
2410
|
+
rowLength = 0;
|
2411
|
+
buffer.length = 0;
|
2412
|
+
} else {
|
2413
|
+
// The rest of this row is in a future chunk. We stash the rest of the
|
2414
|
+
// current chunk until we can process the full row.
|
2415
|
+
var _length = chunk.byteLength - i;
|
2416
|
+
|
2417
|
+
var remainingSlice = new Uint8Array(chunk.buffer, offset, _length);
|
2418
|
+
buffer.push(remainingSlice); // Update how many bytes we're still waiting for. If we're looking for
|
2419
|
+
// a newline, this doesn't hurt since we'll just ignore it.
|
905
2420
|
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
response._partialRow = '';
|
910
|
-
chunk = chunk.subarray(linebreak + 1);
|
911
|
-
linebreak = chunk.indexOf(10); // newline
|
2421
|
+
rowLength -= remainingSlice.byteLength;
|
2422
|
+
break;
|
2423
|
+
}
|
912
2424
|
}
|
913
2425
|
|
914
|
-
response.
|
2426
|
+
response._rowState = rowState;
|
2427
|
+
response._rowID = rowID;
|
2428
|
+
response._rowTag = rowTag;
|
2429
|
+
response._rowLength = rowLength;
|
2430
|
+
}
|
2431
|
+
|
2432
|
+
function parseModel(response, json) {
|
2433
|
+
return JSON.parse(json, response._fromJSON);
|
915
2434
|
}
|
916
2435
|
|
917
2436
|
function createFromJSONCallback(response) {
|
@@ -930,20 +2449,12 @@ function createFromJSONCallback(response) {
|
|
930
2449
|
};
|
931
2450
|
}
|
932
2451
|
|
933
|
-
function
|
934
|
-
//
|
935
|
-
//
|
936
|
-
|
937
|
-
|
938
|
-
response
|
939
|
-
|
940
|
-
{
|
941
|
-
response._stringDecoder = stringDecoder;
|
942
|
-
} // Don't inline this call because it causes closure to outline the call above.
|
943
|
-
|
944
|
-
|
945
|
-
response._fromJSON = createFromJSONCallback(response);
|
946
|
-
return response;
|
2452
|
+
function close(response) {
|
2453
|
+
// In case there are any remaining unresolved chunks, they won't
|
2454
|
+
// be resolved now. So we need to issue an error to those.
|
2455
|
+
// Ideally we should be able to early bail out if we kept a
|
2456
|
+
// ref count of pending chunks.
|
2457
|
+
reportGlobalError(response, new Error('Connection closed.'));
|
947
2458
|
}
|
948
2459
|
|
949
2460
|
function noServerCall() {
|
@@ -951,17 +2462,14 @@ function noServerCall() {
|
|
951
2462
|
}
|
952
2463
|
|
953
2464
|
function createServerReference(id, callServer) {
|
954
|
-
return noServerCall;
|
2465
|
+
return createServerReference$1(id, noServerCall);
|
955
2466
|
}
|
956
2467
|
|
957
|
-
function createFromNodeStream(stream,
|
958
|
-
var response = createResponse(moduleMap, noServerCall
|
2468
|
+
function createFromNodeStream(stream, ssrManifest, options) {
|
2469
|
+
var response = createResponse(ssrManifest.moduleMap, ssrManifest.moduleLoading, noServerCall, options ? options.encodeFormAction : undefined, options && typeof options.nonce === 'string' ? options.nonce : undefined, undefined // TODO: If encodeReply is supported, this should support temporaryReferences
|
2470
|
+
);
|
959
2471
|
stream.on('data', function (chunk) {
|
960
|
-
|
961
|
-
processStringChunk(response, chunk, 0);
|
962
|
-
} else {
|
963
|
-
processBinaryChunk(response, chunk);
|
964
|
-
}
|
2472
|
+
processBinaryChunk(response, chunk);
|
965
2473
|
});
|
966
2474
|
stream.on('error', function (error) {
|
967
2475
|
reportGlobalError(response, error);
|