react-server-dom-webpack 18.3.0-next-fa4314841-20230502 → 19.0.0-beta-4508873393-20240430
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 +1893 -1200
- package/cjs/react-server-dom-webpack-client.browser.production.js +931 -0
- package/cjs/react-server-dom-webpack-client.edge.development.js +1888 -241
- package/cjs/react-server-dom-webpack-client.edge.production.js +1093 -0
- package/cjs/react-server-dom-webpack-client.node.development.js +1876 -259
- package/cjs/react-server-dom-webpack-client.node.production.js +1070 -0
- package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +1833 -212
- package/cjs/react-server-dom-webpack-client.node.unbundled.production.js +1049 -0
- package/cjs/react-server-dom-webpack-node-register.js +59 -10
- package/cjs/react-server-dom-webpack-plugin.js +389 -11
- package/cjs/react-server-dom-webpack-server.browser.development.js +2187 -937
- package/cjs/react-server-dom-webpack-server.browser.production.js +1935 -0
- package/cjs/react-server-dom-webpack-server.edge.development.js +2183 -941
- package/cjs/react-server-dom-webpack-server.edge.production.js +1956 -0
- package/cjs/react-server-dom-webpack-server.node.development.js +2169 -929
- package/cjs/react-server-dom-webpack-server.node.production.js +2083 -0
- package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +2116 -881
- package/cjs/react-server-dom-webpack-server.node.unbundled.production.js +2051 -0
- package/client.browser.js +1 -1
- package/client.edge.js +1 -1
- package/client.node.js +1 -1
- package/client.node.unbundled.js +1 -1
- package/esm/{react-server-dom-webpack-node-loader.production.min.js → react-server-dom-webpack-node-loader.production.js} +20 -13
- package/package.json +8 -15
- package/server.browser.js +1 -1
- package/server.edge.js +1 -1
- package/server.node.js +1 -1
- package/server.node.unbundled.js +1 -1
- package/cjs/react-server-dom-webpack-client.browser.production.min.js +0 -34
- package/cjs/react-server-dom-webpack-client.edge.production.min.js +0 -28
- package/cjs/react-server-dom-webpack-client.node.production.min.js +0 -28
- package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +0 -26
- package/cjs/react-server-dom-webpack-server.browser.production.min.js +0 -62
- package/cjs/react-server-dom-webpack-server.edge.production.min.js +0 -62
- package/cjs/react-server-dom-webpack-server.node.production.min.js +0 -67
- package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +0 -65
- package/umd/react-server-dom-webpack-client.browser.development.js +0 -1731
- package/umd/react-server-dom-webpack-client.browser.production.min.js +0 -29
- package/umd/react-server-dom-webpack-server.browser.development.js +0 -2904
- package/umd/react-server-dom-webpack-server.browser.production.min.js +0 -51
@@ -1,1731 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license React
|
3
|
-
* react-server-dom-webpack-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
|
-
(function (global, factory) {
|
11
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react-dom'), require('react')) :
|
12
|
-
typeof define === 'function' && define.amd ? define(['exports', 'react-dom', 'react'], factory) :
|
13
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactServerDOMClient = {}, global.ReactDOM, global.React));
|
14
|
-
})(this, (function (exports, ReactDOM, React) { 'use strict';
|
15
|
-
|
16
|
-
function createStringDecoder() {
|
17
|
-
return new TextDecoder();
|
18
|
-
}
|
19
|
-
var decoderOptions = {
|
20
|
-
stream: true
|
21
|
-
};
|
22
|
-
function readPartialStringChunk(decoder, buffer) {
|
23
|
-
return decoder.decode(buffer, decoderOptions);
|
24
|
-
}
|
25
|
-
function readFinalStringChunk(decoder, buffer) {
|
26
|
-
return decoder.decode(buffer);
|
27
|
-
}
|
28
|
-
|
29
|
-
function parseModel(response, json) {
|
30
|
-
return JSON.parse(json, response._fromJSON);
|
31
|
-
}
|
32
|
-
|
33
|
-
// eslint-disable-next-line no-unused-vars
|
34
|
-
function resolveClientReference(bundlerConfig, metadata) {
|
35
|
-
if (bundlerConfig) {
|
36
|
-
var moduleExports = bundlerConfig[metadata.id];
|
37
|
-
var resolvedModuleData = moduleExports[metadata.name];
|
38
|
-
var name;
|
39
|
-
|
40
|
-
if (resolvedModuleData) {
|
41
|
-
// The potentially aliased name.
|
42
|
-
name = resolvedModuleData.name;
|
43
|
-
} else {
|
44
|
-
// If we don't have this specific name, we might have the full module.
|
45
|
-
resolvedModuleData = moduleExports['*'];
|
46
|
-
|
47
|
-
if (!resolvedModuleData) {
|
48
|
-
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.');
|
49
|
-
}
|
50
|
-
|
51
|
-
name = metadata.name;
|
52
|
-
}
|
53
|
-
|
54
|
-
return {
|
55
|
-
id: resolvedModuleData.id,
|
56
|
-
chunks: resolvedModuleData.chunks,
|
57
|
-
name: name,
|
58
|
-
async: !!metadata.async
|
59
|
-
};
|
60
|
-
}
|
61
|
-
|
62
|
-
return metadata;
|
63
|
-
}
|
64
|
-
// If they're still pending they're a thenable. This map also exists
|
65
|
-
// in Webpack but unfortunately it's not exposed so we have to
|
66
|
-
// replicate it in user space. null means that it has already loaded.
|
67
|
-
|
68
|
-
var chunkCache = new Map();
|
69
|
-
var asyncModuleCache = new Map();
|
70
|
-
|
71
|
-
function ignoreReject() {// We rely on rejected promises to be handled by another listener.
|
72
|
-
} // Start preloading the modules since we might need them soon.
|
73
|
-
// This function doesn't suspend.
|
74
|
-
|
75
|
-
|
76
|
-
function preloadModule(metadata) {
|
77
|
-
var chunks = metadata.chunks;
|
78
|
-
var promises = [];
|
79
|
-
|
80
|
-
for (var i = 0; i < chunks.length; i++) {
|
81
|
-
var chunkId = chunks[i];
|
82
|
-
var entry = chunkCache.get(chunkId);
|
83
|
-
|
84
|
-
if (entry === undefined) {
|
85
|
-
var thenable = __webpack_chunk_load__(chunkId);
|
86
|
-
|
87
|
-
promises.push(thenable); // $FlowFixMe[method-unbinding]
|
88
|
-
|
89
|
-
var resolve = chunkCache.set.bind(chunkCache, chunkId, null);
|
90
|
-
thenable.then(resolve, ignoreReject);
|
91
|
-
chunkCache.set(chunkId, thenable);
|
92
|
-
} else if (entry !== null) {
|
93
|
-
promises.push(entry);
|
94
|
-
}
|
95
|
-
}
|
96
|
-
|
97
|
-
if (metadata.async) {
|
98
|
-
var existingPromise = asyncModuleCache.get(metadata.id);
|
99
|
-
|
100
|
-
if (existingPromise) {
|
101
|
-
if (existingPromise.status === 'fulfilled') {
|
102
|
-
return null;
|
103
|
-
}
|
104
|
-
|
105
|
-
return existingPromise;
|
106
|
-
} else {
|
107
|
-
var modulePromise = Promise.all(promises).then(function () {
|
108
|
-
return __webpack_require__(metadata.id);
|
109
|
-
});
|
110
|
-
modulePromise.then(function (value) {
|
111
|
-
var fulfilledThenable = modulePromise;
|
112
|
-
fulfilledThenable.status = 'fulfilled';
|
113
|
-
fulfilledThenable.value = value;
|
114
|
-
}, function (reason) {
|
115
|
-
var rejectedThenable = modulePromise;
|
116
|
-
rejectedThenable.status = 'rejected';
|
117
|
-
rejectedThenable.reason = reason;
|
118
|
-
});
|
119
|
-
asyncModuleCache.set(metadata.id, modulePromise);
|
120
|
-
return modulePromise;
|
121
|
-
}
|
122
|
-
} else if (promises.length > 0) {
|
123
|
-
return Promise.all(promises);
|
124
|
-
} else {
|
125
|
-
return null;
|
126
|
-
}
|
127
|
-
} // Actually require the module or suspend if it's not yet ready.
|
128
|
-
// Increase priority if necessary.
|
129
|
-
|
130
|
-
function requireModule(metadata) {
|
131
|
-
var moduleExports;
|
132
|
-
|
133
|
-
if (metadata.async) {
|
134
|
-
// We assume that preloadModule has been called before, which
|
135
|
-
// should have added something to the module cache.
|
136
|
-
var promise = asyncModuleCache.get(metadata.id);
|
137
|
-
|
138
|
-
if (promise.status === 'fulfilled') {
|
139
|
-
moduleExports = promise.value;
|
140
|
-
} else {
|
141
|
-
throw promise.reason;
|
142
|
-
}
|
143
|
-
} else {
|
144
|
-
moduleExports = __webpack_require__(metadata.id);
|
145
|
-
}
|
146
|
-
|
147
|
-
if (metadata.name === '*') {
|
148
|
-
// This is a placeholder value that represents that the caller imported this
|
149
|
-
// as a CommonJS module as is.
|
150
|
-
return moduleExports;
|
151
|
-
}
|
152
|
-
|
153
|
-
if (metadata.name === '') {
|
154
|
-
// This is a placeholder value that represents that the caller accessed the
|
155
|
-
// default property of this if it was an ESM interop module.
|
156
|
-
return moduleExports.__esModule ? moduleExports.default : moduleExports;
|
157
|
-
}
|
158
|
-
|
159
|
-
return moduleExports[metadata.name];
|
160
|
-
}
|
161
|
-
|
162
|
-
var ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
163
|
-
|
164
|
-
// This client file is in the shared folder because it applies to both SSR and browser contexts.
|
165
|
-
var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.Dispatcher;
|
166
|
-
function dispatchHint(code, model) {
|
167
|
-
var dispatcher = ReactDOMCurrentDispatcher.current;
|
168
|
-
|
169
|
-
if (dispatcher) {
|
170
|
-
var href, options;
|
171
|
-
|
172
|
-
if (typeof model === 'string') {
|
173
|
-
href = model;
|
174
|
-
} else {
|
175
|
-
href = model[0];
|
176
|
-
options = model[1];
|
177
|
-
}
|
178
|
-
|
179
|
-
switch (code) {
|
180
|
-
case 'D':
|
181
|
-
{
|
182
|
-
// $FlowFixMe[prop-missing] options are not refined to their types by code
|
183
|
-
dispatcher.prefetchDNS(href, options);
|
184
|
-
return;
|
185
|
-
}
|
186
|
-
|
187
|
-
case 'C':
|
188
|
-
{
|
189
|
-
// $FlowFixMe[prop-missing] options are not refined to their types by code
|
190
|
-
dispatcher.preconnect(href, options);
|
191
|
-
return;
|
192
|
-
}
|
193
|
-
|
194
|
-
case 'L':
|
195
|
-
{
|
196
|
-
// $FlowFixMe[prop-missing] options are not refined to their types by code
|
197
|
-
// $FlowFixMe[incompatible-call] options are not refined to their types by code
|
198
|
-
dispatcher.preload(href, options);
|
199
|
-
return;
|
200
|
-
}
|
201
|
-
|
202
|
-
case 'I':
|
203
|
-
{
|
204
|
-
// $FlowFixMe[prop-missing] options are not refined to their types by code
|
205
|
-
// $FlowFixMe[incompatible-call] options are not refined to their types by code
|
206
|
-
dispatcher.preinit(href, options);
|
207
|
-
return;
|
208
|
-
}
|
209
|
-
}
|
210
|
-
}
|
211
|
-
}
|
212
|
-
|
213
|
-
var knownServerReferences = new WeakMap();
|
214
|
-
function createServerReference(id, callServer) {
|
215
|
-
var proxy = function () {
|
216
|
-
// $FlowFixMe[method-unbinding]
|
217
|
-
var args = Array.prototype.slice.call(arguments);
|
218
|
-
return callServer(id, args);
|
219
|
-
};
|
220
|
-
|
221
|
-
knownServerReferences.set(proxy, {
|
222
|
-
id: id,
|
223
|
-
bound: null
|
224
|
-
});
|
225
|
-
return proxy;
|
226
|
-
}
|
227
|
-
|
228
|
-
// ATTENTION
|
229
|
-
// When adding new symbols to this file,
|
230
|
-
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
|
231
|
-
// The Symbol used to tag the ReactElement-like types.
|
232
|
-
var REACT_ELEMENT_TYPE = Symbol.for('react.element');
|
233
|
-
var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
|
234
|
-
var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
|
235
|
-
var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
|
236
|
-
var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
|
237
|
-
var REACT_MEMO_TYPE = Symbol.for('react.memo');
|
238
|
-
var REACT_LAZY_TYPE = Symbol.for('react.lazy');
|
239
|
-
var REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for('react.default_value');
|
240
|
-
var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
|
241
|
-
var FAUX_ITERATOR_SYMBOL = '@@iterator';
|
242
|
-
function getIteratorFn(maybeIterable) {
|
243
|
-
if (maybeIterable === null || typeof maybeIterable !== 'object') {
|
244
|
-
return null;
|
245
|
-
}
|
246
|
-
|
247
|
-
var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
|
248
|
-
|
249
|
-
if (typeof maybeIterator === 'function') {
|
250
|
-
return maybeIterator;
|
251
|
-
}
|
252
|
-
|
253
|
-
return null;
|
254
|
-
}
|
255
|
-
|
256
|
-
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
257
|
-
|
258
|
-
var ContextRegistry = ReactSharedInternals.ContextRegistry;
|
259
|
-
function getOrCreateServerContext(globalName) {
|
260
|
-
if (!ContextRegistry[globalName]) {
|
261
|
-
ContextRegistry[globalName] = React.createServerContext(globalName, // $FlowFixMe[incompatible-call] function signature doesn't reflect the symbol value
|
262
|
-
REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
|
263
|
-
}
|
264
|
-
|
265
|
-
return ContextRegistry[globalName];
|
266
|
-
}
|
267
|
-
|
268
|
-
var PENDING = 'pending';
|
269
|
-
var BLOCKED = 'blocked';
|
270
|
-
var RESOLVED_MODEL = 'resolved_model';
|
271
|
-
var RESOLVED_MODULE = 'resolved_module';
|
272
|
-
var INITIALIZED = 'fulfilled';
|
273
|
-
var ERRORED = 'rejected'; // $FlowFixMe[missing-this-annot]
|
274
|
-
|
275
|
-
function Chunk(status, value, reason, response) {
|
276
|
-
this.status = status;
|
277
|
-
this.value = value;
|
278
|
-
this.reason = reason;
|
279
|
-
this._response = response;
|
280
|
-
} // We subclass Promise.prototype so that we get other methods like .catch
|
281
|
-
|
282
|
-
|
283
|
-
Chunk.prototype = Object.create(Promise.prototype); // TODO: This doesn't return a new Promise chain unlike the real .then
|
284
|
-
|
285
|
-
Chunk.prototype.then = function (resolve, reject) {
|
286
|
-
var chunk = this; // If we have resolved content, we try to initialize it first which
|
287
|
-
// might put us back into one of the other states.
|
288
|
-
|
289
|
-
switch (chunk.status) {
|
290
|
-
case RESOLVED_MODEL:
|
291
|
-
initializeModelChunk(chunk);
|
292
|
-
break;
|
293
|
-
|
294
|
-
case RESOLVED_MODULE:
|
295
|
-
initializeModuleChunk(chunk);
|
296
|
-
break;
|
297
|
-
} // The status might have changed after initialization.
|
298
|
-
|
299
|
-
|
300
|
-
switch (chunk.status) {
|
301
|
-
case INITIALIZED:
|
302
|
-
resolve(chunk.value);
|
303
|
-
break;
|
304
|
-
|
305
|
-
case PENDING:
|
306
|
-
case BLOCKED:
|
307
|
-
if (resolve) {
|
308
|
-
if (chunk.value === null) {
|
309
|
-
chunk.value = [];
|
310
|
-
}
|
311
|
-
|
312
|
-
chunk.value.push(resolve);
|
313
|
-
}
|
314
|
-
|
315
|
-
if (reject) {
|
316
|
-
if (chunk.reason === null) {
|
317
|
-
chunk.reason = [];
|
318
|
-
}
|
319
|
-
|
320
|
-
chunk.reason.push(reject);
|
321
|
-
}
|
322
|
-
|
323
|
-
break;
|
324
|
-
|
325
|
-
default:
|
326
|
-
reject(chunk.reason);
|
327
|
-
break;
|
328
|
-
}
|
329
|
-
};
|
330
|
-
|
331
|
-
function readChunk(chunk) {
|
332
|
-
// If we have resolved content, we try to initialize it first which
|
333
|
-
// might put us back into one of the other states.
|
334
|
-
switch (chunk.status) {
|
335
|
-
case RESOLVED_MODEL:
|
336
|
-
initializeModelChunk(chunk);
|
337
|
-
break;
|
338
|
-
|
339
|
-
case RESOLVED_MODULE:
|
340
|
-
initializeModuleChunk(chunk);
|
341
|
-
break;
|
342
|
-
} // The status might have changed after initialization.
|
343
|
-
|
344
|
-
|
345
|
-
switch (chunk.status) {
|
346
|
-
case INITIALIZED:
|
347
|
-
return chunk.value;
|
348
|
-
|
349
|
-
case PENDING:
|
350
|
-
case BLOCKED:
|
351
|
-
// eslint-disable-next-line no-throw-literal
|
352
|
-
throw chunk;
|
353
|
-
|
354
|
-
default:
|
355
|
-
throw chunk.reason;
|
356
|
-
}
|
357
|
-
}
|
358
|
-
|
359
|
-
function getRoot(response) {
|
360
|
-
var chunk = getChunk(response, 0);
|
361
|
-
return chunk;
|
362
|
-
}
|
363
|
-
|
364
|
-
function createPendingChunk(response) {
|
365
|
-
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
366
|
-
return new Chunk(PENDING, null, null, response);
|
367
|
-
}
|
368
|
-
|
369
|
-
function createBlockedChunk(response) {
|
370
|
-
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
371
|
-
return new Chunk(BLOCKED, null, null, response);
|
372
|
-
}
|
373
|
-
|
374
|
-
function createErrorChunk(response, error) {
|
375
|
-
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
376
|
-
return new Chunk(ERRORED, null, error, response);
|
377
|
-
}
|
378
|
-
|
379
|
-
function wakeChunk(listeners, value) {
|
380
|
-
for (var i = 0; i < listeners.length; i++) {
|
381
|
-
var listener = listeners[i];
|
382
|
-
listener(value);
|
383
|
-
}
|
384
|
-
}
|
385
|
-
|
386
|
-
function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
|
387
|
-
switch (chunk.status) {
|
388
|
-
case INITIALIZED:
|
389
|
-
wakeChunk(resolveListeners, chunk.value);
|
390
|
-
break;
|
391
|
-
|
392
|
-
case PENDING:
|
393
|
-
case BLOCKED:
|
394
|
-
chunk.value = resolveListeners;
|
395
|
-
chunk.reason = rejectListeners;
|
396
|
-
break;
|
397
|
-
|
398
|
-
case ERRORED:
|
399
|
-
if (rejectListeners) {
|
400
|
-
wakeChunk(rejectListeners, chunk.reason);
|
401
|
-
}
|
402
|
-
|
403
|
-
break;
|
404
|
-
}
|
405
|
-
}
|
406
|
-
|
407
|
-
function triggerErrorOnChunk(chunk, error) {
|
408
|
-
if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
|
409
|
-
// We already resolved. We didn't expect to see this.
|
410
|
-
return;
|
411
|
-
}
|
412
|
-
|
413
|
-
var listeners = chunk.reason;
|
414
|
-
var erroredChunk = chunk;
|
415
|
-
erroredChunk.status = ERRORED;
|
416
|
-
erroredChunk.reason = error;
|
417
|
-
|
418
|
-
if (listeners !== null) {
|
419
|
-
wakeChunk(listeners, error);
|
420
|
-
}
|
421
|
-
}
|
422
|
-
|
423
|
-
function createResolvedModelChunk(response, value) {
|
424
|
-
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
425
|
-
return new Chunk(RESOLVED_MODEL, value, null, response);
|
426
|
-
}
|
427
|
-
|
428
|
-
function createResolvedModuleChunk(response, value) {
|
429
|
-
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
430
|
-
return new Chunk(RESOLVED_MODULE, value, null, response);
|
431
|
-
}
|
432
|
-
|
433
|
-
function resolveModelChunk(chunk, value) {
|
434
|
-
if (chunk.status !== PENDING) {
|
435
|
-
// We already resolved. We didn't expect to see this.
|
436
|
-
return;
|
437
|
-
}
|
438
|
-
|
439
|
-
var resolveListeners = chunk.value;
|
440
|
-
var rejectListeners = chunk.reason;
|
441
|
-
var resolvedChunk = chunk;
|
442
|
-
resolvedChunk.status = RESOLVED_MODEL;
|
443
|
-
resolvedChunk.value = value;
|
444
|
-
|
445
|
-
if (resolveListeners !== null) {
|
446
|
-
// This is unfortunate that we're reading this eagerly if
|
447
|
-
// we already have listeners attached since they might no
|
448
|
-
// longer be rendered or might not be the highest pri.
|
449
|
-
initializeModelChunk(resolvedChunk); // The status might have changed after initialization.
|
450
|
-
|
451
|
-
wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
|
452
|
-
}
|
453
|
-
}
|
454
|
-
|
455
|
-
function resolveModuleChunk(chunk, value) {
|
456
|
-
if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
|
457
|
-
// We already resolved. We didn't expect to see this.
|
458
|
-
return;
|
459
|
-
}
|
460
|
-
|
461
|
-
var resolveListeners = chunk.value;
|
462
|
-
var rejectListeners = chunk.reason;
|
463
|
-
var resolvedChunk = chunk;
|
464
|
-
resolvedChunk.status = RESOLVED_MODULE;
|
465
|
-
resolvedChunk.value = value;
|
466
|
-
|
467
|
-
if (resolveListeners !== null) {
|
468
|
-
initializeModuleChunk(resolvedChunk);
|
469
|
-
wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
|
470
|
-
}
|
471
|
-
}
|
472
|
-
|
473
|
-
var initializingChunk = null;
|
474
|
-
var initializingChunkBlockedModel = null;
|
475
|
-
|
476
|
-
function initializeModelChunk(chunk) {
|
477
|
-
var prevChunk = initializingChunk;
|
478
|
-
var prevBlocked = initializingChunkBlockedModel;
|
479
|
-
initializingChunk = chunk;
|
480
|
-
initializingChunkBlockedModel = null;
|
481
|
-
|
482
|
-
try {
|
483
|
-
var value = parseModel(chunk._response, chunk.value);
|
484
|
-
|
485
|
-
if (initializingChunkBlockedModel !== null && initializingChunkBlockedModel.deps > 0) {
|
486
|
-
initializingChunkBlockedModel.value = value; // We discovered new dependencies on modules that are not yet resolved.
|
487
|
-
// We have to go the BLOCKED state until they're resolved.
|
488
|
-
|
489
|
-
var blockedChunk = chunk;
|
490
|
-
blockedChunk.status = BLOCKED;
|
491
|
-
blockedChunk.value = null;
|
492
|
-
blockedChunk.reason = null;
|
493
|
-
} else {
|
494
|
-
var initializedChunk = chunk;
|
495
|
-
initializedChunk.status = INITIALIZED;
|
496
|
-
initializedChunk.value = value;
|
497
|
-
}
|
498
|
-
} catch (error) {
|
499
|
-
var erroredChunk = chunk;
|
500
|
-
erroredChunk.status = ERRORED;
|
501
|
-
erroredChunk.reason = error;
|
502
|
-
} finally {
|
503
|
-
initializingChunk = prevChunk;
|
504
|
-
initializingChunkBlockedModel = prevBlocked;
|
505
|
-
}
|
506
|
-
}
|
507
|
-
|
508
|
-
function initializeModuleChunk(chunk) {
|
509
|
-
try {
|
510
|
-
var value = requireModule(chunk.value);
|
511
|
-
var initializedChunk = chunk;
|
512
|
-
initializedChunk.status = INITIALIZED;
|
513
|
-
initializedChunk.value = value;
|
514
|
-
} catch (error) {
|
515
|
-
var erroredChunk = chunk;
|
516
|
-
erroredChunk.status = ERRORED;
|
517
|
-
erroredChunk.reason = error;
|
518
|
-
}
|
519
|
-
} // Report that any missing chunks in the model is now going to throw this
|
520
|
-
// error upon read. Also notify any pending promises.
|
521
|
-
|
522
|
-
|
523
|
-
function reportGlobalError(response, error) {
|
524
|
-
response._chunks.forEach(function (chunk) {
|
525
|
-
// If this chunk was already resolved or errored, it won't
|
526
|
-
// trigger an error but if it wasn't then we need to
|
527
|
-
// because we won't be getting any new data to resolve it.
|
528
|
-
if (chunk.status === PENDING) {
|
529
|
-
triggerErrorOnChunk(chunk, error);
|
530
|
-
}
|
531
|
-
});
|
532
|
-
}
|
533
|
-
|
534
|
-
function createElement(type, key, props) {
|
535
|
-
var element = {
|
536
|
-
// This tag allows us to uniquely identify this as a React Element
|
537
|
-
$$typeof: REACT_ELEMENT_TYPE,
|
538
|
-
// Built-in properties that belong on the element
|
539
|
-
type: type,
|
540
|
-
key: key,
|
541
|
-
ref: null,
|
542
|
-
props: props,
|
543
|
-
// Record the component responsible for creating this element.
|
544
|
-
_owner: null
|
545
|
-
};
|
546
|
-
|
547
|
-
{
|
548
|
-
// We don't really need to add any of these but keeping them for good measure.
|
549
|
-
// Unfortunately, _store is enumerable in jest matchers so for equality to
|
550
|
-
// work, I need to keep it or make _store non-enumerable in the other file.
|
551
|
-
element._store = {};
|
552
|
-
Object.defineProperty(element._store, 'validated', {
|
553
|
-
configurable: false,
|
554
|
-
enumerable: false,
|
555
|
-
writable: true,
|
556
|
-
value: true // This element has already been validated on the server.
|
557
|
-
|
558
|
-
});
|
559
|
-
Object.defineProperty(element, '_self', {
|
560
|
-
configurable: false,
|
561
|
-
enumerable: false,
|
562
|
-
writable: false,
|
563
|
-
value: null
|
564
|
-
});
|
565
|
-
Object.defineProperty(element, '_source', {
|
566
|
-
configurable: false,
|
567
|
-
enumerable: false,
|
568
|
-
writable: false,
|
569
|
-
value: null
|
570
|
-
});
|
571
|
-
}
|
572
|
-
|
573
|
-
return element;
|
574
|
-
}
|
575
|
-
|
576
|
-
function createLazyChunkWrapper(chunk) {
|
577
|
-
var lazyType = {
|
578
|
-
$$typeof: REACT_LAZY_TYPE,
|
579
|
-
_payload: chunk,
|
580
|
-
_init: readChunk
|
581
|
-
};
|
582
|
-
return lazyType;
|
583
|
-
}
|
584
|
-
|
585
|
-
function getChunk(response, id) {
|
586
|
-
var chunks = response._chunks;
|
587
|
-
var chunk = chunks.get(id);
|
588
|
-
|
589
|
-
if (!chunk) {
|
590
|
-
chunk = createPendingChunk(response);
|
591
|
-
chunks.set(id, chunk);
|
592
|
-
}
|
593
|
-
|
594
|
-
return chunk;
|
595
|
-
}
|
596
|
-
|
597
|
-
function createModelResolver(chunk, parentObject, key) {
|
598
|
-
var blocked;
|
599
|
-
|
600
|
-
if (initializingChunkBlockedModel) {
|
601
|
-
blocked = initializingChunkBlockedModel;
|
602
|
-
blocked.deps++;
|
603
|
-
} else {
|
604
|
-
blocked = initializingChunkBlockedModel = {
|
605
|
-
deps: 1,
|
606
|
-
value: null
|
607
|
-
};
|
608
|
-
}
|
609
|
-
|
610
|
-
return function (value) {
|
611
|
-
parentObject[key] = value;
|
612
|
-
blocked.deps--;
|
613
|
-
|
614
|
-
if (blocked.deps === 0) {
|
615
|
-
if (chunk.status !== BLOCKED) {
|
616
|
-
return;
|
617
|
-
}
|
618
|
-
|
619
|
-
var resolveListeners = chunk.value;
|
620
|
-
var initializedChunk = chunk;
|
621
|
-
initializedChunk.status = INITIALIZED;
|
622
|
-
initializedChunk.value = blocked.value;
|
623
|
-
|
624
|
-
if (resolveListeners !== null) {
|
625
|
-
wakeChunk(resolveListeners, blocked.value);
|
626
|
-
}
|
627
|
-
}
|
628
|
-
};
|
629
|
-
}
|
630
|
-
|
631
|
-
function createModelReject(chunk) {
|
632
|
-
return function (error) {
|
633
|
-
return triggerErrorOnChunk(chunk, error);
|
634
|
-
};
|
635
|
-
}
|
636
|
-
|
637
|
-
function createServerReferenceProxy(response, metaData) {
|
638
|
-
var callServer = response._callServer;
|
639
|
-
|
640
|
-
var proxy = function () {
|
641
|
-
// $FlowFixMe[method-unbinding]
|
642
|
-
var args = Array.prototype.slice.call(arguments);
|
643
|
-
var p = metaData.bound;
|
644
|
-
|
645
|
-
if (!p) {
|
646
|
-
return callServer(metaData.id, args);
|
647
|
-
}
|
648
|
-
|
649
|
-
if (p.status === INITIALIZED) {
|
650
|
-
var bound = p.value;
|
651
|
-
return callServer(metaData.id, bound.concat(args));
|
652
|
-
} // Since this is a fake Promise whose .then doesn't chain, we have to wrap it.
|
653
|
-
// TODO: Remove the wrapper once that's fixed.
|
654
|
-
|
655
|
-
|
656
|
-
return Promise.resolve(p).then(function (bound) {
|
657
|
-
return callServer(metaData.id, bound.concat(args));
|
658
|
-
});
|
659
|
-
};
|
660
|
-
|
661
|
-
knownServerReferences.set(proxy, metaData);
|
662
|
-
return proxy;
|
663
|
-
}
|
664
|
-
|
665
|
-
function parseModelString(response, parentObject, key, value) {
|
666
|
-
if (value[0] === '$') {
|
667
|
-
if (value === '$') {
|
668
|
-
// A very common symbol.
|
669
|
-
return REACT_ELEMENT_TYPE;
|
670
|
-
}
|
671
|
-
|
672
|
-
switch (value[1]) {
|
673
|
-
case '$':
|
674
|
-
{
|
675
|
-
// This was an escaped string value.
|
676
|
-
return value.slice(1);
|
677
|
-
}
|
678
|
-
|
679
|
-
case 'L':
|
680
|
-
{
|
681
|
-
// Lazy node
|
682
|
-
var id = parseInt(value.slice(2), 16);
|
683
|
-
var chunk = getChunk(response, id); // We create a React.lazy wrapper around any lazy values.
|
684
|
-
// When passed into React, we'll know how to suspend on this.
|
685
|
-
|
686
|
-
return createLazyChunkWrapper(chunk);
|
687
|
-
}
|
688
|
-
|
689
|
-
case '@':
|
690
|
-
{
|
691
|
-
// Promise
|
692
|
-
var _id = parseInt(value.slice(2), 16);
|
693
|
-
|
694
|
-
var _chunk = getChunk(response, _id);
|
695
|
-
|
696
|
-
return _chunk;
|
697
|
-
}
|
698
|
-
|
699
|
-
case 'S':
|
700
|
-
{
|
701
|
-
// Symbol
|
702
|
-
return Symbol.for(value.slice(2));
|
703
|
-
}
|
704
|
-
|
705
|
-
case 'P':
|
706
|
-
{
|
707
|
-
// Server Context Provider
|
708
|
-
return getOrCreateServerContext(value.slice(2)).Provider;
|
709
|
-
}
|
710
|
-
|
711
|
-
case 'F':
|
712
|
-
{
|
713
|
-
// Server Reference
|
714
|
-
var _id2 = parseInt(value.slice(2), 16);
|
715
|
-
|
716
|
-
var _chunk2 = getChunk(response, _id2);
|
717
|
-
|
718
|
-
switch (_chunk2.status) {
|
719
|
-
case RESOLVED_MODEL:
|
720
|
-
initializeModelChunk(_chunk2);
|
721
|
-
break;
|
722
|
-
} // The status might have changed after initialization.
|
723
|
-
|
724
|
-
|
725
|
-
switch (_chunk2.status) {
|
726
|
-
case INITIALIZED:
|
727
|
-
{
|
728
|
-
var metadata = _chunk2.value;
|
729
|
-
return createServerReferenceProxy(response, metadata);
|
730
|
-
}
|
731
|
-
// We always encode it first in the stream so it won't be pending.
|
732
|
-
|
733
|
-
default:
|
734
|
-
throw _chunk2.reason;
|
735
|
-
}
|
736
|
-
}
|
737
|
-
|
738
|
-
case 'I':
|
739
|
-
{
|
740
|
-
// $Infinity
|
741
|
-
return Infinity;
|
742
|
-
}
|
743
|
-
|
744
|
-
case '-':
|
745
|
-
{
|
746
|
-
// $-0 or $-Infinity
|
747
|
-
if (value === '$-0') {
|
748
|
-
return -0;
|
749
|
-
} else {
|
750
|
-
return -Infinity;
|
751
|
-
}
|
752
|
-
}
|
753
|
-
|
754
|
-
case 'N':
|
755
|
-
{
|
756
|
-
// $NaN
|
757
|
-
return NaN;
|
758
|
-
}
|
759
|
-
|
760
|
-
case 'u':
|
761
|
-
{
|
762
|
-
// matches "$undefined"
|
763
|
-
// Special encoding for `undefined` which can't be serialized as JSON otherwise.
|
764
|
-
return undefined;
|
765
|
-
}
|
766
|
-
|
767
|
-
case 'D':
|
768
|
-
{
|
769
|
-
// Date
|
770
|
-
return new Date(Date.parse(value.slice(2)));
|
771
|
-
}
|
772
|
-
|
773
|
-
case 'n':
|
774
|
-
{
|
775
|
-
// BigInt
|
776
|
-
return BigInt(value.slice(2));
|
777
|
-
}
|
778
|
-
|
779
|
-
default:
|
780
|
-
{
|
781
|
-
// We assume that anything else is a reference ID.
|
782
|
-
var _id3 = parseInt(value.slice(1), 16);
|
783
|
-
|
784
|
-
var _chunk3 = getChunk(response, _id3);
|
785
|
-
|
786
|
-
switch (_chunk3.status) {
|
787
|
-
case RESOLVED_MODEL:
|
788
|
-
initializeModelChunk(_chunk3);
|
789
|
-
break;
|
790
|
-
|
791
|
-
case RESOLVED_MODULE:
|
792
|
-
initializeModuleChunk(_chunk3);
|
793
|
-
break;
|
794
|
-
} // The status might have changed after initialization.
|
795
|
-
|
796
|
-
|
797
|
-
switch (_chunk3.status) {
|
798
|
-
case INITIALIZED:
|
799
|
-
return _chunk3.value;
|
800
|
-
|
801
|
-
case PENDING:
|
802
|
-
case BLOCKED:
|
803
|
-
var parentChunk = initializingChunk;
|
804
|
-
|
805
|
-
_chunk3.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
|
806
|
-
|
807
|
-
return null;
|
808
|
-
|
809
|
-
default:
|
810
|
-
throw _chunk3.reason;
|
811
|
-
}
|
812
|
-
}
|
813
|
-
}
|
814
|
-
}
|
815
|
-
|
816
|
-
return value;
|
817
|
-
}
|
818
|
-
function parseModelTuple(response, value) {
|
819
|
-
var tuple = value;
|
820
|
-
|
821
|
-
if (tuple[0] === REACT_ELEMENT_TYPE) {
|
822
|
-
// TODO: Consider having React just directly accept these arrays as elements.
|
823
|
-
// Or even change the ReactElement type to be an array.
|
824
|
-
return createElement(tuple[1], tuple[2], tuple[3]);
|
825
|
-
}
|
826
|
-
|
827
|
-
return value;
|
828
|
-
}
|
829
|
-
|
830
|
-
function missingCall() {
|
831
|
-
throw new Error('Trying to call a function from "use server" but the callServer option ' + 'was not implemented in your router runtime.');
|
832
|
-
}
|
833
|
-
|
834
|
-
function createResponse$1(bundlerConfig, callServer) {
|
835
|
-
var chunks = new Map();
|
836
|
-
var response = {
|
837
|
-
_bundlerConfig: bundlerConfig,
|
838
|
-
_callServer: callServer !== undefined ? callServer : missingCall,
|
839
|
-
_chunks: chunks
|
840
|
-
};
|
841
|
-
return response;
|
842
|
-
}
|
843
|
-
function resolveModel(response, id, model) {
|
844
|
-
var chunks = response._chunks;
|
845
|
-
var chunk = chunks.get(id);
|
846
|
-
|
847
|
-
if (!chunk) {
|
848
|
-
chunks.set(id, createResolvedModelChunk(response, model));
|
849
|
-
} else {
|
850
|
-
resolveModelChunk(chunk, model);
|
851
|
-
}
|
852
|
-
}
|
853
|
-
function resolveModule(response, id, model) {
|
854
|
-
var chunks = response._chunks;
|
855
|
-
var chunk = chunks.get(id);
|
856
|
-
var clientReferenceMetadata = parseModel(response, model);
|
857
|
-
var clientReference = resolveClientReference(response._bundlerConfig, clientReferenceMetadata); // TODO: Add an option to encode modules that are lazy loaded.
|
858
|
-
// For now we preload all modules as early as possible since it's likely
|
859
|
-
// that we'll need them.
|
860
|
-
|
861
|
-
var promise = preloadModule(clientReference);
|
862
|
-
|
863
|
-
if (promise) {
|
864
|
-
var blockedChunk;
|
865
|
-
|
866
|
-
if (!chunk) {
|
867
|
-
// Technically, we should just treat promise as the chunk in this
|
868
|
-
// case. Because it'll just behave as any other promise.
|
869
|
-
blockedChunk = createBlockedChunk(response);
|
870
|
-
chunks.set(id, blockedChunk);
|
871
|
-
} else {
|
872
|
-
// This can't actually happen because we don't have any forward
|
873
|
-
// references to modules.
|
874
|
-
blockedChunk = chunk;
|
875
|
-
blockedChunk.status = BLOCKED;
|
876
|
-
}
|
877
|
-
|
878
|
-
promise.then(function () {
|
879
|
-
return resolveModuleChunk(blockedChunk, clientReference);
|
880
|
-
}, function (error) {
|
881
|
-
return triggerErrorOnChunk(blockedChunk, error);
|
882
|
-
});
|
883
|
-
} else {
|
884
|
-
if (!chunk) {
|
885
|
-
chunks.set(id, createResolvedModuleChunk(response, clientReference));
|
886
|
-
} else {
|
887
|
-
// This can't actually happen because we don't have any forward
|
888
|
-
// references to modules.
|
889
|
-
resolveModuleChunk(chunk, clientReference);
|
890
|
-
}
|
891
|
-
}
|
892
|
-
}
|
893
|
-
function resolveErrorDev(response, id, digest, message, stack) {
|
894
|
-
|
895
|
-
|
896
|
-
var error = new Error(message || 'An error occurred in the Server Components render but no message was provided');
|
897
|
-
error.stack = stack;
|
898
|
-
error.digest = digest;
|
899
|
-
var errorWithDigest = error;
|
900
|
-
var chunks = response._chunks;
|
901
|
-
var chunk = chunks.get(id);
|
902
|
-
|
903
|
-
if (!chunk) {
|
904
|
-
chunks.set(id, createErrorChunk(response, errorWithDigest));
|
905
|
-
} else {
|
906
|
-
triggerErrorOnChunk(chunk, errorWithDigest);
|
907
|
-
}
|
908
|
-
}
|
909
|
-
function resolveHint(response, code, model) {
|
910
|
-
var hintModel = parseModel(response, model);
|
911
|
-
dispatchHint(code, hintModel);
|
912
|
-
}
|
913
|
-
function close(response) {
|
914
|
-
// In case there are any remaining unresolved chunks, they won't
|
915
|
-
// be resolved now. So we need to issue an error to those.
|
916
|
-
// Ideally we should be able to early bail out if we kept a
|
917
|
-
// ref count of pending chunks.
|
918
|
-
reportGlobalError(response, new Error('Connection closed.'));
|
919
|
-
}
|
920
|
-
|
921
|
-
function processFullRow(response, row) {
|
922
|
-
if (row === '') {
|
923
|
-
return;
|
924
|
-
}
|
925
|
-
|
926
|
-
var colon = row.indexOf(':', 0);
|
927
|
-
var id = parseInt(row.slice(0, colon), 16);
|
928
|
-
var tag = row[colon + 1]; // When tags that are not text are added, check them here before
|
929
|
-
// parsing the row as text.
|
930
|
-
// switch (tag) {
|
931
|
-
// }
|
932
|
-
|
933
|
-
switch (tag) {
|
934
|
-
case 'I':
|
935
|
-
{
|
936
|
-
resolveModule(response, id, row.slice(colon + 2));
|
937
|
-
return;
|
938
|
-
}
|
939
|
-
|
940
|
-
case 'H':
|
941
|
-
{
|
942
|
-
var code = row[colon + 2];
|
943
|
-
resolveHint(response, code, row.slice(colon + 3));
|
944
|
-
return;
|
945
|
-
}
|
946
|
-
|
947
|
-
case 'E':
|
948
|
-
{
|
949
|
-
var errorInfo = JSON.parse(row.slice(colon + 2));
|
950
|
-
|
951
|
-
{
|
952
|
-
resolveErrorDev(response, id, errorInfo.digest, errorInfo.message, errorInfo.stack);
|
953
|
-
}
|
954
|
-
|
955
|
-
return;
|
956
|
-
}
|
957
|
-
|
958
|
-
default:
|
959
|
-
{
|
960
|
-
// We assume anything else is JSON.
|
961
|
-
resolveModel(response, id, row.slice(colon + 1));
|
962
|
-
return;
|
963
|
-
}
|
964
|
-
}
|
965
|
-
}
|
966
|
-
|
967
|
-
function processStringChunk(response, chunk, offset) {
|
968
|
-
var linebreak = chunk.indexOf('\n', offset);
|
969
|
-
|
970
|
-
while (linebreak > -1) {
|
971
|
-
var fullrow = response._partialRow + chunk.slice(offset, linebreak);
|
972
|
-
processFullRow(response, fullrow);
|
973
|
-
response._partialRow = '';
|
974
|
-
offset = linebreak + 1;
|
975
|
-
linebreak = chunk.indexOf('\n', offset);
|
976
|
-
}
|
977
|
-
|
978
|
-
response._partialRow += chunk.slice(offset);
|
979
|
-
}
|
980
|
-
function processBinaryChunk(response, chunk) {
|
981
|
-
|
982
|
-
var stringDecoder = response._stringDecoder;
|
983
|
-
var linebreak = chunk.indexOf(10); // newline
|
984
|
-
|
985
|
-
while (linebreak > -1) {
|
986
|
-
var fullrow = response._partialRow + readFinalStringChunk(stringDecoder, chunk.subarray(0, linebreak));
|
987
|
-
processFullRow(response, fullrow);
|
988
|
-
response._partialRow = '';
|
989
|
-
chunk = chunk.subarray(linebreak + 1);
|
990
|
-
linebreak = chunk.indexOf(10); // newline
|
991
|
-
}
|
992
|
-
|
993
|
-
response._partialRow += readPartialStringChunk(stringDecoder, chunk);
|
994
|
-
}
|
995
|
-
|
996
|
-
function createFromJSONCallback(response) {
|
997
|
-
// $FlowFixMe[missing-this-annot]
|
998
|
-
return function (key, value) {
|
999
|
-
if (typeof value === 'string') {
|
1000
|
-
// We can't use .bind here because we need the "this" value.
|
1001
|
-
return parseModelString(response, this, key, value);
|
1002
|
-
}
|
1003
|
-
|
1004
|
-
if (typeof value === 'object' && value !== null) {
|
1005
|
-
return parseModelTuple(response, value);
|
1006
|
-
}
|
1007
|
-
|
1008
|
-
return value;
|
1009
|
-
};
|
1010
|
-
}
|
1011
|
-
|
1012
|
-
function createResponse(bundlerConfig, callServer) {
|
1013
|
-
// NOTE: CHECK THE COMPILER OUTPUT EACH TIME YOU CHANGE THIS.
|
1014
|
-
// It should be inlined to one object literal but minor changes can break it.
|
1015
|
-
var stringDecoder = createStringDecoder() ;
|
1016
|
-
var response = createResponse$1(bundlerConfig, callServer);
|
1017
|
-
response._partialRow = '';
|
1018
|
-
|
1019
|
-
{
|
1020
|
-
response._stringDecoder = stringDecoder;
|
1021
|
-
} // Don't inline this call because it causes closure to outline the call above.
|
1022
|
-
|
1023
|
-
|
1024
|
-
response._fromJSON = createFromJSONCallback(response);
|
1025
|
-
return response;
|
1026
|
-
}
|
1027
|
-
|
1028
|
-
function error(format) {
|
1029
|
-
{
|
1030
|
-
{
|
1031
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
1032
|
-
args[_key2 - 1] = arguments[_key2];
|
1033
|
-
}
|
1034
|
-
|
1035
|
-
printWarning('error', format, args);
|
1036
|
-
}
|
1037
|
-
}
|
1038
|
-
}
|
1039
|
-
|
1040
|
-
function printWarning(level, format, args) {
|
1041
|
-
// When changing this logic, you might want to also
|
1042
|
-
// update consoleWithStackDev.www.js as well.
|
1043
|
-
{
|
1044
|
-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
1045
|
-
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
1046
|
-
|
1047
|
-
if (stack !== '') {
|
1048
|
-
format += '%s';
|
1049
|
-
args = args.concat([stack]);
|
1050
|
-
} // eslint-disable-next-line react-internal/safe-string-coercion
|
1051
|
-
|
1052
|
-
|
1053
|
-
var argsWithFormat = args.map(function (item) {
|
1054
|
-
return String(item);
|
1055
|
-
}); // Careful: RN currently depends on this prefix
|
1056
|
-
|
1057
|
-
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
1058
|
-
// breaks IE9: https://github.com/facebook/react/issues/13610
|
1059
|
-
// eslint-disable-next-line react-internal/no-production-logging
|
1060
|
-
|
1061
|
-
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
1062
|
-
}
|
1063
|
-
}
|
1064
|
-
|
1065
|
-
var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
|
1066
|
-
|
1067
|
-
function isArray(a) {
|
1068
|
-
return isArrayImpl(a);
|
1069
|
-
}
|
1070
|
-
|
1071
|
-
// in case they error.
|
1072
|
-
|
1073
|
-
var jsxPropsParents = new WeakMap();
|
1074
|
-
var jsxChildrenParents = new WeakMap();
|
1075
|
-
|
1076
|
-
function isObjectPrototype(object) {
|
1077
|
-
if (!object) {
|
1078
|
-
return false;
|
1079
|
-
}
|
1080
|
-
|
1081
|
-
var ObjectPrototype = Object.prototype;
|
1082
|
-
|
1083
|
-
if (object === ObjectPrototype) {
|
1084
|
-
return true;
|
1085
|
-
} // It might be an object from a different Realm which is
|
1086
|
-
// still just a plain simple object.
|
1087
|
-
|
1088
|
-
|
1089
|
-
if (Object.getPrototypeOf(object)) {
|
1090
|
-
return false;
|
1091
|
-
}
|
1092
|
-
|
1093
|
-
var names = Object.getOwnPropertyNames(object);
|
1094
|
-
|
1095
|
-
for (var i = 0; i < names.length; i++) {
|
1096
|
-
if (!(names[i] in ObjectPrototype)) {
|
1097
|
-
return false;
|
1098
|
-
}
|
1099
|
-
}
|
1100
|
-
|
1101
|
-
return true;
|
1102
|
-
}
|
1103
|
-
|
1104
|
-
function isSimpleObject(object) {
|
1105
|
-
if (!isObjectPrototype(Object.getPrototypeOf(object))) {
|
1106
|
-
return false;
|
1107
|
-
}
|
1108
|
-
|
1109
|
-
var names = Object.getOwnPropertyNames(object);
|
1110
|
-
|
1111
|
-
for (var i = 0; i < names.length; i++) {
|
1112
|
-
var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
|
1113
|
-
|
1114
|
-
if (!descriptor) {
|
1115
|
-
return false;
|
1116
|
-
}
|
1117
|
-
|
1118
|
-
if (!descriptor.enumerable) {
|
1119
|
-
if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
|
1120
|
-
// React adds key and ref getters to props objects to issue warnings.
|
1121
|
-
// Those getters will not be transferred to the client, but that's ok,
|
1122
|
-
// so we'll special case them.
|
1123
|
-
continue;
|
1124
|
-
}
|
1125
|
-
|
1126
|
-
return false;
|
1127
|
-
}
|
1128
|
-
}
|
1129
|
-
|
1130
|
-
return true;
|
1131
|
-
}
|
1132
|
-
function objectName(object) {
|
1133
|
-
// $FlowFixMe[method-unbinding]
|
1134
|
-
var name = Object.prototype.toString.call(object);
|
1135
|
-
return name.replace(/^\[object (.*)\]$/, function (m, p0) {
|
1136
|
-
return p0;
|
1137
|
-
});
|
1138
|
-
}
|
1139
|
-
|
1140
|
-
function describeKeyForErrorMessage(key) {
|
1141
|
-
var encodedKey = JSON.stringify(key);
|
1142
|
-
return '"' + key + '"' === encodedKey ? key : encodedKey;
|
1143
|
-
}
|
1144
|
-
|
1145
|
-
function describeValueForErrorMessage(value) {
|
1146
|
-
switch (typeof value) {
|
1147
|
-
case 'string':
|
1148
|
-
{
|
1149
|
-
return JSON.stringify(value.length <= 10 ? value : value.slice(0, 10) + '...');
|
1150
|
-
}
|
1151
|
-
|
1152
|
-
case 'object':
|
1153
|
-
{
|
1154
|
-
if (isArray(value)) {
|
1155
|
-
return '[...]';
|
1156
|
-
}
|
1157
|
-
|
1158
|
-
var name = objectName(value);
|
1159
|
-
|
1160
|
-
if (name === 'Object') {
|
1161
|
-
return '{...}';
|
1162
|
-
}
|
1163
|
-
|
1164
|
-
return name;
|
1165
|
-
}
|
1166
|
-
|
1167
|
-
case 'function':
|
1168
|
-
return 'function';
|
1169
|
-
|
1170
|
-
default:
|
1171
|
-
// eslint-disable-next-line react-internal/safe-string-coercion
|
1172
|
-
return String(value);
|
1173
|
-
}
|
1174
|
-
}
|
1175
|
-
|
1176
|
-
function describeElementType(type) {
|
1177
|
-
if (typeof type === 'string') {
|
1178
|
-
return type;
|
1179
|
-
}
|
1180
|
-
|
1181
|
-
switch (type) {
|
1182
|
-
case REACT_SUSPENSE_TYPE:
|
1183
|
-
return 'Suspense';
|
1184
|
-
|
1185
|
-
case REACT_SUSPENSE_LIST_TYPE:
|
1186
|
-
return 'SuspenseList';
|
1187
|
-
}
|
1188
|
-
|
1189
|
-
if (typeof type === 'object') {
|
1190
|
-
switch (type.$$typeof) {
|
1191
|
-
case REACT_FORWARD_REF_TYPE:
|
1192
|
-
return describeElementType(type.render);
|
1193
|
-
|
1194
|
-
case REACT_MEMO_TYPE:
|
1195
|
-
return describeElementType(type.type);
|
1196
|
-
|
1197
|
-
case REACT_LAZY_TYPE:
|
1198
|
-
{
|
1199
|
-
var lazyComponent = type;
|
1200
|
-
var payload = lazyComponent._payload;
|
1201
|
-
var init = lazyComponent._init;
|
1202
|
-
|
1203
|
-
try {
|
1204
|
-
// Lazy may contain any component type so we recursively resolve it.
|
1205
|
-
return describeElementType(init(payload));
|
1206
|
-
} catch (x) {}
|
1207
|
-
}
|
1208
|
-
}
|
1209
|
-
}
|
1210
|
-
|
1211
|
-
return '';
|
1212
|
-
}
|
1213
|
-
|
1214
|
-
function describeObjectForErrorMessage(objectOrArray, expandedName) {
|
1215
|
-
var objKind = objectName(objectOrArray);
|
1216
|
-
|
1217
|
-
if (objKind !== 'Object' && objKind !== 'Array') {
|
1218
|
-
return objKind;
|
1219
|
-
}
|
1220
|
-
|
1221
|
-
var str = '';
|
1222
|
-
var start = -1;
|
1223
|
-
var length = 0;
|
1224
|
-
|
1225
|
-
if (isArray(objectOrArray)) {
|
1226
|
-
if (jsxChildrenParents.has(objectOrArray)) {
|
1227
|
-
// Print JSX Children
|
1228
|
-
var type = jsxChildrenParents.get(objectOrArray);
|
1229
|
-
str = '<' + describeElementType(type) + '>';
|
1230
|
-
var array = objectOrArray;
|
1231
|
-
|
1232
|
-
for (var i = 0; i < array.length; i++) {
|
1233
|
-
var value = array[i];
|
1234
|
-
var substr = void 0;
|
1235
|
-
|
1236
|
-
if (typeof value === 'string') {
|
1237
|
-
substr = value;
|
1238
|
-
} else if (typeof value === 'object' && value !== null) {
|
1239
|
-
// $FlowFixMe[incompatible-call] found when upgrading Flow
|
1240
|
-
substr = '{' + describeObjectForErrorMessage(value) + '}';
|
1241
|
-
} else {
|
1242
|
-
substr = '{' + describeValueForErrorMessage(value) + '}';
|
1243
|
-
}
|
1244
|
-
|
1245
|
-
if ('' + i === expandedName) {
|
1246
|
-
start = str.length;
|
1247
|
-
length = substr.length;
|
1248
|
-
str += substr;
|
1249
|
-
} else if (substr.length < 15 && str.length + substr.length < 40) {
|
1250
|
-
str += substr;
|
1251
|
-
} else {
|
1252
|
-
str += '{...}';
|
1253
|
-
}
|
1254
|
-
}
|
1255
|
-
|
1256
|
-
str += '</' + describeElementType(type) + '>';
|
1257
|
-
} else {
|
1258
|
-
// Print Array
|
1259
|
-
str = '[';
|
1260
|
-
var _array = objectOrArray;
|
1261
|
-
|
1262
|
-
for (var _i = 0; _i < _array.length; _i++) {
|
1263
|
-
if (_i > 0) {
|
1264
|
-
str += ', ';
|
1265
|
-
}
|
1266
|
-
|
1267
|
-
var _value = _array[_i];
|
1268
|
-
|
1269
|
-
var _substr = void 0;
|
1270
|
-
|
1271
|
-
if (typeof _value === 'object' && _value !== null) {
|
1272
|
-
// $FlowFixMe[incompatible-call] found when upgrading Flow
|
1273
|
-
_substr = describeObjectForErrorMessage(_value);
|
1274
|
-
} else {
|
1275
|
-
_substr = describeValueForErrorMessage(_value);
|
1276
|
-
}
|
1277
|
-
|
1278
|
-
if ('' + _i === expandedName) {
|
1279
|
-
start = str.length;
|
1280
|
-
length = _substr.length;
|
1281
|
-
str += _substr;
|
1282
|
-
} else if (_substr.length < 10 && str.length + _substr.length < 40) {
|
1283
|
-
str += _substr;
|
1284
|
-
} else {
|
1285
|
-
str += '...';
|
1286
|
-
}
|
1287
|
-
}
|
1288
|
-
|
1289
|
-
str += ']';
|
1290
|
-
}
|
1291
|
-
} else {
|
1292
|
-
if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
|
1293
|
-
str = '<' + describeElementType(objectOrArray.type) + '/>';
|
1294
|
-
} else if (jsxPropsParents.has(objectOrArray)) {
|
1295
|
-
// Print JSX
|
1296
|
-
var _type = jsxPropsParents.get(objectOrArray);
|
1297
|
-
|
1298
|
-
str = '<' + (describeElementType(_type) || '...');
|
1299
|
-
var object = objectOrArray;
|
1300
|
-
var names = Object.keys(object);
|
1301
|
-
|
1302
|
-
for (var _i2 = 0; _i2 < names.length; _i2++) {
|
1303
|
-
str += ' ';
|
1304
|
-
var name = names[_i2];
|
1305
|
-
str += describeKeyForErrorMessage(name) + '=';
|
1306
|
-
var _value2 = object[name];
|
1307
|
-
|
1308
|
-
var _substr2 = void 0;
|
1309
|
-
|
1310
|
-
if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
|
1311
|
-
// $FlowFixMe[incompatible-call] found when upgrading Flow
|
1312
|
-
_substr2 = describeObjectForErrorMessage(_value2);
|
1313
|
-
} else {
|
1314
|
-
_substr2 = describeValueForErrorMessage(_value2);
|
1315
|
-
}
|
1316
|
-
|
1317
|
-
if (typeof _value2 !== 'string') {
|
1318
|
-
_substr2 = '{' + _substr2 + '}';
|
1319
|
-
}
|
1320
|
-
|
1321
|
-
if (name === expandedName) {
|
1322
|
-
start = str.length;
|
1323
|
-
length = _substr2.length;
|
1324
|
-
str += _substr2;
|
1325
|
-
} else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
|
1326
|
-
str += _substr2;
|
1327
|
-
} else {
|
1328
|
-
str += '...';
|
1329
|
-
}
|
1330
|
-
}
|
1331
|
-
|
1332
|
-
str += '>';
|
1333
|
-
} else {
|
1334
|
-
// Print Object
|
1335
|
-
str = '{';
|
1336
|
-
var _object = objectOrArray;
|
1337
|
-
|
1338
|
-
var _names = Object.keys(_object);
|
1339
|
-
|
1340
|
-
for (var _i3 = 0; _i3 < _names.length; _i3++) {
|
1341
|
-
if (_i3 > 0) {
|
1342
|
-
str += ', ';
|
1343
|
-
}
|
1344
|
-
|
1345
|
-
var _name = _names[_i3];
|
1346
|
-
str += describeKeyForErrorMessage(_name) + ': ';
|
1347
|
-
var _value3 = _object[_name];
|
1348
|
-
|
1349
|
-
var _substr3 = void 0;
|
1350
|
-
|
1351
|
-
if (typeof _value3 === 'object' && _value3 !== null) {
|
1352
|
-
// $FlowFixMe[incompatible-call] found when upgrading Flow
|
1353
|
-
_substr3 = describeObjectForErrorMessage(_value3);
|
1354
|
-
} else {
|
1355
|
-
_substr3 = describeValueForErrorMessage(_value3);
|
1356
|
-
}
|
1357
|
-
|
1358
|
-
if (_name === expandedName) {
|
1359
|
-
start = str.length;
|
1360
|
-
length = _substr3.length;
|
1361
|
-
str += _substr3;
|
1362
|
-
} else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
|
1363
|
-
str += _substr3;
|
1364
|
-
} else {
|
1365
|
-
str += '...';
|
1366
|
-
}
|
1367
|
-
}
|
1368
|
-
|
1369
|
-
str += '}';
|
1370
|
-
}
|
1371
|
-
}
|
1372
|
-
|
1373
|
-
if (expandedName === undefined) {
|
1374
|
-
return str;
|
1375
|
-
}
|
1376
|
-
|
1377
|
-
if (start > -1 && length > 0) {
|
1378
|
-
var highlight = ' '.repeat(start) + '^'.repeat(length);
|
1379
|
-
return '\n ' + str + '\n ' + highlight;
|
1380
|
-
}
|
1381
|
-
|
1382
|
-
return '\n ' + str;
|
1383
|
-
}
|
1384
|
-
|
1385
|
-
// Thenable<ReactServerValue>
|
1386
|
-
// function serializeByValueID(id: number): string {
|
1387
|
-
// return '$' + id.toString(16);
|
1388
|
-
// }
|
1389
|
-
|
1390
|
-
function serializePromiseID(id) {
|
1391
|
-
return '$@' + id.toString(16);
|
1392
|
-
}
|
1393
|
-
|
1394
|
-
function serializeServerReferenceID(id) {
|
1395
|
-
return '$F' + id.toString(16);
|
1396
|
-
}
|
1397
|
-
|
1398
|
-
function serializeSymbolReference(name) {
|
1399
|
-
return '$S' + name;
|
1400
|
-
}
|
1401
|
-
|
1402
|
-
function serializeFormDataReference(id) {
|
1403
|
-
// Why K? F is "Function". D is "Date". What else?
|
1404
|
-
return '$K' + id.toString(16);
|
1405
|
-
}
|
1406
|
-
|
1407
|
-
function serializeNumber(number) {
|
1408
|
-
if (Number.isFinite(number)) {
|
1409
|
-
if (number === 0 && 1 / number === -Infinity) {
|
1410
|
-
return '$-0';
|
1411
|
-
} else {
|
1412
|
-
return number;
|
1413
|
-
}
|
1414
|
-
} else {
|
1415
|
-
if (number === Infinity) {
|
1416
|
-
return '$Infinity';
|
1417
|
-
} else if (number === -Infinity) {
|
1418
|
-
return '$-Infinity';
|
1419
|
-
} else {
|
1420
|
-
return '$NaN';
|
1421
|
-
}
|
1422
|
-
}
|
1423
|
-
}
|
1424
|
-
|
1425
|
-
function serializeUndefined() {
|
1426
|
-
return '$undefined';
|
1427
|
-
}
|
1428
|
-
|
1429
|
-
function serializeDateFromDateJSON(dateJSON) {
|
1430
|
-
// JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
|
1431
|
-
// We need only tack on a $D prefix.
|
1432
|
-
return '$D' + dateJSON;
|
1433
|
-
}
|
1434
|
-
|
1435
|
-
function serializeBigInt(n) {
|
1436
|
-
return '$n' + n.toString(10);
|
1437
|
-
}
|
1438
|
-
|
1439
|
-
function escapeStringValue(value) {
|
1440
|
-
if (value[0] === '$') {
|
1441
|
-
// We need to escape $ prefixed strings since we use those to encode
|
1442
|
-
// references to IDs and as special symbol values.
|
1443
|
-
return '$' + value;
|
1444
|
-
} else {
|
1445
|
-
return value;
|
1446
|
-
}
|
1447
|
-
}
|
1448
|
-
|
1449
|
-
function processReply(root, formFieldPrefix, resolve, reject) {
|
1450
|
-
var nextPartId = 1;
|
1451
|
-
var pendingParts = 0;
|
1452
|
-
var formData = null;
|
1453
|
-
|
1454
|
-
function resolveToJSON(key, value) {
|
1455
|
-
var parent = this; // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
|
1456
|
-
|
1457
|
-
{
|
1458
|
-
// $FlowFixMe[incompatible-use]
|
1459
|
-
var originalValue = parent[key];
|
1460
|
-
|
1461
|
-
if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
|
1462
|
-
if (objectName(originalValue) !== 'Object') {
|
1463
|
-
error('Only plain objects can be passed to Server Functions from the Client. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
|
1464
|
-
} else {
|
1465
|
-
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));
|
1466
|
-
}
|
1467
|
-
}
|
1468
|
-
}
|
1469
|
-
|
1470
|
-
if (value === null) {
|
1471
|
-
return null;
|
1472
|
-
}
|
1473
|
-
|
1474
|
-
if (typeof value === 'object') {
|
1475
|
-
// $FlowFixMe[method-unbinding]
|
1476
|
-
if (typeof value.then === 'function') {
|
1477
|
-
// We assume that any object with a .then property is a "Thenable" type,
|
1478
|
-
// or a Promise type. Either of which can be represented by a Promise.
|
1479
|
-
if (formData === null) {
|
1480
|
-
// Upgrade to use FormData to allow us to stream this value.
|
1481
|
-
formData = new FormData();
|
1482
|
-
}
|
1483
|
-
|
1484
|
-
pendingParts++;
|
1485
|
-
var promiseId = nextPartId++;
|
1486
|
-
var thenable = value;
|
1487
|
-
thenable.then(function (partValue) {
|
1488
|
-
var partJSON = JSON.stringify(partValue, resolveToJSON); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
1489
|
-
|
1490
|
-
var data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
|
1491
|
-
|
1492
|
-
data.append(formFieldPrefix + promiseId, partJSON);
|
1493
|
-
pendingParts--;
|
1494
|
-
|
1495
|
-
if (pendingParts === 0) {
|
1496
|
-
resolve(data);
|
1497
|
-
}
|
1498
|
-
}, function (reason) {
|
1499
|
-
// In the future we could consider serializing this as an error
|
1500
|
-
// that throws on the server instead.
|
1501
|
-
reject(reason);
|
1502
|
-
});
|
1503
|
-
return serializePromiseID(promiseId);
|
1504
|
-
} // TODO: Should we the Object.prototype.toString.call() to test for cross-realm objects?
|
1505
|
-
|
1506
|
-
|
1507
|
-
if (value instanceof FormData) {
|
1508
|
-
if (formData === null) {
|
1509
|
-
// Upgrade to use FormData to allow us to use rich objects as its values.
|
1510
|
-
formData = new FormData();
|
1511
|
-
}
|
1512
|
-
|
1513
|
-
var data = formData;
|
1514
|
-
var refId = nextPartId++; // Copy all the form fields with a prefix for this reference.
|
1515
|
-
// These must come first in the form order because we assume that all the
|
1516
|
-
// fields are available before this is referenced.
|
1517
|
-
|
1518
|
-
var prefix = formFieldPrefix + refId + '_'; // $FlowFixMe[prop-missing]: FormData has forEach.
|
1519
|
-
|
1520
|
-
value.forEach(function (originalValue, originalKey) {
|
1521
|
-
data.append(prefix + originalKey, originalValue);
|
1522
|
-
});
|
1523
|
-
return serializeFormDataReference(refId);
|
1524
|
-
}
|
1525
|
-
|
1526
|
-
if (!isArray(value)) {
|
1527
|
-
var iteratorFn = getIteratorFn(value);
|
1528
|
-
|
1529
|
-
if (iteratorFn) {
|
1530
|
-
return Array.from(value);
|
1531
|
-
}
|
1532
|
-
}
|
1533
|
-
|
1534
|
-
{
|
1535
|
-
if (value !== null && !isArray(value)) {
|
1536
|
-
// Verify that this is a simple plain object.
|
1537
|
-
if (value.$$typeof === REACT_ELEMENT_TYPE) {
|
1538
|
-
error('React Element cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
|
1539
|
-
} else if (value.$$typeof === REACT_LAZY_TYPE) {
|
1540
|
-
error('React Lazy cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
|
1541
|
-
} else if (value.$$typeof === REACT_PROVIDER_TYPE) {
|
1542
|
-
error('React Context Providers cannot be passed to Server Functions from the Client.%s', describeObjectForErrorMessage(parent, key));
|
1543
|
-
} else if (objectName(value) !== 'Object') {
|
1544
|
-
error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
|
1545
|
-
} else if (!isSimpleObject(value)) {
|
1546
|
-
error('Only plain objects can be passed to Client Components from Server Components. ' + 'Classes or other objects with methods are not supported.%s', describeObjectForErrorMessage(parent, key));
|
1547
|
-
} else if (Object.getOwnPropertySymbols) {
|
1548
|
-
var symbols = Object.getOwnPropertySymbols(value);
|
1549
|
-
|
1550
|
-
if (symbols.length > 0) {
|
1551
|
-
error('Only plain objects can be passed to Client Components from Server Components. ' + 'Objects with symbol properties like %s are not supported.%s', symbols[0].description, describeObjectForErrorMessage(parent, key));
|
1552
|
-
}
|
1553
|
-
}
|
1554
|
-
}
|
1555
|
-
} // $FlowFixMe[incompatible-return]
|
1556
|
-
|
1557
|
-
|
1558
|
-
return value;
|
1559
|
-
}
|
1560
|
-
|
1561
|
-
if (typeof value === 'string') {
|
1562
|
-
// TODO: Maybe too clever. If we support URL there's no similar trick.
|
1563
|
-
if (value[value.length - 1] === 'Z') {
|
1564
|
-
// Possibly a Date, whose toJSON automatically calls toISOString
|
1565
|
-
// $FlowFixMe[incompatible-use]
|
1566
|
-
var _originalValue = parent[key]; // $FlowFixMe[method-unbinding]
|
1567
|
-
|
1568
|
-
if (_originalValue instanceof Date) {
|
1569
|
-
return serializeDateFromDateJSON(value);
|
1570
|
-
}
|
1571
|
-
}
|
1572
|
-
|
1573
|
-
return escapeStringValue(value);
|
1574
|
-
}
|
1575
|
-
|
1576
|
-
if (typeof value === 'boolean') {
|
1577
|
-
return value;
|
1578
|
-
}
|
1579
|
-
|
1580
|
-
if (typeof value === 'number') {
|
1581
|
-
return serializeNumber(value);
|
1582
|
-
}
|
1583
|
-
|
1584
|
-
if (typeof value === 'undefined') {
|
1585
|
-
return serializeUndefined();
|
1586
|
-
}
|
1587
|
-
|
1588
|
-
if (typeof value === 'function') {
|
1589
|
-
var metaData = knownServerReferences.get(value);
|
1590
|
-
|
1591
|
-
if (metaData !== undefined) {
|
1592
|
-
var metaDataJSON = JSON.stringify(metaData, resolveToJSON);
|
1593
|
-
|
1594
|
-
if (formData === null) {
|
1595
|
-
// Upgrade to use FormData to allow us to stream this value.
|
1596
|
-
formData = new FormData();
|
1597
|
-
} // The reference to this function came from the same client so we can pass it back.
|
1598
|
-
|
1599
|
-
|
1600
|
-
var _refId = nextPartId++; // eslint-disable-next-line react-internal/safe-string-coercion
|
1601
|
-
|
1602
|
-
|
1603
|
-
formData.set(formFieldPrefix + _refId, metaDataJSON);
|
1604
|
-
return serializeServerReferenceID(_refId);
|
1605
|
-
}
|
1606
|
-
|
1607
|
-
throw new Error('Client Functions cannot be passed directly to Server Functions. ' + 'Only Functions passed from the Server can be passed back again.');
|
1608
|
-
}
|
1609
|
-
|
1610
|
-
if (typeof value === 'symbol') {
|
1611
|
-
// $FlowFixMe[incompatible-type] `description` might be undefined
|
1612
|
-
var name = value.description;
|
1613
|
-
|
1614
|
-
if (Symbol.for(name) !== value) {
|
1615
|
-
throw new Error('Only global symbols received from Symbol.for(...) can be passed to Server Functions. ' + ("The symbol Symbol.for(" + // $FlowFixMe[incompatible-type] `description` might be undefined
|
1616
|
-
value.description + ") cannot be found among global symbols."));
|
1617
|
-
}
|
1618
|
-
|
1619
|
-
return serializeSymbolReference(name);
|
1620
|
-
}
|
1621
|
-
|
1622
|
-
if (typeof value === 'bigint') {
|
1623
|
-
return serializeBigInt(value);
|
1624
|
-
}
|
1625
|
-
|
1626
|
-
throw new Error("Type " + typeof value + " is not supported as an argument to a Server Function.");
|
1627
|
-
} // $FlowFixMe[incompatible-type] it's not going to be undefined because we'll encode it.
|
1628
|
-
|
1629
|
-
|
1630
|
-
var json = JSON.stringify(root, resolveToJSON);
|
1631
|
-
|
1632
|
-
if (formData === null) {
|
1633
|
-
// If it's a simple data structure, we just use plain JSON.
|
1634
|
-
resolve(json);
|
1635
|
-
} else {
|
1636
|
-
// Otherwise, we use FormData to let us stream in the result.
|
1637
|
-
formData.set(formFieldPrefix + '0', json);
|
1638
|
-
|
1639
|
-
if (pendingParts === 0) {
|
1640
|
-
// $FlowFixMe[incompatible-call] this has already been refined.
|
1641
|
-
resolve(formData);
|
1642
|
-
}
|
1643
|
-
}
|
1644
|
-
}
|
1645
|
-
|
1646
|
-
function createResponseFromOptions(options) {
|
1647
|
-
return createResponse(null, options && options.callServer ? options.callServer : undefined);
|
1648
|
-
}
|
1649
|
-
|
1650
|
-
function startReadingFromStream(response, stream) {
|
1651
|
-
var reader = stream.getReader();
|
1652
|
-
|
1653
|
-
function progress(_ref) {
|
1654
|
-
var done = _ref.done,
|
1655
|
-
value = _ref.value;
|
1656
|
-
|
1657
|
-
if (done) {
|
1658
|
-
close(response);
|
1659
|
-
return;
|
1660
|
-
}
|
1661
|
-
|
1662
|
-
var buffer = value;
|
1663
|
-
processBinaryChunk(response, buffer);
|
1664
|
-
return reader.read().then(progress).catch(error);
|
1665
|
-
}
|
1666
|
-
|
1667
|
-
function error(e) {
|
1668
|
-
reportGlobalError(response, e);
|
1669
|
-
}
|
1670
|
-
|
1671
|
-
reader.read().then(progress).catch(error);
|
1672
|
-
}
|
1673
|
-
|
1674
|
-
function createFromReadableStream(stream, options) {
|
1675
|
-
var response = createResponseFromOptions(options);
|
1676
|
-
startReadingFromStream(response, stream);
|
1677
|
-
return getRoot(response);
|
1678
|
-
}
|
1679
|
-
|
1680
|
-
function createFromFetch(promiseForResponse, options) {
|
1681
|
-
var response = createResponseFromOptions(options);
|
1682
|
-
promiseForResponse.then(function (r) {
|
1683
|
-
startReadingFromStream(response, r.body);
|
1684
|
-
}, function (e) {
|
1685
|
-
reportGlobalError(response, e);
|
1686
|
-
});
|
1687
|
-
return getRoot(response);
|
1688
|
-
}
|
1689
|
-
|
1690
|
-
function createFromXHR(request, options) {
|
1691
|
-
var response = createResponseFromOptions(options);
|
1692
|
-
var processedLength = 0;
|
1693
|
-
|
1694
|
-
function progress(e) {
|
1695
|
-
var chunk = request.responseText;
|
1696
|
-
processStringChunk(response, chunk, processedLength);
|
1697
|
-
processedLength = chunk.length;
|
1698
|
-
}
|
1699
|
-
|
1700
|
-
function load(e) {
|
1701
|
-
progress();
|
1702
|
-
close(response);
|
1703
|
-
}
|
1704
|
-
|
1705
|
-
function error(e) {
|
1706
|
-
reportGlobalError(response, new TypeError('Network error'));
|
1707
|
-
}
|
1708
|
-
|
1709
|
-
request.addEventListener('progress', progress);
|
1710
|
-
request.addEventListener('load', load);
|
1711
|
-
request.addEventListener('error', error);
|
1712
|
-
request.addEventListener('abort', error);
|
1713
|
-
request.addEventListener('timeout', error);
|
1714
|
-
return getRoot(response);
|
1715
|
-
}
|
1716
|
-
|
1717
|
-
function encodeReply(value)
|
1718
|
-
/* We don't use URLSearchParams yet but maybe */
|
1719
|
-
{
|
1720
|
-
return new Promise(function (resolve, reject) {
|
1721
|
-
processReply(value, '', resolve, reject);
|
1722
|
-
});
|
1723
|
-
}
|
1724
|
-
|
1725
|
-
exports.createFromFetch = createFromFetch;
|
1726
|
-
exports.createFromReadableStream = createFromReadableStream;
|
1727
|
-
exports.createFromXHR = createFromXHR;
|
1728
|
-
exports.createServerReference = createServerReference;
|
1729
|
-
exports.encodeReply = encodeReply;
|
1730
|
-
|
1731
|
-
}));
|