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,2904 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @license React
|
3
|
-
* react-server-dom-webpack-server.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'), require('react-dom')) :
|
12
|
-
typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom'], factory) :
|
13
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactServerDOMServer = {}, global.React, global.ReactDOM));
|
14
|
-
})(this, (function (exports, React, ReactDOM) { 'use strict';
|
15
|
-
|
16
|
-
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
17
|
-
|
18
|
-
function error(format) {
|
19
|
-
{
|
20
|
-
{
|
21
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
22
|
-
args[_key2 - 1] = arguments[_key2];
|
23
|
-
}
|
24
|
-
|
25
|
-
printWarning('error', format, args);
|
26
|
-
}
|
27
|
-
}
|
28
|
-
}
|
29
|
-
|
30
|
-
function printWarning(level, format, args) {
|
31
|
-
// When changing this logic, you might want to also
|
32
|
-
// update consoleWithStackDev.www.js as well.
|
33
|
-
{
|
34
|
-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
35
|
-
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
36
|
-
|
37
|
-
if (stack !== '') {
|
38
|
-
format += '%s';
|
39
|
-
args = args.concat([stack]);
|
40
|
-
} // eslint-disable-next-line react-internal/safe-string-coercion
|
41
|
-
|
42
|
-
|
43
|
-
var argsWithFormat = args.map(function (item) {
|
44
|
-
return String(item);
|
45
|
-
}); // Careful: RN currently depends on this prefix
|
46
|
-
|
47
|
-
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
48
|
-
// breaks IE9: https://github.com/facebook/react/issues/13610
|
49
|
-
// eslint-disable-next-line react-internal/no-production-logging
|
50
|
-
|
51
|
-
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
function scheduleWork(callback) {
|
56
|
-
callback();
|
57
|
-
}
|
58
|
-
var VIEW_SIZE = 512;
|
59
|
-
var currentView = null;
|
60
|
-
var writtenBytes = 0;
|
61
|
-
function beginWriting(destination) {
|
62
|
-
currentView = new Uint8Array(VIEW_SIZE);
|
63
|
-
writtenBytes = 0;
|
64
|
-
}
|
65
|
-
function writeChunk(destination, chunk) {
|
66
|
-
if (chunk.length === 0) {
|
67
|
-
return;
|
68
|
-
}
|
69
|
-
|
70
|
-
if (chunk.length > VIEW_SIZE) {
|
71
|
-
{
|
72
|
-
if (precomputedChunkSet.has(chunk)) {
|
73
|
-
error('A large precomputed chunk was passed to writeChunk without being copied.' + ' Large chunks get enqueued directly and are not copied. This is incompatible with precomputed chunks because you cannot enqueue the same precomputed chunk twice.' + ' Use "cloneChunk" to make a copy of this large precomputed chunk before writing it. This is a bug in React.');
|
74
|
-
}
|
75
|
-
} // this chunk may overflow a single view which implies it was not
|
76
|
-
// one that is cached by the streaming renderer. We will enqueu
|
77
|
-
// it directly and expect it is not re-used
|
78
|
-
|
79
|
-
|
80
|
-
if (writtenBytes > 0) {
|
81
|
-
destination.enqueue(new Uint8Array(currentView.buffer, 0, writtenBytes));
|
82
|
-
currentView = new Uint8Array(VIEW_SIZE);
|
83
|
-
writtenBytes = 0;
|
84
|
-
}
|
85
|
-
|
86
|
-
destination.enqueue(chunk);
|
87
|
-
return;
|
88
|
-
}
|
89
|
-
|
90
|
-
var bytesToWrite = chunk;
|
91
|
-
var allowableBytes = currentView.length - writtenBytes;
|
92
|
-
|
93
|
-
if (allowableBytes < bytesToWrite.length) {
|
94
|
-
// this chunk would overflow the current view. We enqueue a full view
|
95
|
-
// and start a new view with the remaining chunk
|
96
|
-
if (allowableBytes === 0) {
|
97
|
-
// the current view is already full, send it
|
98
|
-
destination.enqueue(currentView);
|
99
|
-
} else {
|
100
|
-
// fill up the current view and apply the remaining chunk bytes
|
101
|
-
// to a new view.
|
102
|
-
currentView.set(bytesToWrite.subarray(0, allowableBytes), writtenBytes); // writtenBytes += allowableBytes; // this can be skipped because we are going to immediately reset the view
|
103
|
-
|
104
|
-
destination.enqueue(currentView);
|
105
|
-
bytesToWrite = bytesToWrite.subarray(allowableBytes);
|
106
|
-
}
|
107
|
-
|
108
|
-
currentView = new Uint8Array(VIEW_SIZE);
|
109
|
-
writtenBytes = 0;
|
110
|
-
}
|
111
|
-
|
112
|
-
currentView.set(bytesToWrite, writtenBytes);
|
113
|
-
writtenBytes += bytesToWrite.length;
|
114
|
-
}
|
115
|
-
function writeChunkAndReturn(destination, chunk) {
|
116
|
-
writeChunk(destination, chunk); // in web streams there is no backpressure so we can alwas write more
|
117
|
-
|
118
|
-
return true;
|
119
|
-
}
|
120
|
-
function completeWriting(destination) {
|
121
|
-
if (currentView && writtenBytes > 0) {
|
122
|
-
destination.enqueue(new Uint8Array(currentView.buffer, 0, writtenBytes));
|
123
|
-
currentView = null;
|
124
|
-
writtenBytes = 0;
|
125
|
-
}
|
126
|
-
}
|
127
|
-
function close$1(destination) {
|
128
|
-
destination.close();
|
129
|
-
}
|
130
|
-
var textEncoder = new TextEncoder();
|
131
|
-
function stringToChunk(content) {
|
132
|
-
return textEncoder.encode(content);
|
133
|
-
}
|
134
|
-
var precomputedChunkSet = new Set() ;
|
135
|
-
function closeWithError(destination, error) {
|
136
|
-
// $FlowFixMe[method-unbinding]
|
137
|
-
if (typeof destination.error === 'function') {
|
138
|
-
// $FlowFixMe[incompatible-call]: This is an Error object or the destination accepts other types.
|
139
|
-
destination.error(error);
|
140
|
-
} else {
|
141
|
-
// Earlier implementations doesn't support this method. In that environment you're
|
142
|
-
// supposed to throw from a promise returned but we don't return a promise in our
|
143
|
-
// approach. We could fork this implementation but this is environment is an edge
|
144
|
-
// case to begin with. It's even less common to run this in an older environment.
|
145
|
-
// Even then, this is not where errors are supposed to happen and they get reported
|
146
|
-
// to a global callback in addition to this anyway. So it's fine just to close this.
|
147
|
-
destination.close();
|
148
|
-
}
|
149
|
-
}
|
150
|
-
|
151
|
-
// This file is an intermediate layer to translate between Flight
|
152
|
-
var stringify = JSON.stringify;
|
153
|
-
|
154
|
-
function serializeRowHeader(tag, id) {
|
155
|
-
return id.toString(16) + ':' + tag;
|
156
|
-
}
|
157
|
-
|
158
|
-
function processErrorChunkProd(request, id, digest) {
|
159
|
-
{
|
160
|
-
// These errors should never make it into a build so we don't need to encode them in codes.json
|
161
|
-
// eslint-disable-next-line react-internal/prod-error-codes
|
162
|
-
throw new Error('processErrorChunkProd should never be called while in development mode. Use processErrorChunkDev instead. This is a bug in React.');
|
163
|
-
}
|
164
|
-
}
|
165
|
-
function processErrorChunkDev(request, id, digest, message, stack) {
|
166
|
-
|
167
|
-
var errorInfo = {
|
168
|
-
digest: digest,
|
169
|
-
message: message,
|
170
|
-
stack: stack
|
171
|
-
};
|
172
|
-
var row = serializeRowHeader('E', id) + stringify(errorInfo) + '\n';
|
173
|
-
return stringToChunk(row);
|
174
|
-
}
|
175
|
-
function processModelChunk(request, id, model) {
|
176
|
-
// $FlowFixMe[incompatible-type] stringify can return null
|
177
|
-
var json = stringify(model, request.toJSON);
|
178
|
-
var row = id.toString(16) + ':' + json + '\n';
|
179
|
-
return stringToChunk(row);
|
180
|
-
}
|
181
|
-
function processReferenceChunk(request, id, reference) {
|
182
|
-
var json = stringify(reference);
|
183
|
-
var row = id.toString(16) + ':' + json + '\n';
|
184
|
-
return stringToChunk(row);
|
185
|
-
}
|
186
|
-
function processImportChunk(request, id, clientReferenceMetadata) {
|
187
|
-
// $FlowFixMe[incompatible-type] stringify can return null
|
188
|
-
var json = stringify(clientReferenceMetadata);
|
189
|
-
var row = serializeRowHeader('I', id) + json + '\n';
|
190
|
-
return stringToChunk(row);
|
191
|
-
}
|
192
|
-
function processHintChunk(request, id, code, model) {
|
193
|
-
var json = stringify(model);
|
194
|
-
var row = serializeRowHeader('H' + code, id) + json + '\n';
|
195
|
-
return stringToChunk(row);
|
196
|
-
}
|
197
|
-
|
198
|
-
// eslint-disable-next-line no-unused-vars
|
199
|
-
var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
|
200
|
-
var SERVER_REFERENCE_TAG = Symbol.for('react.server.reference');
|
201
|
-
function getClientReferenceKey(reference) {
|
202
|
-
return reference.$$async ? reference.$$id + '#async' : reference.$$id;
|
203
|
-
}
|
204
|
-
function isClientReference(reference) {
|
205
|
-
return reference.$$typeof === CLIENT_REFERENCE_TAG;
|
206
|
-
}
|
207
|
-
function isServerReference(reference) {
|
208
|
-
return reference.$$typeof === SERVER_REFERENCE_TAG;
|
209
|
-
}
|
210
|
-
function resolveClientReferenceMetadata(config, clientReference) {
|
211
|
-
var modulePath = clientReference.$$id;
|
212
|
-
var name = '';
|
213
|
-
var resolvedModuleData = config[modulePath];
|
214
|
-
|
215
|
-
if (resolvedModuleData) {
|
216
|
-
// The potentially aliased name.
|
217
|
-
name = resolvedModuleData.name;
|
218
|
-
} else {
|
219
|
-
// We didn't find this specific export name but we might have the * export
|
220
|
-
// which contains this name as well.
|
221
|
-
// TODO: It's unfortunate that we now have to parse this string. We should
|
222
|
-
// probably go back to encoding path and name separately on the client reference.
|
223
|
-
var idx = modulePath.lastIndexOf('#');
|
224
|
-
|
225
|
-
if (idx !== -1) {
|
226
|
-
name = modulePath.slice(idx + 1);
|
227
|
-
resolvedModuleData = config[modulePath.slice(0, idx)];
|
228
|
-
}
|
229
|
-
|
230
|
-
if (!resolvedModuleData) {
|
231
|
-
throw new Error('Could not find the module "' + modulePath + '" in the React Client Manifest. ' + 'This is probably a bug in the React Server Components bundler.');
|
232
|
-
}
|
233
|
-
}
|
234
|
-
|
235
|
-
return {
|
236
|
-
id: resolvedModuleData.id,
|
237
|
-
chunks: resolvedModuleData.chunks,
|
238
|
-
name: name,
|
239
|
-
async: !!clientReference.$$async
|
240
|
-
};
|
241
|
-
}
|
242
|
-
function getServerReferenceId(config, serverReference) {
|
243
|
-
return serverReference.$$id;
|
244
|
-
}
|
245
|
-
function getServerReferenceBoundArguments(config, serverReference) {
|
246
|
-
return serverReference.$$bound;
|
247
|
-
}
|
248
|
-
|
249
|
-
var ReactDOMSharedInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
250
|
-
|
251
|
-
var ReactDOMFlightServerDispatcher = {
|
252
|
-
prefetchDNS: prefetchDNS,
|
253
|
-
preconnect: preconnect,
|
254
|
-
preload: preload,
|
255
|
-
preinit: preinit
|
256
|
-
};
|
257
|
-
|
258
|
-
function prefetchDNS(href, options) {
|
259
|
-
{
|
260
|
-
if (typeof href === 'string') {
|
261
|
-
var request = resolveRequest();
|
262
|
-
|
263
|
-
if (request) {
|
264
|
-
var hints = getHints(request);
|
265
|
-
var key = 'D' + href;
|
266
|
-
|
267
|
-
if (hints.has(key)) {
|
268
|
-
// duplicate hint
|
269
|
-
return;
|
270
|
-
}
|
271
|
-
|
272
|
-
hints.add(key);
|
273
|
-
|
274
|
-
if (options) {
|
275
|
-
emitHint(request, 'D', [href, options]);
|
276
|
-
} else {
|
277
|
-
emitHint(request, 'D', href);
|
278
|
-
}
|
279
|
-
}
|
280
|
-
}
|
281
|
-
}
|
282
|
-
}
|
283
|
-
|
284
|
-
function preconnect(href, options) {
|
285
|
-
{
|
286
|
-
if (typeof href === 'string') {
|
287
|
-
var request = resolveRequest();
|
288
|
-
|
289
|
-
if (request) {
|
290
|
-
var hints = getHints(request);
|
291
|
-
var crossOrigin = options == null || typeof options.crossOrigin !== 'string' ? null : options.crossOrigin === 'use-credentials' ? 'use-credentials' : '';
|
292
|
-
var key = "C" + (crossOrigin === null ? 'null' : crossOrigin) + "|" + href;
|
293
|
-
|
294
|
-
if (hints.has(key)) {
|
295
|
-
// duplicate hint
|
296
|
-
return;
|
297
|
-
}
|
298
|
-
|
299
|
-
hints.add(key);
|
300
|
-
|
301
|
-
if (options) {
|
302
|
-
emitHint(request, 'C', [href, options]);
|
303
|
-
} else {
|
304
|
-
emitHint(request, 'C', href);
|
305
|
-
}
|
306
|
-
}
|
307
|
-
}
|
308
|
-
}
|
309
|
-
}
|
310
|
-
|
311
|
-
function preload(href, options) {
|
312
|
-
{
|
313
|
-
if (typeof href === 'string') {
|
314
|
-
var request = resolveRequest();
|
315
|
-
|
316
|
-
if (request) {
|
317
|
-
var hints = getHints(request);
|
318
|
-
var key = 'L' + href;
|
319
|
-
|
320
|
-
if (hints.has(key)) {
|
321
|
-
// duplicate hint
|
322
|
-
return;
|
323
|
-
}
|
324
|
-
|
325
|
-
hints.add(key);
|
326
|
-
emitHint(request, 'L', [href, options]);
|
327
|
-
}
|
328
|
-
}
|
329
|
-
}
|
330
|
-
}
|
331
|
-
|
332
|
-
function preinit(href, options) {
|
333
|
-
{
|
334
|
-
if (typeof href === 'string') {
|
335
|
-
var request = resolveRequest();
|
336
|
-
|
337
|
-
if (request) {
|
338
|
-
var hints = getHints(request);
|
339
|
-
var key = 'I' + href;
|
340
|
-
|
341
|
-
if (hints.has(key)) {
|
342
|
-
// duplicate hint
|
343
|
-
return;
|
344
|
-
}
|
345
|
-
|
346
|
-
hints.add(key);
|
347
|
-
emitHint(request, 'I', [href, options]);
|
348
|
-
}
|
349
|
-
}
|
350
|
-
}
|
351
|
-
}
|
352
|
-
|
353
|
-
var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.Dispatcher;
|
354
|
-
function prepareHostDispatcher() {
|
355
|
-
ReactDOMCurrentDispatcher.current = ReactDOMFlightServerDispatcher;
|
356
|
-
} // Used to distinguish these contexts from ones used in other renderers.
|
357
|
-
function createHints() {
|
358
|
-
return new Set();
|
359
|
-
}
|
360
|
-
|
361
|
-
// ATTENTION
|
362
|
-
// When adding new symbols to this file,
|
363
|
-
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
|
364
|
-
// The Symbol used to tag the ReactElement-like types.
|
365
|
-
var REACT_ELEMENT_TYPE = Symbol.for('react.element');
|
366
|
-
var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
|
367
|
-
var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
|
368
|
-
var REACT_SERVER_CONTEXT_TYPE = Symbol.for('react.server_context');
|
369
|
-
var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
|
370
|
-
var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
|
371
|
-
var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
|
372
|
-
var REACT_MEMO_TYPE = Symbol.for('react.memo');
|
373
|
-
var REACT_LAZY_TYPE = Symbol.for('react.lazy');
|
374
|
-
var REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED = Symbol.for('react.default_value');
|
375
|
-
var REACT_MEMO_CACHE_SENTINEL = Symbol.for('react.memo_cache_sentinel');
|
376
|
-
var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
|
377
|
-
var FAUX_ITERATOR_SYMBOL = '@@iterator';
|
378
|
-
function getIteratorFn(maybeIterable) {
|
379
|
-
if (maybeIterable === null || typeof maybeIterable !== 'object') {
|
380
|
-
return null;
|
381
|
-
}
|
382
|
-
|
383
|
-
var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
|
384
|
-
|
385
|
-
if (typeof maybeIterator === 'function') {
|
386
|
-
return maybeIterator;
|
387
|
-
}
|
388
|
-
|
389
|
-
return null;
|
390
|
-
}
|
391
|
-
|
392
|
-
var rendererSigil;
|
393
|
-
|
394
|
-
{
|
395
|
-
// Use this to detect multiple renderers using the same context
|
396
|
-
rendererSigil = {};
|
397
|
-
} // Used to store the parent path of all context overrides in a shared linked list.
|
398
|
-
// Forming a reverse tree.
|
399
|
-
// The structure of a context snapshot is an implementation of this file.
|
400
|
-
// Currently, it's implemented as tracking the current active node.
|
401
|
-
|
402
|
-
|
403
|
-
var rootContextSnapshot = null; // We assume that this runtime owns the "current" field on all ReactContext instances.
|
404
|
-
// This global (actually thread local) state represents what state all those "current",
|
405
|
-
// fields are currently in.
|
406
|
-
|
407
|
-
var currentActiveSnapshot = null;
|
408
|
-
|
409
|
-
function popNode(prev) {
|
410
|
-
{
|
411
|
-
prev.context._currentValue = prev.parentValue;
|
412
|
-
}
|
413
|
-
}
|
414
|
-
|
415
|
-
function pushNode(next) {
|
416
|
-
{
|
417
|
-
next.context._currentValue = next.value;
|
418
|
-
}
|
419
|
-
}
|
420
|
-
|
421
|
-
function popToNearestCommonAncestor(prev, next) {
|
422
|
-
if (prev === next) ; else {
|
423
|
-
popNode(prev);
|
424
|
-
var parentPrev = prev.parent;
|
425
|
-
var parentNext = next.parent;
|
426
|
-
|
427
|
-
if (parentPrev === null) {
|
428
|
-
if (parentNext !== null) {
|
429
|
-
throw new Error('The stacks must reach the root at the same time. This is a bug in React.');
|
430
|
-
}
|
431
|
-
} else {
|
432
|
-
if (parentNext === null) {
|
433
|
-
throw new Error('The stacks must reach the root at the same time. This is a bug in React.');
|
434
|
-
}
|
435
|
-
|
436
|
-
popToNearestCommonAncestor(parentPrev, parentNext); // On the way back, we push the new ones that weren't common.
|
437
|
-
|
438
|
-
pushNode(next);
|
439
|
-
}
|
440
|
-
}
|
441
|
-
}
|
442
|
-
|
443
|
-
function popAllPrevious(prev) {
|
444
|
-
popNode(prev);
|
445
|
-
var parentPrev = prev.parent;
|
446
|
-
|
447
|
-
if (parentPrev !== null) {
|
448
|
-
popAllPrevious(parentPrev);
|
449
|
-
}
|
450
|
-
}
|
451
|
-
|
452
|
-
function pushAllNext(next) {
|
453
|
-
var parentNext = next.parent;
|
454
|
-
|
455
|
-
if (parentNext !== null) {
|
456
|
-
pushAllNext(parentNext);
|
457
|
-
}
|
458
|
-
|
459
|
-
pushNode(next);
|
460
|
-
}
|
461
|
-
|
462
|
-
function popPreviousToCommonLevel(prev, next) {
|
463
|
-
popNode(prev);
|
464
|
-
var parentPrev = prev.parent;
|
465
|
-
|
466
|
-
if (parentPrev === null) {
|
467
|
-
throw new Error('The depth must equal at least at zero before reaching the root. This is a bug in React.');
|
468
|
-
}
|
469
|
-
|
470
|
-
if (parentPrev.depth === next.depth) {
|
471
|
-
// We found the same level. Now we just need to find a shared ancestor.
|
472
|
-
popToNearestCommonAncestor(parentPrev, next);
|
473
|
-
} else {
|
474
|
-
// We must still be deeper.
|
475
|
-
popPreviousToCommonLevel(parentPrev, next);
|
476
|
-
}
|
477
|
-
}
|
478
|
-
|
479
|
-
function popNextToCommonLevel(prev, next) {
|
480
|
-
var parentNext = next.parent;
|
481
|
-
|
482
|
-
if (parentNext === null) {
|
483
|
-
throw new Error('The depth must equal at least at zero before reaching the root. This is a bug in React.');
|
484
|
-
}
|
485
|
-
|
486
|
-
if (prev.depth === parentNext.depth) {
|
487
|
-
// We found the same level. Now we just need to find a shared ancestor.
|
488
|
-
popToNearestCommonAncestor(prev, parentNext);
|
489
|
-
} else {
|
490
|
-
// We must still be deeper.
|
491
|
-
popNextToCommonLevel(prev, parentNext);
|
492
|
-
}
|
493
|
-
|
494
|
-
pushNode(next);
|
495
|
-
} // Perform context switching to the new snapshot.
|
496
|
-
// To make it cheap to read many contexts, while not suspending, we make the switch eagerly by
|
497
|
-
// updating all the context's current values. That way reads, always just read the current value.
|
498
|
-
// At the cost of updating contexts even if they're never read by this subtree.
|
499
|
-
|
500
|
-
|
501
|
-
function switchContext(newSnapshot) {
|
502
|
-
// The basic algorithm we need to do is to pop back any contexts that are no longer on the stack.
|
503
|
-
// We also need to update any new contexts that are now on the stack with the deepest value.
|
504
|
-
// The easiest way to update new contexts is to just reapply them in reverse order from the
|
505
|
-
// perspective of the backpointers. To avoid allocating a lot when switching, we use the stack
|
506
|
-
// for that. Therefore this algorithm is recursive.
|
507
|
-
// 1) First we pop which ever snapshot tree was deepest. Popping old contexts as we go.
|
508
|
-
// 2) Then we find the nearest common ancestor from there. Popping old contexts as we go.
|
509
|
-
// 3) Then we reapply new contexts on the way back up the stack.
|
510
|
-
var prev = currentActiveSnapshot;
|
511
|
-
var next = newSnapshot;
|
512
|
-
|
513
|
-
if (prev !== next) {
|
514
|
-
if (prev === null) {
|
515
|
-
// $FlowFixMe[incompatible-call]: This has to be non-null since it's not equal to prev.
|
516
|
-
pushAllNext(next);
|
517
|
-
} else if (next === null) {
|
518
|
-
popAllPrevious(prev);
|
519
|
-
} else if (prev.depth === next.depth) {
|
520
|
-
popToNearestCommonAncestor(prev, next);
|
521
|
-
} else if (prev.depth > next.depth) {
|
522
|
-
popPreviousToCommonLevel(prev, next);
|
523
|
-
} else {
|
524
|
-
popNextToCommonLevel(prev, next);
|
525
|
-
}
|
526
|
-
|
527
|
-
currentActiveSnapshot = next;
|
528
|
-
}
|
529
|
-
}
|
530
|
-
function pushProvider(context, nextValue) {
|
531
|
-
var prevValue;
|
532
|
-
|
533
|
-
{
|
534
|
-
prevValue = context._currentValue;
|
535
|
-
context._currentValue = nextValue;
|
536
|
-
|
537
|
-
{
|
538
|
-
if (context._currentRenderer !== undefined && context._currentRenderer !== null && context._currentRenderer !== rendererSigil) {
|
539
|
-
error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
|
540
|
-
}
|
541
|
-
|
542
|
-
context._currentRenderer = rendererSigil;
|
543
|
-
}
|
544
|
-
}
|
545
|
-
|
546
|
-
var prevNode = currentActiveSnapshot;
|
547
|
-
var newNode = {
|
548
|
-
parent: prevNode,
|
549
|
-
depth: prevNode === null ? 0 : prevNode.depth + 1,
|
550
|
-
context: context,
|
551
|
-
parentValue: prevValue,
|
552
|
-
value: nextValue
|
553
|
-
};
|
554
|
-
currentActiveSnapshot = newNode;
|
555
|
-
return newNode;
|
556
|
-
}
|
557
|
-
function popProvider() {
|
558
|
-
var prevSnapshot = currentActiveSnapshot;
|
559
|
-
|
560
|
-
if (prevSnapshot === null) {
|
561
|
-
throw new Error('Tried to pop a Context at the root of the app. This is a bug in React.');
|
562
|
-
}
|
563
|
-
|
564
|
-
{
|
565
|
-
var value = prevSnapshot.parentValue;
|
566
|
-
|
567
|
-
if (value === REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED) {
|
568
|
-
prevSnapshot.context._currentValue = prevSnapshot.context._defaultValue;
|
569
|
-
} else {
|
570
|
-
prevSnapshot.context._currentValue = value;
|
571
|
-
}
|
572
|
-
}
|
573
|
-
|
574
|
-
return currentActiveSnapshot = prevSnapshot.parent;
|
575
|
-
}
|
576
|
-
function getActiveContext() {
|
577
|
-
return currentActiveSnapshot;
|
578
|
-
}
|
579
|
-
function readContext$1(context) {
|
580
|
-
var value = context._currentValue ;
|
581
|
-
return value;
|
582
|
-
}
|
583
|
-
|
584
|
-
// Corresponds to ReactFiberWakeable and ReactFizzWakeable modules. Generally,
|
585
|
-
// changes to one module should be reflected in the others.
|
586
|
-
// TODO: Rename this module and the corresponding Fiber one to "Thenable"
|
587
|
-
// instead of "Wakeable". Or some other more appropriate name.
|
588
|
-
// An error that is thrown (e.g. by `use`) to trigger Suspense. If we
|
589
|
-
// detect this is caught by userspace, we'll log a warning in development.
|
590
|
-
var SuspenseException = new Error("Suspense Exception: This is not a real error! It's an implementation " + 'detail of `use` to interrupt the current render. You must either ' + 'rethrow it immediately, or move the `use` call outside of the ' + '`try/catch` block. Capturing without rethrowing will lead to ' + 'unexpected behavior.\n\n' + 'To handle async errors, wrap your component in an error boundary, or ' + "call the promise's `.catch` method and pass the result to `use`");
|
591
|
-
function createThenableState() {
|
592
|
-
// The ThenableState is created the first time a component suspends. If it
|
593
|
-
// suspends again, we'll reuse the same state.
|
594
|
-
return [];
|
595
|
-
}
|
596
|
-
|
597
|
-
function noop() {}
|
598
|
-
|
599
|
-
function trackUsedThenable(thenableState, thenable, index) {
|
600
|
-
var previous = thenableState[index];
|
601
|
-
|
602
|
-
if (previous === undefined) {
|
603
|
-
thenableState.push(thenable);
|
604
|
-
} else {
|
605
|
-
if (previous !== thenable) {
|
606
|
-
// Reuse the previous thenable, and drop the new one. We can assume
|
607
|
-
// they represent the same value, because components are idempotent.
|
608
|
-
// Avoid an unhandled rejection errors for the Promises that we'll
|
609
|
-
// intentionally ignore.
|
610
|
-
thenable.then(noop, noop);
|
611
|
-
thenable = previous;
|
612
|
-
}
|
613
|
-
} // We use an expando to track the status and result of a thenable so that we
|
614
|
-
// can synchronously unwrap the value. Think of this as an extension of the
|
615
|
-
// Promise API, or a custom interface that is a superset of Thenable.
|
616
|
-
//
|
617
|
-
// If the thenable doesn't have a status, set it to "pending" and attach
|
618
|
-
// a listener that will update its status and result when it resolves.
|
619
|
-
|
620
|
-
|
621
|
-
switch (thenable.status) {
|
622
|
-
case 'fulfilled':
|
623
|
-
{
|
624
|
-
var fulfilledValue = thenable.value;
|
625
|
-
return fulfilledValue;
|
626
|
-
}
|
627
|
-
|
628
|
-
case 'rejected':
|
629
|
-
{
|
630
|
-
var rejectedError = thenable.reason;
|
631
|
-
throw rejectedError;
|
632
|
-
}
|
633
|
-
|
634
|
-
default:
|
635
|
-
{
|
636
|
-
if (typeof thenable.status === 'string') ; else {
|
637
|
-
var pendingThenable = thenable;
|
638
|
-
pendingThenable.status = 'pending';
|
639
|
-
pendingThenable.then(function (fulfilledValue) {
|
640
|
-
if (thenable.status === 'pending') {
|
641
|
-
var fulfilledThenable = thenable;
|
642
|
-
fulfilledThenable.status = 'fulfilled';
|
643
|
-
fulfilledThenable.value = fulfilledValue;
|
644
|
-
}
|
645
|
-
}, function (error) {
|
646
|
-
if (thenable.status === 'pending') {
|
647
|
-
var rejectedThenable = thenable;
|
648
|
-
rejectedThenable.status = 'rejected';
|
649
|
-
rejectedThenable.reason = error;
|
650
|
-
}
|
651
|
-
}); // Check one more time in case the thenable resolved synchronously
|
652
|
-
|
653
|
-
switch (thenable.status) {
|
654
|
-
case 'fulfilled':
|
655
|
-
{
|
656
|
-
var fulfilledThenable = thenable;
|
657
|
-
return fulfilledThenable.value;
|
658
|
-
}
|
659
|
-
|
660
|
-
case 'rejected':
|
661
|
-
{
|
662
|
-
var rejectedThenable = thenable;
|
663
|
-
throw rejectedThenable.reason;
|
664
|
-
}
|
665
|
-
}
|
666
|
-
} // Suspend.
|
667
|
-
//
|
668
|
-
// Throwing here is an implementation detail that allows us to unwind the
|
669
|
-
// call stack. But we shouldn't allow it to leak into userspace. Throw an
|
670
|
-
// opaque placeholder value instead of the actual thenable. If it doesn't
|
671
|
-
// get captured by the work loop, log a warning, because that means
|
672
|
-
// something in userspace must have caught it.
|
673
|
-
|
674
|
-
|
675
|
-
suspendedThenable = thenable;
|
676
|
-
throw SuspenseException;
|
677
|
-
}
|
678
|
-
}
|
679
|
-
} // This is used to track the actual thenable that suspended so it can be
|
680
|
-
// passed to the rest of the Suspense implementation — which, for historical
|
681
|
-
// reasons, expects to receive a thenable.
|
682
|
-
|
683
|
-
var suspendedThenable = null;
|
684
|
-
function getSuspendedThenable() {
|
685
|
-
// This is called right after `use` suspends by throwing an exception. `use`
|
686
|
-
// throws an opaque value instead of the thenable itself so that it can't be
|
687
|
-
// caught in userspace. Then the work loop accesses the actual thenable using
|
688
|
-
// this function.
|
689
|
-
if (suspendedThenable === null) {
|
690
|
-
throw new Error('Expected a suspended thenable. This is a bug in React. Please file ' + 'an issue.');
|
691
|
-
}
|
692
|
-
|
693
|
-
var thenable = suspendedThenable;
|
694
|
-
suspendedThenable = null;
|
695
|
-
return thenable;
|
696
|
-
}
|
697
|
-
|
698
|
-
var currentRequest$1 = null;
|
699
|
-
var thenableIndexCounter = 0;
|
700
|
-
var thenableState = null;
|
701
|
-
function prepareToUseHooksForRequest(request) {
|
702
|
-
currentRequest$1 = request;
|
703
|
-
}
|
704
|
-
function resetHooksForRequest() {
|
705
|
-
currentRequest$1 = null;
|
706
|
-
}
|
707
|
-
function prepareToUseHooksForComponent(prevThenableState) {
|
708
|
-
thenableIndexCounter = 0;
|
709
|
-
thenableState = prevThenableState;
|
710
|
-
}
|
711
|
-
function getThenableStateAfterSuspending() {
|
712
|
-
var state = thenableState;
|
713
|
-
thenableState = null;
|
714
|
-
return state;
|
715
|
-
}
|
716
|
-
|
717
|
-
function readContext(context) {
|
718
|
-
{
|
719
|
-
if (context.$$typeof !== REACT_SERVER_CONTEXT_TYPE) {
|
720
|
-
if (isClientReference(context)) {
|
721
|
-
error('Cannot read a Client Context from a Server Component.');
|
722
|
-
} else {
|
723
|
-
error('Only createServerContext is supported in Server Components.');
|
724
|
-
}
|
725
|
-
}
|
726
|
-
|
727
|
-
if (currentRequest$1 === null) {
|
728
|
-
error('Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
|
729
|
-
}
|
730
|
-
}
|
731
|
-
|
732
|
-
return readContext$1(context);
|
733
|
-
}
|
734
|
-
|
735
|
-
var HooksDispatcher = {
|
736
|
-
useMemo: function (nextCreate) {
|
737
|
-
return nextCreate();
|
738
|
-
},
|
739
|
-
useCallback: function (callback) {
|
740
|
-
return callback;
|
741
|
-
},
|
742
|
-
useDebugValue: function () {},
|
743
|
-
useDeferredValue: unsupportedHook,
|
744
|
-
useTransition: unsupportedHook,
|
745
|
-
readContext: readContext,
|
746
|
-
useContext: readContext,
|
747
|
-
useReducer: unsupportedHook,
|
748
|
-
useRef: unsupportedHook,
|
749
|
-
useState: unsupportedHook,
|
750
|
-
useInsertionEffect: unsupportedHook,
|
751
|
-
useLayoutEffect: unsupportedHook,
|
752
|
-
useImperativeHandle: unsupportedHook,
|
753
|
-
useEffect: unsupportedHook,
|
754
|
-
useId: useId,
|
755
|
-
useMutableSource: unsupportedHook,
|
756
|
-
useSyncExternalStore: unsupportedHook,
|
757
|
-
useCacheRefresh: function () {
|
758
|
-
return unsupportedRefresh;
|
759
|
-
},
|
760
|
-
useMemoCache: function (size) {
|
761
|
-
var data = new Array(size);
|
762
|
-
|
763
|
-
for (var i = 0; i < size; i++) {
|
764
|
-
data[i] = REACT_MEMO_CACHE_SENTINEL;
|
765
|
-
}
|
766
|
-
|
767
|
-
return data;
|
768
|
-
},
|
769
|
-
use: use
|
770
|
-
};
|
771
|
-
|
772
|
-
function unsupportedHook() {
|
773
|
-
throw new Error('This Hook is not supported in Server Components.');
|
774
|
-
}
|
775
|
-
|
776
|
-
function unsupportedRefresh() {
|
777
|
-
throw new Error('Refreshing the cache is not supported in Server Components.');
|
778
|
-
}
|
779
|
-
|
780
|
-
function useId() {
|
781
|
-
if (currentRequest$1 === null) {
|
782
|
-
throw new Error('useId can only be used while React is rendering');
|
783
|
-
}
|
784
|
-
|
785
|
-
var id = currentRequest$1.identifierCount++; // use 'S' for Flight components to distinguish from 'R' and 'r' in Fizz/Client
|
786
|
-
|
787
|
-
return ':' + currentRequest$1.identifierPrefix + 'S' + id.toString(32) + ':';
|
788
|
-
}
|
789
|
-
|
790
|
-
function use(usable) {
|
791
|
-
if (usable !== null && typeof usable === 'object' || typeof usable === 'function') {
|
792
|
-
// $FlowFixMe[method-unbinding]
|
793
|
-
if (typeof usable.then === 'function') {
|
794
|
-
// This is a thenable.
|
795
|
-
var thenable = usable; // Track the position of the thenable within this fiber.
|
796
|
-
|
797
|
-
var index = thenableIndexCounter;
|
798
|
-
thenableIndexCounter += 1;
|
799
|
-
|
800
|
-
if (thenableState === null) {
|
801
|
-
thenableState = createThenableState();
|
802
|
-
}
|
803
|
-
|
804
|
-
return trackUsedThenable(thenableState, thenable, index);
|
805
|
-
} else if (usable.$$typeof === REACT_SERVER_CONTEXT_TYPE) {
|
806
|
-
var context = usable;
|
807
|
-
return readContext(context);
|
808
|
-
}
|
809
|
-
}
|
810
|
-
|
811
|
-
{
|
812
|
-
if (isClientReference(usable)) {
|
813
|
-
error('Cannot use() an already resolved Client Reference.');
|
814
|
-
}
|
815
|
-
} // eslint-disable-next-line react-internal/safe-string-coercion
|
816
|
-
|
817
|
-
|
818
|
-
throw new Error('An unsupported type was passed to use(): ' + String(usable));
|
819
|
-
}
|
820
|
-
|
821
|
-
function createSignal() {
|
822
|
-
return new AbortController().signal;
|
823
|
-
}
|
824
|
-
|
825
|
-
function resolveCache() {
|
826
|
-
var request = resolveRequest();
|
827
|
-
|
828
|
-
if (request) {
|
829
|
-
return getCache(request);
|
830
|
-
}
|
831
|
-
|
832
|
-
return new Map();
|
833
|
-
}
|
834
|
-
|
835
|
-
var DefaultCacheDispatcher = {
|
836
|
-
getCacheSignal: function () {
|
837
|
-
var cache = resolveCache();
|
838
|
-
var entry = cache.get(createSignal);
|
839
|
-
|
840
|
-
if (entry === undefined) {
|
841
|
-
entry = createSignal();
|
842
|
-
cache.set(createSignal, entry);
|
843
|
-
}
|
844
|
-
|
845
|
-
return entry;
|
846
|
-
},
|
847
|
-
getCacheForType: function (resourceType) {
|
848
|
-
var cache = resolveCache();
|
849
|
-
var entry = cache.get(resourceType);
|
850
|
-
|
851
|
-
if (entry === undefined) {
|
852
|
-
entry = resourceType(); // TODO: Warn if undefined?
|
853
|
-
|
854
|
-
cache.set(resourceType, entry);
|
855
|
-
}
|
856
|
-
|
857
|
-
return entry;
|
858
|
-
}
|
859
|
-
};
|
860
|
-
|
861
|
-
var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
|
862
|
-
|
863
|
-
function isArray(a) {
|
864
|
-
return isArrayImpl(a);
|
865
|
-
}
|
866
|
-
|
867
|
-
// in case they error.
|
868
|
-
|
869
|
-
var jsxPropsParents = new WeakMap();
|
870
|
-
var jsxChildrenParents = new WeakMap();
|
871
|
-
|
872
|
-
function isObjectPrototype(object) {
|
873
|
-
if (!object) {
|
874
|
-
return false;
|
875
|
-
}
|
876
|
-
|
877
|
-
var ObjectPrototype = Object.prototype;
|
878
|
-
|
879
|
-
if (object === ObjectPrototype) {
|
880
|
-
return true;
|
881
|
-
} // It might be an object from a different Realm which is
|
882
|
-
// still just a plain simple object.
|
883
|
-
|
884
|
-
|
885
|
-
if (Object.getPrototypeOf(object)) {
|
886
|
-
return false;
|
887
|
-
}
|
888
|
-
|
889
|
-
var names = Object.getOwnPropertyNames(object);
|
890
|
-
|
891
|
-
for (var i = 0; i < names.length; i++) {
|
892
|
-
if (!(names[i] in ObjectPrototype)) {
|
893
|
-
return false;
|
894
|
-
}
|
895
|
-
}
|
896
|
-
|
897
|
-
return true;
|
898
|
-
}
|
899
|
-
|
900
|
-
function isSimpleObject(object) {
|
901
|
-
if (!isObjectPrototype(Object.getPrototypeOf(object))) {
|
902
|
-
return false;
|
903
|
-
}
|
904
|
-
|
905
|
-
var names = Object.getOwnPropertyNames(object);
|
906
|
-
|
907
|
-
for (var i = 0; i < names.length; i++) {
|
908
|
-
var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
|
909
|
-
|
910
|
-
if (!descriptor) {
|
911
|
-
return false;
|
912
|
-
}
|
913
|
-
|
914
|
-
if (!descriptor.enumerable) {
|
915
|
-
if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
|
916
|
-
// React adds key and ref getters to props objects to issue warnings.
|
917
|
-
// Those getters will not be transferred to the client, but that's ok,
|
918
|
-
// so we'll special case them.
|
919
|
-
continue;
|
920
|
-
}
|
921
|
-
|
922
|
-
return false;
|
923
|
-
}
|
924
|
-
}
|
925
|
-
|
926
|
-
return true;
|
927
|
-
}
|
928
|
-
function objectName(object) {
|
929
|
-
// $FlowFixMe[method-unbinding]
|
930
|
-
var name = Object.prototype.toString.call(object);
|
931
|
-
return name.replace(/^\[object (.*)\]$/, function (m, p0) {
|
932
|
-
return p0;
|
933
|
-
});
|
934
|
-
}
|
935
|
-
|
936
|
-
function describeKeyForErrorMessage(key) {
|
937
|
-
var encodedKey = JSON.stringify(key);
|
938
|
-
return '"' + key + '"' === encodedKey ? key : encodedKey;
|
939
|
-
}
|
940
|
-
|
941
|
-
function describeValueForErrorMessage(value) {
|
942
|
-
switch (typeof value) {
|
943
|
-
case 'string':
|
944
|
-
{
|
945
|
-
return JSON.stringify(value.length <= 10 ? value : value.slice(0, 10) + '...');
|
946
|
-
}
|
947
|
-
|
948
|
-
case 'object':
|
949
|
-
{
|
950
|
-
if (isArray(value)) {
|
951
|
-
return '[...]';
|
952
|
-
}
|
953
|
-
|
954
|
-
var name = objectName(value);
|
955
|
-
|
956
|
-
if (name === 'Object') {
|
957
|
-
return '{...}';
|
958
|
-
}
|
959
|
-
|
960
|
-
return name;
|
961
|
-
}
|
962
|
-
|
963
|
-
case 'function':
|
964
|
-
return 'function';
|
965
|
-
|
966
|
-
default:
|
967
|
-
// eslint-disable-next-line react-internal/safe-string-coercion
|
968
|
-
return String(value);
|
969
|
-
}
|
970
|
-
}
|
971
|
-
|
972
|
-
function describeElementType(type) {
|
973
|
-
if (typeof type === 'string') {
|
974
|
-
return type;
|
975
|
-
}
|
976
|
-
|
977
|
-
switch (type) {
|
978
|
-
case REACT_SUSPENSE_TYPE:
|
979
|
-
return 'Suspense';
|
980
|
-
|
981
|
-
case REACT_SUSPENSE_LIST_TYPE:
|
982
|
-
return 'SuspenseList';
|
983
|
-
}
|
984
|
-
|
985
|
-
if (typeof type === 'object') {
|
986
|
-
switch (type.$$typeof) {
|
987
|
-
case REACT_FORWARD_REF_TYPE:
|
988
|
-
return describeElementType(type.render);
|
989
|
-
|
990
|
-
case REACT_MEMO_TYPE:
|
991
|
-
return describeElementType(type.type);
|
992
|
-
|
993
|
-
case REACT_LAZY_TYPE:
|
994
|
-
{
|
995
|
-
var lazyComponent = type;
|
996
|
-
var payload = lazyComponent._payload;
|
997
|
-
var init = lazyComponent._init;
|
998
|
-
|
999
|
-
try {
|
1000
|
-
// Lazy may contain any component type so we recursively resolve it.
|
1001
|
-
return describeElementType(init(payload));
|
1002
|
-
} catch (x) {}
|
1003
|
-
}
|
1004
|
-
}
|
1005
|
-
}
|
1006
|
-
|
1007
|
-
return '';
|
1008
|
-
}
|
1009
|
-
|
1010
|
-
function describeObjectForErrorMessage(objectOrArray, expandedName) {
|
1011
|
-
var objKind = objectName(objectOrArray);
|
1012
|
-
|
1013
|
-
if (objKind !== 'Object' && objKind !== 'Array') {
|
1014
|
-
return objKind;
|
1015
|
-
}
|
1016
|
-
|
1017
|
-
var str = '';
|
1018
|
-
var start = -1;
|
1019
|
-
var length = 0;
|
1020
|
-
|
1021
|
-
if (isArray(objectOrArray)) {
|
1022
|
-
if (jsxChildrenParents.has(objectOrArray)) {
|
1023
|
-
// Print JSX Children
|
1024
|
-
var type = jsxChildrenParents.get(objectOrArray);
|
1025
|
-
str = '<' + describeElementType(type) + '>';
|
1026
|
-
var array = objectOrArray;
|
1027
|
-
|
1028
|
-
for (var i = 0; i < array.length; i++) {
|
1029
|
-
var value = array[i];
|
1030
|
-
var substr = void 0;
|
1031
|
-
|
1032
|
-
if (typeof value === 'string') {
|
1033
|
-
substr = value;
|
1034
|
-
} else if (typeof value === 'object' && value !== null) {
|
1035
|
-
// $FlowFixMe[incompatible-call] found when upgrading Flow
|
1036
|
-
substr = '{' + describeObjectForErrorMessage(value) + '}';
|
1037
|
-
} else {
|
1038
|
-
substr = '{' + describeValueForErrorMessage(value) + '}';
|
1039
|
-
}
|
1040
|
-
|
1041
|
-
if ('' + i === expandedName) {
|
1042
|
-
start = str.length;
|
1043
|
-
length = substr.length;
|
1044
|
-
str += substr;
|
1045
|
-
} else if (substr.length < 15 && str.length + substr.length < 40) {
|
1046
|
-
str += substr;
|
1047
|
-
} else {
|
1048
|
-
str += '{...}';
|
1049
|
-
}
|
1050
|
-
}
|
1051
|
-
|
1052
|
-
str += '</' + describeElementType(type) + '>';
|
1053
|
-
} else {
|
1054
|
-
// Print Array
|
1055
|
-
str = '[';
|
1056
|
-
var _array = objectOrArray;
|
1057
|
-
|
1058
|
-
for (var _i = 0; _i < _array.length; _i++) {
|
1059
|
-
if (_i > 0) {
|
1060
|
-
str += ', ';
|
1061
|
-
}
|
1062
|
-
|
1063
|
-
var _value = _array[_i];
|
1064
|
-
|
1065
|
-
var _substr = void 0;
|
1066
|
-
|
1067
|
-
if (typeof _value === 'object' && _value !== null) {
|
1068
|
-
// $FlowFixMe[incompatible-call] found when upgrading Flow
|
1069
|
-
_substr = describeObjectForErrorMessage(_value);
|
1070
|
-
} else {
|
1071
|
-
_substr = describeValueForErrorMessage(_value);
|
1072
|
-
}
|
1073
|
-
|
1074
|
-
if ('' + _i === expandedName) {
|
1075
|
-
start = str.length;
|
1076
|
-
length = _substr.length;
|
1077
|
-
str += _substr;
|
1078
|
-
} else if (_substr.length < 10 && str.length + _substr.length < 40) {
|
1079
|
-
str += _substr;
|
1080
|
-
} else {
|
1081
|
-
str += '...';
|
1082
|
-
}
|
1083
|
-
}
|
1084
|
-
|
1085
|
-
str += ']';
|
1086
|
-
}
|
1087
|
-
} else {
|
1088
|
-
if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
|
1089
|
-
str = '<' + describeElementType(objectOrArray.type) + '/>';
|
1090
|
-
} else if (jsxPropsParents.has(objectOrArray)) {
|
1091
|
-
// Print JSX
|
1092
|
-
var _type = jsxPropsParents.get(objectOrArray);
|
1093
|
-
|
1094
|
-
str = '<' + (describeElementType(_type) || '...');
|
1095
|
-
var object = objectOrArray;
|
1096
|
-
var names = Object.keys(object);
|
1097
|
-
|
1098
|
-
for (var _i2 = 0; _i2 < names.length; _i2++) {
|
1099
|
-
str += ' ';
|
1100
|
-
var name = names[_i2];
|
1101
|
-
str += describeKeyForErrorMessage(name) + '=';
|
1102
|
-
var _value2 = object[name];
|
1103
|
-
|
1104
|
-
var _substr2 = void 0;
|
1105
|
-
|
1106
|
-
if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
|
1107
|
-
// $FlowFixMe[incompatible-call] found when upgrading Flow
|
1108
|
-
_substr2 = describeObjectForErrorMessage(_value2);
|
1109
|
-
} else {
|
1110
|
-
_substr2 = describeValueForErrorMessage(_value2);
|
1111
|
-
}
|
1112
|
-
|
1113
|
-
if (typeof _value2 !== 'string') {
|
1114
|
-
_substr2 = '{' + _substr2 + '}';
|
1115
|
-
}
|
1116
|
-
|
1117
|
-
if (name === expandedName) {
|
1118
|
-
start = str.length;
|
1119
|
-
length = _substr2.length;
|
1120
|
-
str += _substr2;
|
1121
|
-
} else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
|
1122
|
-
str += _substr2;
|
1123
|
-
} else {
|
1124
|
-
str += '...';
|
1125
|
-
}
|
1126
|
-
}
|
1127
|
-
|
1128
|
-
str += '>';
|
1129
|
-
} else {
|
1130
|
-
// Print Object
|
1131
|
-
str = '{';
|
1132
|
-
var _object = objectOrArray;
|
1133
|
-
|
1134
|
-
var _names = Object.keys(_object);
|
1135
|
-
|
1136
|
-
for (var _i3 = 0; _i3 < _names.length; _i3++) {
|
1137
|
-
if (_i3 > 0) {
|
1138
|
-
str += ', ';
|
1139
|
-
}
|
1140
|
-
|
1141
|
-
var _name = _names[_i3];
|
1142
|
-
str += describeKeyForErrorMessage(_name) + ': ';
|
1143
|
-
var _value3 = _object[_name];
|
1144
|
-
|
1145
|
-
var _substr3 = void 0;
|
1146
|
-
|
1147
|
-
if (typeof _value3 === 'object' && _value3 !== null) {
|
1148
|
-
// $FlowFixMe[incompatible-call] found when upgrading Flow
|
1149
|
-
_substr3 = describeObjectForErrorMessage(_value3);
|
1150
|
-
} else {
|
1151
|
-
_substr3 = describeValueForErrorMessage(_value3);
|
1152
|
-
}
|
1153
|
-
|
1154
|
-
if (_name === expandedName) {
|
1155
|
-
start = str.length;
|
1156
|
-
length = _substr3.length;
|
1157
|
-
str += _substr3;
|
1158
|
-
} else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
|
1159
|
-
str += _substr3;
|
1160
|
-
} else {
|
1161
|
-
str += '...';
|
1162
|
-
}
|
1163
|
-
}
|
1164
|
-
|
1165
|
-
str += '}';
|
1166
|
-
}
|
1167
|
-
}
|
1168
|
-
|
1169
|
-
if (expandedName === undefined) {
|
1170
|
-
return str;
|
1171
|
-
}
|
1172
|
-
|
1173
|
-
if (start > -1 && length > 0) {
|
1174
|
-
var highlight = ' '.repeat(start) + '^'.repeat(length);
|
1175
|
-
return '\n ' + str + '\n ' + highlight;
|
1176
|
-
}
|
1177
|
-
|
1178
|
-
return '\n ' + str;
|
1179
|
-
}
|
1180
|
-
|
1181
|
-
var ContextRegistry = ReactSharedInternals.ContextRegistry;
|
1182
|
-
function getOrCreateServerContext(globalName) {
|
1183
|
-
if (!ContextRegistry[globalName]) {
|
1184
|
-
ContextRegistry[globalName] = React.createServerContext(globalName, // $FlowFixMe[incompatible-call] function signature doesn't reflect the symbol value
|
1185
|
-
REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
|
1186
|
-
}
|
1187
|
-
|
1188
|
-
return ContextRegistry[globalName];
|
1189
|
-
}
|
1190
|
-
|
1191
|
-
// Thenable<ReactClientValue>
|
1192
|
-
|
1193
|
-
var PENDING$1 = 0;
|
1194
|
-
var COMPLETED = 1;
|
1195
|
-
var ABORTED = 3;
|
1196
|
-
var ERRORED$1 = 4;
|
1197
|
-
var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
|
1198
|
-
var ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
|
1199
|
-
|
1200
|
-
function defaultErrorHandler(error) {
|
1201
|
-
console['error'](error); // Don't transform to our wrapper
|
1202
|
-
}
|
1203
|
-
|
1204
|
-
var OPEN = 0;
|
1205
|
-
var CLOSING = 1;
|
1206
|
-
var CLOSED = 2;
|
1207
|
-
function createRequest(model, bundlerConfig, onError, context, identifierPrefix) {
|
1208
|
-
if (ReactCurrentCache.current !== null && ReactCurrentCache.current !== DefaultCacheDispatcher) {
|
1209
|
-
throw new Error('Currently React only supports one RSC renderer at a time.');
|
1210
|
-
}
|
1211
|
-
|
1212
|
-
prepareHostDispatcher();
|
1213
|
-
ReactCurrentCache.current = DefaultCacheDispatcher;
|
1214
|
-
var abortSet = new Set();
|
1215
|
-
var pingedTasks = [];
|
1216
|
-
var hints = createHints();
|
1217
|
-
var request = {
|
1218
|
-
status: OPEN,
|
1219
|
-
flushScheduled: false,
|
1220
|
-
fatalError: null,
|
1221
|
-
destination: null,
|
1222
|
-
bundlerConfig: bundlerConfig,
|
1223
|
-
cache: new Map(),
|
1224
|
-
nextChunkId: 0,
|
1225
|
-
pendingChunks: 0,
|
1226
|
-
hints: hints,
|
1227
|
-
abortableTasks: abortSet,
|
1228
|
-
pingedTasks: pingedTasks,
|
1229
|
-
completedImportChunks: [],
|
1230
|
-
completedHintChunks: [],
|
1231
|
-
completedJSONChunks: [],
|
1232
|
-
completedErrorChunks: [],
|
1233
|
-
writtenSymbols: new Map(),
|
1234
|
-
writtenClientReferences: new Map(),
|
1235
|
-
writtenServerReferences: new Map(),
|
1236
|
-
writtenProviders: new Map(),
|
1237
|
-
identifierPrefix: identifierPrefix || '',
|
1238
|
-
identifierCount: 1,
|
1239
|
-
onError: onError === undefined ? defaultErrorHandler : onError,
|
1240
|
-
// $FlowFixMe[missing-this-annot]
|
1241
|
-
toJSON: function (key, value) {
|
1242
|
-
return resolveModelToJSON(request, this, key, value);
|
1243
|
-
}
|
1244
|
-
};
|
1245
|
-
request.pendingChunks++;
|
1246
|
-
var rootContext = createRootContext(context);
|
1247
|
-
var rootTask = createTask(request, model, rootContext, abortSet);
|
1248
|
-
pingedTasks.push(rootTask);
|
1249
|
-
return request;
|
1250
|
-
}
|
1251
|
-
var currentRequest = null;
|
1252
|
-
function resolveRequest() {
|
1253
|
-
if (currentRequest) return currentRequest;
|
1254
|
-
|
1255
|
-
return null;
|
1256
|
-
}
|
1257
|
-
|
1258
|
-
function createRootContext(reqContext) {
|
1259
|
-
return importServerContexts(reqContext);
|
1260
|
-
}
|
1261
|
-
|
1262
|
-
var POP = {};
|
1263
|
-
|
1264
|
-
function serializeThenable(request, thenable) {
|
1265
|
-
request.pendingChunks++;
|
1266
|
-
var newTask = createTask(request, null, getActiveContext(), request.abortableTasks);
|
1267
|
-
|
1268
|
-
switch (thenable.status) {
|
1269
|
-
case 'fulfilled':
|
1270
|
-
{
|
1271
|
-
// We have the resolved value, we can go ahead and schedule it for serialization.
|
1272
|
-
newTask.model = thenable.value;
|
1273
|
-
pingTask(request, newTask);
|
1274
|
-
return newTask.id;
|
1275
|
-
}
|
1276
|
-
|
1277
|
-
case 'rejected':
|
1278
|
-
{
|
1279
|
-
var x = thenable.reason;
|
1280
|
-
var digest = logRecoverableError(request, x);
|
1281
|
-
|
1282
|
-
{
|
1283
|
-
var _getErrorMessageAndSt = getErrorMessageAndStackDev(x),
|
1284
|
-
message = _getErrorMessageAndSt.message,
|
1285
|
-
stack = _getErrorMessageAndSt.stack;
|
1286
|
-
|
1287
|
-
emitErrorChunkDev(request, newTask.id, digest, message, stack);
|
1288
|
-
}
|
1289
|
-
|
1290
|
-
return newTask.id;
|
1291
|
-
}
|
1292
|
-
|
1293
|
-
default:
|
1294
|
-
{
|
1295
|
-
if (typeof thenable.status === 'string') {
|
1296
|
-
// Only instrument the thenable if the status if not defined. If
|
1297
|
-
// it's defined, but an unknown value, assume it's been instrumented by
|
1298
|
-
// some custom userspace implementation. We treat it as "pending".
|
1299
|
-
break;
|
1300
|
-
}
|
1301
|
-
|
1302
|
-
var pendingThenable = thenable;
|
1303
|
-
pendingThenable.status = 'pending';
|
1304
|
-
pendingThenable.then(function (fulfilledValue) {
|
1305
|
-
if (thenable.status === 'pending') {
|
1306
|
-
var fulfilledThenable = thenable;
|
1307
|
-
fulfilledThenable.status = 'fulfilled';
|
1308
|
-
fulfilledThenable.value = fulfilledValue;
|
1309
|
-
}
|
1310
|
-
}, function (error) {
|
1311
|
-
if (thenable.status === 'pending') {
|
1312
|
-
var rejectedThenable = thenable;
|
1313
|
-
rejectedThenable.status = 'rejected';
|
1314
|
-
rejectedThenable.reason = error;
|
1315
|
-
}
|
1316
|
-
});
|
1317
|
-
break;
|
1318
|
-
}
|
1319
|
-
}
|
1320
|
-
|
1321
|
-
thenable.then(function (value) {
|
1322
|
-
newTask.model = value;
|
1323
|
-
pingTask(request, newTask);
|
1324
|
-
}, function (reason) {
|
1325
|
-
newTask.status = ERRORED$1; // TODO: We should ideally do this inside performWork so it's scheduled
|
1326
|
-
|
1327
|
-
var digest = logRecoverableError(request, reason);
|
1328
|
-
|
1329
|
-
{
|
1330
|
-
var _getErrorMessageAndSt2 = getErrorMessageAndStackDev(reason),
|
1331
|
-
_message = _getErrorMessageAndSt2.message,
|
1332
|
-
_stack = _getErrorMessageAndSt2.stack;
|
1333
|
-
|
1334
|
-
emitErrorChunkDev(request, newTask.id, digest, _message, _stack);
|
1335
|
-
}
|
1336
|
-
|
1337
|
-
if (request.destination !== null) {
|
1338
|
-
flushCompletedChunks(request, request.destination);
|
1339
|
-
}
|
1340
|
-
});
|
1341
|
-
return newTask.id;
|
1342
|
-
}
|
1343
|
-
|
1344
|
-
function emitHint(request, code, model) {
|
1345
|
-
emitHintChunk(request, code, model);
|
1346
|
-
enqueueFlush(request);
|
1347
|
-
}
|
1348
|
-
function getHints(request) {
|
1349
|
-
return request.hints;
|
1350
|
-
}
|
1351
|
-
function getCache(request) {
|
1352
|
-
return request.cache;
|
1353
|
-
}
|
1354
|
-
|
1355
|
-
function readThenable(thenable) {
|
1356
|
-
if (thenable.status === 'fulfilled') {
|
1357
|
-
return thenable.value;
|
1358
|
-
} else if (thenable.status === 'rejected') {
|
1359
|
-
throw thenable.reason;
|
1360
|
-
}
|
1361
|
-
|
1362
|
-
throw thenable;
|
1363
|
-
}
|
1364
|
-
|
1365
|
-
function createLazyWrapperAroundWakeable(wakeable) {
|
1366
|
-
// This is a temporary fork of the `use` implementation until we accept
|
1367
|
-
// promises everywhere.
|
1368
|
-
var thenable = wakeable;
|
1369
|
-
|
1370
|
-
switch (thenable.status) {
|
1371
|
-
case 'fulfilled':
|
1372
|
-
case 'rejected':
|
1373
|
-
break;
|
1374
|
-
|
1375
|
-
default:
|
1376
|
-
{
|
1377
|
-
if (typeof thenable.status === 'string') {
|
1378
|
-
// Only instrument the thenable if the status if not defined. If
|
1379
|
-
// it's defined, but an unknown value, assume it's been instrumented by
|
1380
|
-
// some custom userspace implementation. We treat it as "pending".
|
1381
|
-
break;
|
1382
|
-
}
|
1383
|
-
|
1384
|
-
var pendingThenable = thenable;
|
1385
|
-
pendingThenable.status = 'pending';
|
1386
|
-
pendingThenable.then(function (fulfilledValue) {
|
1387
|
-
if (thenable.status === 'pending') {
|
1388
|
-
var fulfilledThenable = thenable;
|
1389
|
-
fulfilledThenable.status = 'fulfilled';
|
1390
|
-
fulfilledThenable.value = fulfilledValue;
|
1391
|
-
}
|
1392
|
-
}, function (error) {
|
1393
|
-
if (thenable.status === 'pending') {
|
1394
|
-
var rejectedThenable = thenable;
|
1395
|
-
rejectedThenable.status = 'rejected';
|
1396
|
-
rejectedThenable.reason = error;
|
1397
|
-
}
|
1398
|
-
});
|
1399
|
-
break;
|
1400
|
-
}
|
1401
|
-
}
|
1402
|
-
|
1403
|
-
var lazyType = {
|
1404
|
-
$$typeof: REACT_LAZY_TYPE,
|
1405
|
-
_payload: thenable,
|
1406
|
-
_init: readThenable
|
1407
|
-
};
|
1408
|
-
return lazyType;
|
1409
|
-
}
|
1410
|
-
|
1411
|
-
function attemptResolveElement(request, type, key, ref, props, prevThenableState) {
|
1412
|
-
if (ref !== null && ref !== undefined) {
|
1413
|
-
// When the ref moves to the regular props object this will implicitly
|
1414
|
-
// throw for functions. We could probably relax it to a DEV warning for other
|
1415
|
-
// cases.
|
1416
|
-
throw new Error('Refs cannot be used in Server Components, nor passed to Client Components.');
|
1417
|
-
}
|
1418
|
-
|
1419
|
-
{
|
1420
|
-
jsxPropsParents.set(props, type);
|
1421
|
-
|
1422
|
-
if (typeof props.children === 'object' && props.children !== null) {
|
1423
|
-
jsxChildrenParents.set(props.children, type);
|
1424
|
-
}
|
1425
|
-
}
|
1426
|
-
|
1427
|
-
if (typeof type === 'function') {
|
1428
|
-
if (isClientReference(type)) {
|
1429
|
-
// This is a reference to a Client Component.
|
1430
|
-
return [REACT_ELEMENT_TYPE, type, key, props];
|
1431
|
-
} // This is a server-side component.
|
1432
|
-
|
1433
|
-
|
1434
|
-
prepareToUseHooksForComponent(prevThenableState);
|
1435
|
-
var result = type(props);
|
1436
|
-
|
1437
|
-
if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
|
1438
|
-
// When the return value is in children position we can resolve it immediately,
|
1439
|
-
// to its value without a wrapper if it's synchronously available.
|
1440
|
-
var thenable = result;
|
1441
|
-
|
1442
|
-
if (thenable.status === 'fulfilled') {
|
1443
|
-
return thenable.value;
|
1444
|
-
} // TODO: Once we accept Promises as children on the client, we can just return
|
1445
|
-
// the thenable here.
|
1446
|
-
|
1447
|
-
|
1448
|
-
return createLazyWrapperAroundWakeable(result);
|
1449
|
-
}
|
1450
|
-
|
1451
|
-
return result;
|
1452
|
-
} else if (typeof type === 'string') {
|
1453
|
-
// This is a host element. E.g. HTML.
|
1454
|
-
return [REACT_ELEMENT_TYPE, type, key, props];
|
1455
|
-
} else if (typeof type === 'symbol') {
|
1456
|
-
if (type === REACT_FRAGMENT_TYPE) {
|
1457
|
-
// For key-less fragments, we add a small optimization to avoid serializing
|
1458
|
-
// it as a wrapper.
|
1459
|
-
// TODO: If a key is specified, we should propagate its key to any children.
|
1460
|
-
// Same as if a Server Component has a key.
|
1461
|
-
return props.children;
|
1462
|
-
} // This might be a built-in React component. We'll let the client decide.
|
1463
|
-
// Any built-in works as long as its props are serializable.
|
1464
|
-
|
1465
|
-
|
1466
|
-
return [REACT_ELEMENT_TYPE, type, key, props];
|
1467
|
-
} else if (type != null && typeof type === 'object') {
|
1468
|
-
if (isClientReference(type)) {
|
1469
|
-
// This is a reference to a Client Component.
|
1470
|
-
return [REACT_ELEMENT_TYPE, type, key, props];
|
1471
|
-
}
|
1472
|
-
|
1473
|
-
switch (type.$$typeof) {
|
1474
|
-
case REACT_LAZY_TYPE:
|
1475
|
-
{
|
1476
|
-
var payload = type._payload;
|
1477
|
-
var init = type._init;
|
1478
|
-
var wrappedType = init(payload);
|
1479
|
-
return attemptResolveElement(request, wrappedType, key, ref, props, prevThenableState);
|
1480
|
-
}
|
1481
|
-
|
1482
|
-
case REACT_FORWARD_REF_TYPE:
|
1483
|
-
{
|
1484
|
-
var render = type.render;
|
1485
|
-
prepareToUseHooksForComponent(prevThenableState);
|
1486
|
-
return render(props, undefined);
|
1487
|
-
}
|
1488
|
-
|
1489
|
-
case REACT_MEMO_TYPE:
|
1490
|
-
{
|
1491
|
-
return attemptResolveElement(request, type.type, key, ref, props, prevThenableState);
|
1492
|
-
}
|
1493
|
-
|
1494
|
-
case REACT_PROVIDER_TYPE:
|
1495
|
-
{
|
1496
|
-
pushProvider(type._context, props.value);
|
1497
|
-
|
1498
|
-
{
|
1499
|
-
var extraKeys = Object.keys(props).filter(function (value) {
|
1500
|
-
if (value === 'children' || value === 'value') {
|
1501
|
-
return false;
|
1502
|
-
}
|
1503
|
-
|
1504
|
-
return true;
|
1505
|
-
});
|
1506
|
-
|
1507
|
-
if (extraKeys.length !== 0) {
|
1508
|
-
error('ServerContext can only have a value prop and children. Found: %s', JSON.stringify(extraKeys));
|
1509
|
-
}
|
1510
|
-
}
|
1511
|
-
|
1512
|
-
return [REACT_ELEMENT_TYPE, type, key, // Rely on __popProvider being serialized last to pop the provider.
|
1513
|
-
{
|
1514
|
-
value: props.value,
|
1515
|
-
children: props.children,
|
1516
|
-
__pop: POP
|
1517
|
-
}];
|
1518
|
-
}
|
1519
|
-
}
|
1520
|
-
}
|
1521
|
-
|
1522
|
-
throw new Error("Unsupported Server Component type: " + describeValueForErrorMessage(type));
|
1523
|
-
}
|
1524
|
-
|
1525
|
-
function pingTask(request, task) {
|
1526
|
-
var pingedTasks = request.pingedTasks;
|
1527
|
-
pingedTasks.push(task);
|
1528
|
-
|
1529
|
-
if (pingedTasks.length === 1) {
|
1530
|
-
request.flushScheduled = request.destination !== null;
|
1531
|
-
scheduleWork(function () {
|
1532
|
-
return performWork(request);
|
1533
|
-
});
|
1534
|
-
}
|
1535
|
-
}
|
1536
|
-
|
1537
|
-
function createTask(request, model, context, abortSet) {
|
1538
|
-
var id = request.nextChunkId++;
|
1539
|
-
var task = {
|
1540
|
-
id: id,
|
1541
|
-
status: PENDING$1,
|
1542
|
-
model: model,
|
1543
|
-
context: context,
|
1544
|
-
ping: function () {
|
1545
|
-
return pingTask(request, task);
|
1546
|
-
},
|
1547
|
-
thenableState: null
|
1548
|
-
};
|
1549
|
-
abortSet.add(task);
|
1550
|
-
return task;
|
1551
|
-
}
|
1552
|
-
|
1553
|
-
function serializeByValueID(id) {
|
1554
|
-
return '$' + id.toString(16);
|
1555
|
-
}
|
1556
|
-
|
1557
|
-
function serializeLazyID(id) {
|
1558
|
-
return '$L' + id.toString(16);
|
1559
|
-
}
|
1560
|
-
|
1561
|
-
function serializePromiseID(id) {
|
1562
|
-
return '$@' + id.toString(16);
|
1563
|
-
}
|
1564
|
-
|
1565
|
-
function serializeServerReferenceID(id) {
|
1566
|
-
return '$F' + id.toString(16);
|
1567
|
-
}
|
1568
|
-
|
1569
|
-
function serializeSymbolReference(name) {
|
1570
|
-
return '$S' + name;
|
1571
|
-
}
|
1572
|
-
|
1573
|
-
function serializeProviderReference(name) {
|
1574
|
-
return '$P' + name;
|
1575
|
-
}
|
1576
|
-
|
1577
|
-
function serializeNumber(number) {
|
1578
|
-
if (Number.isFinite(number)) {
|
1579
|
-
if (number === 0 && 1 / number === -Infinity) {
|
1580
|
-
return '$-0';
|
1581
|
-
} else {
|
1582
|
-
return number;
|
1583
|
-
}
|
1584
|
-
} else {
|
1585
|
-
if (number === Infinity) {
|
1586
|
-
return '$Infinity';
|
1587
|
-
} else if (number === -Infinity) {
|
1588
|
-
return '$-Infinity';
|
1589
|
-
} else {
|
1590
|
-
return '$NaN';
|
1591
|
-
}
|
1592
|
-
}
|
1593
|
-
}
|
1594
|
-
|
1595
|
-
function serializeUndefined() {
|
1596
|
-
return '$undefined';
|
1597
|
-
}
|
1598
|
-
|
1599
|
-
function serializeDateFromDateJSON(dateJSON) {
|
1600
|
-
// JSON.stringify automatically calls Date.prototype.toJSON which calls toISOString.
|
1601
|
-
// We need only tack on a $D prefix.
|
1602
|
-
return '$D' + dateJSON;
|
1603
|
-
}
|
1604
|
-
|
1605
|
-
function serializeBigInt(n) {
|
1606
|
-
return '$n' + n.toString(10);
|
1607
|
-
}
|
1608
|
-
|
1609
|
-
function serializeClientReference(request, parent, key, clientReference) {
|
1610
|
-
var clientReferenceKey = getClientReferenceKey(clientReference);
|
1611
|
-
var writtenClientReferences = request.writtenClientReferences;
|
1612
|
-
var existingId = writtenClientReferences.get(clientReferenceKey);
|
1613
|
-
|
1614
|
-
if (existingId !== undefined) {
|
1615
|
-
if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
|
1616
|
-
// If we're encoding the "type" of an element, we can refer
|
1617
|
-
// to that by a lazy reference instead of directly since React
|
1618
|
-
// knows how to deal with lazy values. This lets us suspend
|
1619
|
-
// on this component rather than its parent until the code has
|
1620
|
-
// loaded.
|
1621
|
-
return serializeLazyID(existingId);
|
1622
|
-
}
|
1623
|
-
|
1624
|
-
return serializeByValueID(existingId);
|
1625
|
-
}
|
1626
|
-
|
1627
|
-
try {
|
1628
|
-
var clientReferenceMetadata = resolveClientReferenceMetadata(request.bundlerConfig, clientReference);
|
1629
|
-
request.pendingChunks++;
|
1630
|
-
var importId = request.nextChunkId++;
|
1631
|
-
emitImportChunk(request, importId, clientReferenceMetadata);
|
1632
|
-
writtenClientReferences.set(clientReferenceKey, importId);
|
1633
|
-
|
1634
|
-
if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
|
1635
|
-
// If we're encoding the "type" of an element, we can refer
|
1636
|
-
// to that by a lazy reference instead of directly since React
|
1637
|
-
// knows how to deal with lazy values. This lets us suspend
|
1638
|
-
// on this component rather than its parent until the code has
|
1639
|
-
// loaded.
|
1640
|
-
return serializeLazyID(importId);
|
1641
|
-
}
|
1642
|
-
|
1643
|
-
return serializeByValueID(importId);
|
1644
|
-
} catch (x) {
|
1645
|
-
request.pendingChunks++;
|
1646
|
-
var errorId = request.nextChunkId++;
|
1647
|
-
var digest = logRecoverableError(request, x);
|
1648
|
-
|
1649
|
-
{
|
1650
|
-
var _getErrorMessageAndSt3 = getErrorMessageAndStackDev(x),
|
1651
|
-
message = _getErrorMessageAndSt3.message,
|
1652
|
-
stack = _getErrorMessageAndSt3.stack;
|
1653
|
-
|
1654
|
-
emitErrorChunkDev(request, errorId, digest, message, stack);
|
1655
|
-
}
|
1656
|
-
|
1657
|
-
return serializeByValueID(errorId);
|
1658
|
-
}
|
1659
|
-
}
|
1660
|
-
|
1661
|
-
function serializeServerReference(request, parent, key, serverReference) {
|
1662
|
-
var writtenServerReferences = request.writtenServerReferences;
|
1663
|
-
var existingId = writtenServerReferences.get(serverReference);
|
1664
|
-
|
1665
|
-
if (existingId !== undefined) {
|
1666
|
-
return serializeServerReferenceID(existingId);
|
1667
|
-
}
|
1668
|
-
|
1669
|
-
var bound = getServerReferenceBoundArguments(request.bundlerConfig, serverReference);
|
1670
|
-
var serverReferenceMetadata = {
|
1671
|
-
id: getServerReferenceId(request.bundlerConfig, serverReference),
|
1672
|
-
bound: bound ? Promise.resolve(bound) : null
|
1673
|
-
};
|
1674
|
-
request.pendingChunks++;
|
1675
|
-
var metadataId = request.nextChunkId++; // We assume that this object doesn't suspend.
|
1676
|
-
|
1677
|
-
var processedChunk = processModelChunk(request, metadataId, serverReferenceMetadata);
|
1678
|
-
request.completedJSONChunks.push(processedChunk);
|
1679
|
-
writtenServerReferences.set(serverReference, metadataId);
|
1680
|
-
return serializeServerReferenceID(metadataId);
|
1681
|
-
}
|
1682
|
-
|
1683
|
-
function escapeStringValue(value) {
|
1684
|
-
if (value[0] === '$') {
|
1685
|
-
// We need to escape $ prefixed strings since we use those to encode
|
1686
|
-
// references to IDs and as special symbol values.
|
1687
|
-
return '$' + value;
|
1688
|
-
} else {
|
1689
|
-
return value;
|
1690
|
-
}
|
1691
|
-
}
|
1692
|
-
|
1693
|
-
var insideContextProps = null;
|
1694
|
-
var isInsideContextValue = false;
|
1695
|
-
function resolveModelToJSON(request, parent, key, value) {
|
1696
|
-
// Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
|
1697
|
-
{
|
1698
|
-
// $FlowFixMe[incompatible-use]
|
1699
|
-
var originalValue = parent[key];
|
1700
|
-
|
1701
|
-
if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
|
1702
|
-
if (objectName(originalValue) !== 'Object') {
|
1703
|
-
var jsxParentType = jsxChildrenParents.get(parent);
|
1704
|
-
|
1705
|
-
if (typeof jsxParentType === 'string') {
|
1706
|
-
error('%s objects cannot be rendered as text children. Try formatting it using toString().%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
|
1707
|
-
} else {
|
1708
|
-
error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
|
1709
|
-
}
|
1710
|
-
} else {
|
1711
|
-
error('Only plain objects can be passed to Client Components from Server Components. ' + 'Objects with toJSON methods are not supported. Convert it manually ' + 'to a simple value before passing it to props.%s', describeObjectForErrorMessage(parent, key));
|
1712
|
-
}
|
1713
|
-
}
|
1714
|
-
} // Special Symbols
|
1715
|
-
|
1716
|
-
|
1717
|
-
switch (value) {
|
1718
|
-
case REACT_ELEMENT_TYPE:
|
1719
|
-
return '$';
|
1720
|
-
}
|
1721
|
-
|
1722
|
-
{
|
1723
|
-
if (parent[0] === REACT_ELEMENT_TYPE && parent[1] && parent[1].$$typeof === REACT_PROVIDER_TYPE && key === '3') {
|
1724
|
-
insideContextProps = value;
|
1725
|
-
} else if (insideContextProps === parent && key === 'value') {
|
1726
|
-
isInsideContextValue = true;
|
1727
|
-
} else if (insideContextProps === parent && key === 'children') {
|
1728
|
-
isInsideContextValue = false;
|
1729
|
-
}
|
1730
|
-
} // Resolve Server Components.
|
1731
|
-
|
1732
|
-
|
1733
|
-
while (typeof value === 'object' && value !== null && (value.$$typeof === REACT_ELEMENT_TYPE || value.$$typeof === REACT_LAZY_TYPE)) {
|
1734
|
-
{
|
1735
|
-
if (isInsideContextValue) {
|
1736
|
-
error('React elements are not allowed in ServerContext');
|
1737
|
-
}
|
1738
|
-
}
|
1739
|
-
|
1740
|
-
try {
|
1741
|
-
switch (value.$$typeof) {
|
1742
|
-
case REACT_ELEMENT_TYPE:
|
1743
|
-
{
|
1744
|
-
// TODO: Concatenate keys of parents onto children.
|
1745
|
-
var element = value; // Attempt to render the Server Component.
|
1746
|
-
|
1747
|
-
value = attemptResolveElement(request, element.type, element.key, element.ref, element.props, null);
|
1748
|
-
break;
|
1749
|
-
}
|
1750
|
-
|
1751
|
-
case REACT_LAZY_TYPE:
|
1752
|
-
{
|
1753
|
-
var payload = value._payload;
|
1754
|
-
var init = value._init;
|
1755
|
-
value = init(payload);
|
1756
|
-
break;
|
1757
|
-
}
|
1758
|
-
}
|
1759
|
-
} catch (thrownValue) {
|
1760
|
-
var x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
|
1761
|
-
// reasons, the rest of the Suspense implementation expects the thrown
|
1762
|
-
// value to be a thenable, because before `use` existed that was the
|
1763
|
-
// (unstable) API for suspending. This implementation detail can change
|
1764
|
-
// later, once we deprecate the old API in favor of `use`.
|
1765
|
-
getSuspendedThenable() : thrownValue; // $FlowFixMe[method-unbinding]
|
1766
|
-
|
1767
|
-
if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
|
1768
|
-
// Something suspended, we'll need to create a new task and resolve it later.
|
1769
|
-
request.pendingChunks++;
|
1770
|
-
var newTask = createTask(request, value, getActiveContext(), request.abortableTasks);
|
1771
|
-
var ping = newTask.ping;
|
1772
|
-
x.then(ping, ping);
|
1773
|
-
newTask.thenableState = getThenableStateAfterSuspending();
|
1774
|
-
return serializeLazyID(newTask.id);
|
1775
|
-
} else {
|
1776
|
-
// Something errored. We'll still send everything we have up until this point.
|
1777
|
-
// We'll replace this element with a lazy reference that throws on the client
|
1778
|
-
// once it gets rendered.
|
1779
|
-
request.pendingChunks++;
|
1780
|
-
var errorId = request.nextChunkId++;
|
1781
|
-
var digest = logRecoverableError(request, x);
|
1782
|
-
|
1783
|
-
{
|
1784
|
-
var _getErrorMessageAndSt4 = getErrorMessageAndStackDev(x),
|
1785
|
-
message = _getErrorMessageAndSt4.message,
|
1786
|
-
stack = _getErrorMessageAndSt4.stack;
|
1787
|
-
|
1788
|
-
emitErrorChunkDev(request, errorId, digest, message, stack);
|
1789
|
-
}
|
1790
|
-
|
1791
|
-
return serializeLazyID(errorId);
|
1792
|
-
}
|
1793
|
-
}
|
1794
|
-
}
|
1795
|
-
|
1796
|
-
if (value === null) {
|
1797
|
-
return null;
|
1798
|
-
}
|
1799
|
-
|
1800
|
-
if (typeof value === 'object') {
|
1801
|
-
if (isClientReference(value)) {
|
1802
|
-
return serializeClientReference(request, parent, key, value); // $FlowFixMe[method-unbinding]
|
1803
|
-
} else if (typeof value.then === 'function') {
|
1804
|
-
// We assume that any object with a .then property is a "Thenable" type,
|
1805
|
-
// or a Promise type. Either of which can be represented by a Promise.
|
1806
|
-
var promiseId = serializeThenable(request, value);
|
1807
|
-
return serializePromiseID(promiseId);
|
1808
|
-
} else if (value.$$typeof === REACT_PROVIDER_TYPE) {
|
1809
|
-
var providerKey = value._context._globalName;
|
1810
|
-
var writtenProviders = request.writtenProviders;
|
1811
|
-
var providerId = writtenProviders.get(key);
|
1812
|
-
|
1813
|
-
if (providerId === undefined) {
|
1814
|
-
request.pendingChunks++;
|
1815
|
-
providerId = request.nextChunkId++;
|
1816
|
-
writtenProviders.set(providerKey, providerId);
|
1817
|
-
emitProviderChunk(request, providerId, providerKey);
|
1818
|
-
}
|
1819
|
-
|
1820
|
-
return serializeByValueID(providerId);
|
1821
|
-
} else if (value === POP) {
|
1822
|
-
popProvider();
|
1823
|
-
|
1824
|
-
{
|
1825
|
-
insideContextProps = null;
|
1826
|
-
isInsideContextValue = false;
|
1827
|
-
}
|
1828
|
-
|
1829
|
-
return undefined;
|
1830
|
-
}
|
1831
|
-
|
1832
|
-
if (!isArray(value)) {
|
1833
|
-
var iteratorFn = getIteratorFn(value);
|
1834
|
-
|
1835
|
-
if (iteratorFn) {
|
1836
|
-
return Array.from(value);
|
1837
|
-
}
|
1838
|
-
}
|
1839
|
-
|
1840
|
-
{
|
1841
|
-
if (value !== null && !isArray(value)) {
|
1842
|
-
// Verify that this is a simple plain object.
|
1843
|
-
if (objectName(value) !== 'Object') {
|
1844
|
-
error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
|
1845
|
-
} else if (!isSimpleObject(value)) {
|
1846
|
-
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));
|
1847
|
-
} else if (Object.getOwnPropertySymbols) {
|
1848
|
-
var symbols = Object.getOwnPropertySymbols(value);
|
1849
|
-
|
1850
|
-
if (symbols.length > 0) {
|
1851
|
-
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));
|
1852
|
-
}
|
1853
|
-
}
|
1854
|
-
}
|
1855
|
-
} // $FlowFixMe[incompatible-return]
|
1856
|
-
|
1857
|
-
|
1858
|
-
return value;
|
1859
|
-
}
|
1860
|
-
|
1861
|
-
if (typeof value === 'string') {
|
1862
|
-
// TODO: Maybe too clever. If we support URL there's no similar trick.
|
1863
|
-
if (value[value.length - 1] === 'Z') {
|
1864
|
-
// Possibly a Date, whose toJSON automatically calls toISOString
|
1865
|
-
// $FlowFixMe[incompatible-use]
|
1866
|
-
var _originalValue = parent[key]; // $FlowFixMe[method-unbinding]
|
1867
|
-
|
1868
|
-
if (_originalValue instanceof Date) {
|
1869
|
-
return serializeDateFromDateJSON(value);
|
1870
|
-
}
|
1871
|
-
}
|
1872
|
-
|
1873
|
-
return escapeStringValue(value);
|
1874
|
-
}
|
1875
|
-
|
1876
|
-
if (typeof value === 'boolean') {
|
1877
|
-
return value;
|
1878
|
-
}
|
1879
|
-
|
1880
|
-
if (typeof value === 'number') {
|
1881
|
-
return serializeNumber(value);
|
1882
|
-
}
|
1883
|
-
|
1884
|
-
if (typeof value === 'undefined') {
|
1885
|
-
return serializeUndefined();
|
1886
|
-
}
|
1887
|
-
|
1888
|
-
if (typeof value === 'function') {
|
1889
|
-
if (isClientReference(value)) {
|
1890
|
-
return serializeClientReference(request, parent, key, value);
|
1891
|
-
}
|
1892
|
-
|
1893
|
-
if (isServerReference(value)) {
|
1894
|
-
return serializeServerReference(request, parent, key, value);
|
1895
|
-
}
|
1896
|
-
|
1897
|
-
if (/^on[A-Z]/.test(key)) {
|
1898
|
-
throw new Error('Event handlers cannot be passed to Client Component props.' + describeObjectForErrorMessage(parent, key) + '\nIf you need interactivity, consider converting part of this to a Client Component.');
|
1899
|
-
} else {
|
1900
|
-
throw new Error('Functions cannot be passed directly to Client Components ' + 'unless you explicitly expose it by marking it with "use server".' + describeObjectForErrorMessage(parent, key));
|
1901
|
-
}
|
1902
|
-
}
|
1903
|
-
|
1904
|
-
if (typeof value === 'symbol') {
|
1905
|
-
var writtenSymbols = request.writtenSymbols;
|
1906
|
-
var existingId = writtenSymbols.get(value);
|
1907
|
-
|
1908
|
-
if (existingId !== undefined) {
|
1909
|
-
return serializeByValueID(existingId);
|
1910
|
-
} // $FlowFixMe[incompatible-type] `description` might be undefined
|
1911
|
-
|
1912
|
-
|
1913
|
-
var name = value.description;
|
1914
|
-
|
1915
|
-
if (Symbol.for(name) !== value) {
|
1916
|
-
throw new Error('Only global symbols received from Symbol.for(...) can be passed to Client Components. ' + ("The symbol Symbol.for(" + // $FlowFixMe[incompatible-type] `description` might be undefined
|
1917
|
-
value.description + ") cannot be found among global symbols.") + describeObjectForErrorMessage(parent, key));
|
1918
|
-
}
|
1919
|
-
|
1920
|
-
request.pendingChunks++;
|
1921
|
-
var symbolId = request.nextChunkId++;
|
1922
|
-
emitSymbolChunk(request, symbolId, name);
|
1923
|
-
writtenSymbols.set(value, symbolId);
|
1924
|
-
return serializeByValueID(symbolId);
|
1925
|
-
}
|
1926
|
-
|
1927
|
-
if (typeof value === 'bigint') {
|
1928
|
-
return serializeBigInt(value);
|
1929
|
-
}
|
1930
|
-
|
1931
|
-
throw new Error("Type " + typeof value + " is not supported in Client Component props." + describeObjectForErrorMessage(parent, key));
|
1932
|
-
}
|
1933
|
-
|
1934
|
-
function logRecoverableError(request, error) {
|
1935
|
-
var onError = request.onError;
|
1936
|
-
var errorDigest = onError(error);
|
1937
|
-
|
1938
|
-
if (errorDigest != null && typeof errorDigest !== 'string') {
|
1939
|
-
// eslint-disable-next-line react-internal/prod-error-codes
|
1940
|
-
throw new Error("onError returned something with a type other than \"string\". onError should return a string and may return null or undefined but must not return anything else. It received something of type \"" + typeof errorDigest + "\" instead");
|
1941
|
-
}
|
1942
|
-
|
1943
|
-
return errorDigest || '';
|
1944
|
-
}
|
1945
|
-
|
1946
|
-
function getErrorMessageAndStackDev(error) {
|
1947
|
-
{
|
1948
|
-
var message;
|
1949
|
-
var stack = '';
|
1950
|
-
|
1951
|
-
try {
|
1952
|
-
if (error instanceof Error) {
|
1953
|
-
// eslint-disable-next-line react-internal/safe-string-coercion
|
1954
|
-
message = String(error.message); // eslint-disable-next-line react-internal/safe-string-coercion
|
1955
|
-
|
1956
|
-
stack = String(error.stack);
|
1957
|
-
} else {
|
1958
|
-
message = 'Error: ' + error;
|
1959
|
-
}
|
1960
|
-
} catch (x) {
|
1961
|
-
message = 'An error occurred but serializing the error message failed.';
|
1962
|
-
}
|
1963
|
-
|
1964
|
-
return {
|
1965
|
-
message: message,
|
1966
|
-
stack: stack
|
1967
|
-
};
|
1968
|
-
}
|
1969
|
-
}
|
1970
|
-
|
1971
|
-
function fatalError(request, error) {
|
1972
|
-
// This is called outside error handling code such as if an error happens in React internals.
|
1973
|
-
if (request.destination !== null) {
|
1974
|
-
request.status = CLOSED;
|
1975
|
-
closeWithError(request.destination, error);
|
1976
|
-
} else {
|
1977
|
-
request.status = CLOSING;
|
1978
|
-
request.fatalError = error;
|
1979
|
-
}
|
1980
|
-
}
|
1981
|
-
|
1982
|
-
function emitErrorChunkProd(request, id, digest) {
|
1983
|
-
var processedChunk = processErrorChunkProd();
|
1984
|
-
request.completedErrorChunks.push(processedChunk);
|
1985
|
-
}
|
1986
|
-
|
1987
|
-
function emitErrorChunkDev(request, id, digest, message, stack) {
|
1988
|
-
var processedChunk = processErrorChunkDev(request, id, digest, message, stack);
|
1989
|
-
request.completedErrorChunks.push(processedChunk);
|
1990
|
-
}
|
1991
|
-
|
1992
|
-
function emitImportChunk(request, id, clientReferenceMetadata) {
|
1993
|
-
var processedChunk = processImportChunk(request, id, clientReferenceMetadata);
|
1994
|
-
request.completedImportChunks.push(processedChunk);
|
1995
|
-
}
|
1996
|
-
|
1997
|
-
function emitHintChunk(request, code, model) {
|
1998
|
-
var processedChunk = processHintChunk(request, request.nextChunkId++, code, model);
|
1999
|
-
request.completedHintChunks.push(processedChunk);
|
2000
|
-
}
|
2001
|
-
|
2002
|
-
function emitSymbolChunk(request, id, name) {
|
2003
|
-
var symbolReference = serializeSymbolReference(name);
|
2004
|
-
var processedChunk = processReferenceChunk(request, id, symbolReference);
|
2005
|
-
request.completedImportChunks.push(processedChunk);
|
2006
|
-
}
|
2007
|
-
|
2008
|
-
function emitProviderChunk(request, id, contextName) {
|
2009
|
-
var contextReference = serializeProviderReference(contextName);
|
2010
|
-
var processedChunk = processReferenceChunk(request, id, contextReference);
|
2011
|
-
request.completedJSONChunks.push(processedChunk);
|
2012
|
-
}
|
2013
|
-
|
2014
|
-
function retryTask(request, task) {
|
2015
|
-
if (task.status !== PENDING$1) {
|
2016
|
-
// We completed this by other means before we had a chance to retry it.
|
2017
|
-
return;
|
2018
|
-
}
|
2019
|
-
|
2020
|
-
switchContext(task.context);
|
2021
|
-
|
2022
|
-
try {
|
2023
|
-
var value = task.model;
|
2024
|
-
|
2025
|
-
if (typeof value === 'object' && value !== null && value.$$typeof === REACT_ELEMENT_TYPE) {
|
2026
|
-
// TODO: Concatenate keys of parents onto children.
|
2027
|
-
var element = value; // When retrying a component, reuse the thenableState from the
|
2028
|
-
// previous attempt.
|
2029
|
-
|
2030
|
-
var prevThenableState = task.thenableState; // Attempt to render the Server Component.
|
2031
|
-
// Doing this here lets us reuse this same task if the next component
|
2032
|
-
// also suspends.
|
2033
|
-
|
2034
|
-
task.model = value;
|
2035
|
-
value = attemptResolveElement(request, element.type, element.key, element.ref, element.props, prevThenableState); // Successfully finished this component. We're going to keep rendering
|
2036
|
-
// using the same task, but we reset its thenable state before continuing.
|
2037
|
-
|
2038
|
-
task.thenableState = null; // Keep rendering and reuse the same task. This inner loop is separate
|
2039
|
-
// from the render above because we don't need to reset the thenable state
|
2040
|
-
// until the next time something suspends and retries.
|
2041
|
-
|
2042
|
-
while (typeof value === 'object' && value !== null && value.$$typeof === REACT_ELEMENT_TYPE) {
|
2043
|
-
// TODO: Concatenate keys of parents onto children.
|
2044
|
-
var nextElement = value;
|
2045
|
-
task.model = value;
|
2046
|
-
value = attemptResolveElement(request, nextElement.type, nextElement.key, nextElement.ref, nextElement.props, null);
|
2047
|
-
}
|
2048
|
-
}
|
2049
|
-
|
2050
|
-
var processedChunk = processModelChunk(request, task.id, value);
|
2051
|
-
request.completedJSONChunks.push(processedChunk);
|
2052
|
-
request.abortableTasks.delete(task);
|
2053
|
-
task.status = COMPLETED;
|
2054
|
-
} catch (thrownValue) {
|
2055
|
-
var x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
|
2056
|
-
// reasons, the rest of the Suspense implementation expects the thrown
|
2057
|
-
// value to be a thenable, because before `use` existed that was the
|
2058
|
-
// (unstable) API for suspending. This implementation detail can change
|
2059
|
-
// later, once we deprecate the old API in favor of `use`.
|
2060
|
-
getSuspendedThenable() : thrownValue; // $FlowFixMe[method-unbinding]
|
2061
|
-
|
2062
|
-
if (typeof x === 'object' && x !== null && typeof x.then === 'function') {
|
2063
|
-
// Something suspended again, let's pick it back up later.
|
2064
|
-
var ping = task.ping;
|
2065
|
-
x.then(ping, ping);
|
2066
|
-
task.thenableState = getThenableStateAfterSuspending();
|
2067
|
-
return;
|
2068
|
-
} else {
|
2069
|
-
request.abortableTasks.delete(task);
|
2070
|
-
task.status = ERRORED$1;
|
2071
|
-
var digest = logRecoverableError(request, x);
|
2072
|
-
|
2073
|
-
{
|
2074
|
-
var _getErrorMessageAndSt5 = getErrorMessageAndStackDev(x),
|
2075
|
-
message = _getErrorMessageAndSt5.message,
|
2076
|
-
stack = _getErrorMessageAndSt5.stack;
|
2077
|
-
|
2078
|
-
emitErrorChunkDev(request, task.id, digest, message, stack);
|
2079
|
-
}
|
2080
|
-
}
|
2081
|
-
}
|
2082
|
-
}
|
2083
|
-
|
2084
|
-
function performWork(request) {
|
2085
|
-
var prevDispatcher = ReactCurrentDispatcher.current;
|
2086
|
-
ReactCurrentDispatcher.current = HooksDispatcher;
|
2087
|
-
var prevRequest = currentRequest;
|
2088
|
-
currentRequest = request;
|
2089
|
-
prepareToUseHooksForRequest(request);
|
2090
|
-
|
2091
|
-
try {
|
2092
|
-
var pingedTasks = request.pingedTasks;
|
2093
|
-
request.pingedTasks = [];
|
2094
|
-
|
2095
|
-
for (var i = 0; i < pingedTasks.length; i++) {
|
2096
|
-
var task = pingedTasks[i];
|
2097
|
-
retryTask(request, task);
|
2098
|
-
}
|
2099
|
-
|
2100
|
-
if (request.destination !== null) {
|
2101
|
-
flushCompletedChunks(request, request.destination);
|
2102
|
-
}
|
2103
|
-
} catch (error) {
|
2104
|
-
logRecoverableError(request, error);
|
2105
|
-
fatalError(request, error);
|
2106
|
-
} finally {
|
2107
|
-
ReactCurrentDispatcher.current = prevDispatcher;
|
2108
|
-
resetHooksForRequest();
|
2109
|
-
currentRequest = prevRequest;
|
2110
|
-
}
|
2111
|
-
}
|
2112
|
-
|
2113
|
-
function abortTask(task, request, errorId) {
|
2114
|
-
task.status = ABORTED; // Instead of emitting an error per task.id, we emit a model that only
|
2115
|
-
// has a single value referencing the error.
|
2116
|
-
|
2117
|
-
var ref = serializeByValueID(errorId);
|
2118
|
-
var processedChunk = processReferenceChunk(request, task.id, ref);
|
2119
|
-
request.completedErrorChunks.push(processedChunk);
|
2120
|
-
}
|
2121
|
-
|
2122
|
-
function flushCompletedChunks(request, destination) {
|
2123
|
-
beginWriting();
|
2124
|
-
|
2125
|
-
try {
|
2126
|
-
// We emit module chunks first in the stream so that
|
2127
|
-
// they can be preloaded as early as possible.
|
2128
|
-
var importsChunks = request.completedImportChunks;
|
2129
|
-
var i = 0;
|
2130
|
-
|
2131
|
-
for (; i < importsChunks.length; i++) {
|
2132
|
-
request.pendingChunks--;
|
2133
|
-
var chunk = importsChunks[i];
|
2134
|
-
var keepWriting = writeChunkAndReturn(destination, chunk);
|
2135
|
-
|
2136
|
-
if (!keepWriting) {
|
2137
|
-
request.destination = null;
|
2138
|
-
i++;
|
2139
|
-
break;
|
2140
|
-
}
|
2141
|
-
}
|
2142
|
-
|
2143
|
-
importsChunks.splice(0, i); // Next comes hints.
|
2144
|
-
|
2145
|
-
var hintChunks = request.completedHintChunks;
|
2146
|
-
i = 0;
|
2147
|
-
|
2148
|
-
for (; i < hintChunks.length; i++) {
|
2149
|
-
var _chunk = hintChunks[i];
|
2150
|
-
|
2151
|
-
var _keepWriting = writeChunkAndReturn(destination, _chunk);
|
2152
|
-
|
2153
|
-
if (!_keepWriting) {
|
2154
|
-
request.destination = null;
|
2155
|
-
i++;
|
2156
|
-
break;
|
2157
|
-
}
|
2158
|
-
}
|
2159
|
-
|
2160
|
-
hintChunks.splice(0, i); // Next comes model data.
|
2161
|
-
|
2162
|
-
var jsonChunks = request.completedJSONChunks;
|
2163
|
-
i = 0;
|
2164
|
-
|
2165
|
-
for (; i < jsonChunks.length; i++) {
|
2166
|
-
request.pendingChunks--;
|
2167
|
-
var _chunk2 = jsonChunks[i];
|
2168
|
-
|
2169
|
-
var _keepWriting2 = writeChunkAndReturn(destination, _chunk2);
|
2170
|
-
|
2171
|
-
if (!_keepWriting2) {
|
2172
|
-
request.destination = null;
|
2173
|
-
i++;
|
2174
|
-
break;
|
2175
|
-
}
|
2176
|
-
}
|
2177
|
-
|
2178
|
-
jsonChunks.splice(0, i); // Finally, errors are sent. The idea is that it's ok to delay
|
2179
|
-
// any error messages and prioritize display of other parts of
|
2180
|
-
// the page.
|
2181
|
-
|
2182
|
-
var errorChunks = request.completedErrorChunks;
|
2183
|
-
i = 0;
|
2184
|
-
|
2185
|
-
for (; i < errorChunks.length; i++) {
|
2186
|
-
request.pendingChunks--;
|
2187
|
-
var _chunk3 = errorChunks[i];
|
2188
|
-
|
2189
|
-
var _keepWriting3 = writeChunkAndReturn(destination, _chunk3);
|
2190
|
-
|
2191
|
-
if (!_keepWriting3) {
|
2192
|
-
request.destination = null;
|
2193
|
-
i++;
|
2194
|
-
break;
|
2195
|
-
}
|
2196
|
-
}
|
2197
|
-
|
2198
|
-
errorChunks.splice(0, i);
|
2199
|
-
} finally {
|
2200
|
-
request.flushScheduled = false;
|
2201
|
-
completeWriting(destination);
|
2202
|
-
}
|
2203
|
-
|
2204
|
-
if (request.pendingChunks === 0) {
|
2205
|
-
// We're done.
|
2206
|
-
close$1(destination);
|
2207
|
-
}
|
2208
|
-
}
|
2209
|
-
|
2210
|
-
function startWork(request) {
|
2211
|
-
request.flushScheduled = request.destination !== null;
|
2212
|
-
|
2213
|
-
{
|
2214
|
-
scheduleWork(function () {
|
2215
|
-
return performWork(request);
|
2216
|
-
});
|
2217
|
-
}
|
2218
|
-
}
|
2219
|
-
|
2220
|
-
function enqueueFlush(request) {
|
2221
|
-
if (request.flushScheduled === false && // If there are pinged tasks we are going to flush anyway after work completes
|
2222
|
-
request.pingedTasks.length === 0 && // If there is no destination there is nothing we can flush to. A flush will
|
2223
|
-
// happen when we start flowing again
|
2224
|
-
request.destination !== null) {
|
2225
|
-
var destination = request.destination;
|
2226
|
-
request.flushScheduled = true;
|
2227
|
-
scheduleWork(function () {
|
2228
|
-
return flushCompletedChunks(request, destination);
|
2229
|
-
});
|
2230
|
-
}
|
2231
|
-
}
|
2232
|
-
|
2233
|
-
function startFlowing(request, destination) {
|
2234
|
-
if (request.status === CLOSING) {
|
2235
|
-
request.status = CLOSED;
|
2236
|
-
closeWithError(destination, request.fatalError);
|
2237
|
-
return;
|
2238
|
-
}
|
2239
|
-
|
2240
|
-
if (request.status === CLOSED) {
|
2241
|
-
return;
|
2242
|
-
}
|
2243
|
-
|
2244
|
-
if (request.destination !== null) {
|
2245
|
-
// We're already flowing.
|
2246
|
-
return;
|
2247
|
-
}
|
2248
|
-
|
2249
|
-
request.destination = destination;
|
2250
|
-
|
2251
|
-
try {
|
2252
|
-
flushCompletedChunks(request, destination);
|
2253
|
-
} catch (error) {
|
2254
|
-
logRecoverableError(request, error);
|
2255
|
-
fatalError(request, error);
|
2256
|
-
}
|
2257
|
-
} // This is called to early terminate a request. It creates an error at all pending tasks.
|
2258
|
-
|
2259
|
-
function abort(request, reason) {
|
2260
|
-
try {
|
2261
|
-
var abortableTasks = request.abortableTasks;
|
2262
|
-
|
2263
|
-
if (abortableTasks.size > 0) {
|
2264
|
-
// We have tasks to abort. We'll emit one error row and then emit a reference
|
2265
|
-
// to that row from every row that's still remaining.
|
2266
|
-
var error = reason === undefined ? new Error('The render was aborted by the server without a reason.') : reason;
|
2267
|
-
var digest = logRecoverableError(request, error);
|
2268
|
-
request.pendingChunks++;
|
2269
|
-
var errorId = request.nextChunkId++;
|
2270
|
-
|
2271
|
-
if (true) {
|
2272
|
-
var _getErrorMessageAndSt6 = getErrorMessageAndStackDev(error),
|
2273
|
-
message = _getErrorMessageAndSt6.message,
|
2274
|
-
stack = _getErrorMessageAndSt6.stack;
|
2275
|
-
|
2276
|
-
emitErrorChunkDev(request, errorId, digest, message, stack);
|
2277
|
-
}
|
2278
|
-
|
2279
|
-
abortableTasks.forEach(function (task) {
|
2280
|
-
return abortTask(task, request, errorId);
|
2281
|
-
});
|
2282
|
-
abortableTasks.clear();
|
2283
|
-
}
|
2284
|
-
|
2285
|
-
if (request.destination !== null) {
|
2286
|
-
flushCompletedChunks(request, request.destination);
|
2287
|
-
}
|
2288
|
-
} catch (error) {
|
2289
|
-
logRecoverableError(request, error);
|
2290
|
-
fatalError(request, error);
|
2291
|
-
}
|
2292
|
-
}
|
2293
|
-
|
2294
|
-
function importServerContexts(contexts) {
|
2295
|
-
if (contexts) {
|
2296
|
-
var prevContext = getActiveContext();
|
2297
|
-
switchContext(rootContextSnapshot);
|
2298
|
-
|
2299
|
-
for (var i = 0; i < contexts.length; i++) {
|
2300
|
-
var _contexts$i = contexts[i],
|
2301
|
-
name = _contexts$i[0],
|
2302
|
-
value = _contexts$i[1];
|
2303
|
-
var context = getOrCreateServerContext(name);
|
2304
|
-
pushProvider(context, value);
|
2305
|
-
}
|
2306
|
-
|
2307
|
-
var importedContext = getActiveContext();
|
2308
|
-
switchContext(prevContext);
|
2309
|
-
return importedContext;
|
2310
|
-
}
|
2311
|
-
|
2312
|
-
return rootContextSnapshot;
|
2313
|
-
}
|
2314
|
-
|
2315
|
-
// eslint-disable-next-line no-unused-vars
|
2316
|
-
function resolveServerReference(bundlerConfig, id) {
|
2317
|
-
var name = '';
|
2318
|
-
var resolvedModuleData = bundlerConfig[id];
|
2319
|
-
|
2320
|
-
if (resolvedModuleData) {
|
2321
|
-
// The potentially aliased name.
|
2322
|
-
name = resolvedModuleData.name;
|
2323
|
-
} else {
|
2324
|
-
// We didn't find this specific export name but we might have the * export
|
2325
|
-
// which contains this name as well.
|
2326
|
-
// TODO: It's unfortunate that we now have to parse this string. We should
|
2327
|
-
// probably go back to encoding path and name separately on the client reference.
|
2328
|
-
var idx = id.lastIndexOf('#');
|
2329
|
-
|
2330
|
-
if (idx !== -1) {
|
2331
|
-
name = id.slice(idx + 1);
|
2332
|
-
resolvedModuleData = bundlerConfig[id.slice(0, idx)];
|
2333
|
-
}
|
2334
|
-
|
2335
|
-
if (!resolvedModuleData) {
|
2336
|
-
throw new Error('Could not find the module "' + id + '" in the React Server Manifest. ' + 'This is probably a bug in the React Server Components bundler.');
|
2337
|
-
}
|
2338
|
-
} // TODO: This needs to return async: true if it's an async module.
|
2339
|
-
|
2340
|
-
|
2341
|
-
return {
|
2342
|
-
id: resolvedModuleData.id,
|
2343
|
-
chunks: resolvedModuleData.chunks,
|
2344
|
-
name: name,
|
2345
|
-
async: false
|
2346
|
-
};
|
2347
|
-
} // The chunk cache contains all the chunks we've preloaded so far.
|
2348
|
-
// If they're still pending they're a thenable. This map also exists
|
2349
|
-
// in Webpack but unfortunately it's not exposed so we have to
|
2350
|
-
// replicate it in user space. null means that it has already loaded.
|
2351
|
-
|
2352
|
-
var chunkCache = new Map();
|
2353
|
-
var asyncModuleCache = new Map();
|
2354
|
-
|
2355
|
-
function ignoreReject() {// We rely on rejected promises to be handled by another listener.
|
2356
|
-
} // Start preloading the modules since we might need them soon.
|
2357
|
-
// This function doesn't suspend.
|
2358
|
-
|
2359
|
-
|
2360
|
-
function preloadModule(metadata) {
|
2361
|
-
var chunks = metadata.chunks;
|
2362
|
-
var promises = [];
|
2363
|
-
|
2364
|
-
for (var i = 0; i < chunks.length; i++) {
|
2365
|
-
var chunkId = chunks[i];
|
2366
|
-
var entry = chunkCache.get(chunkId);
|
2367
|
-
|
2368
|
-
if (entry === undefined) {
|
2369
|
-
var thenable = __webpack_chunk_load__(chunkId);
|
2370
|
-
|
2371
|
-
promises.push(thenable); // $FlowFixMe[method-unbinding]
|
2372
|
-
|
2373
|
-
var resolve = chunkCache.set.bind(chunkCache, chunkId, null);
|
2374
|
-
thenable.then(resolve, ignoreReject);
|
2375
|
-
chunkCache.set(chunkId, thenable);
|
2376
|
-
} else if (entry !== null) {
|
2377
|
-
promises.push(entry);
|
2378
|
-
}
|
2379
|
-
}
|
2380
|
-
|
2381
|
-
if (metadata.async) {
|
2382
|
-
var existingPromise = asyncModuleCache.get(metadata.id);
|
2383
|
-
|
2384
|
-
if (existingPromise) {
|
2385
|
-
if (existingPromise.status === 'fulfilled') {
|
2386
|
-
return null;
|
2387
|
-
}
|
2388
|
-
|
2389
|
-
return existingPromise;
|
2390
|
-
} else {
|
2391
|
-
var modulePromise = Promise.all(promises).then(function () {
|
2392
|
-
return __webpack_require__(metadata.id);
|
2393
|
-
});
|
2394
|
-
modulePromise.then(function (value) {
|
2395
|
-
var fulfilledThenable = modulePromise;
|
2396
|
-
fulfilledThenable.status = 'fulfilled';
|
2397
|
-
fulfilledThenable.value = value;
|
2398
|
-
}, function (reason) {
|
2399
|
-
var rejectedThenable = modulePromise;
|
2400
|
-
rejectedThenable.status = 'rejected';
|
2401
|
-
rejectedThenable.reason = reason;
|
2402
|
-
});
|
2403
|
-
asyncModuleCache.set(metadata.id, modulePromise);
|
2404
|
-
return modulePromise;
|
2405
|
-
}
|
2406
|
-
} else if (promises.length > 0) {
|
2407
|
-
return Promise.all(promises);
|
2408
|
-
} else {
|
2409
|
-
return null;
|
2410
|
-
}
|
2411
|
-
} // Actually require the module or suspend if it's not yet ready.
|
2412
|
-
// Increase priority if necessary.
|
2413
|
-
|
2414
|
-
function requireModule(metadata) {
|
2415
|
-
var moduleExports;
|
2416
|
-
|
2417
|
-
if (metadata.async) {
|
2418
|
-
// We assume that preloadModule has been called before, which
|
2419
|
-
// should have added something to the module cache.
|
2420
|
-
var promise = asyncModuleCache.get(metadata.id);
|
2421
|
-
|
2422
|
-
if (promise.status === 'fulfilled') {
|
2423
|
-
moduleExports = promise.value;
|
2424
|
-
} else {
|
2425
|
-
throw promise.reason;
|
2426
|
-
}
|
2427
|
-
} else {
|
2428
|
-
moduleExports = __webpack_require__(metadata.id);
|
2429
|
-
}
|
2430
|
-
|
2431
|
-
if (metadata.name === '*') {
|
2432
|
-
// This is a placeholder value that represents that the caller imported this
|
2433
|
-
// as a CommonJS module as is.
|
2434
|
-
return moduleExports;
|
2435
|
-
}
|
2436
|
-
|
2437
|
-
if (metadata.name === '') {
|
2438
|
-
// This is a placeholder value that represents that the caller accessed the
|
2439
|
-
// default property of this if it was an ESM interop module.
|
2440
|
-
return moduleExports.__esModule ? moduleExports.default : moduleExports;
|
2441
|
-
}
|
2442
|
-
|
2443
|
-
return moduleExports[metadata.name];
|
2444
|
-
}
|
2445
|
-
|
2446
|
-
// The server acts as a Client of itself when resolving Server References.
|
2447
|
-
var PENDING = 'pending';
|
2448
|
-
var BLOCKED = 'blocked';
|
2449
|
-
var RESOLVED_MODEL = 'resolved_model';
|
2450
|
-
var INITIALIZED = 'fulfilled';
|
2451
|
-
var ERRORED = 'rejected'; // $FlowFixMe[missing-this-annot]
|
2452
|
-
|
2453
|
-
function Chunk(status, value, reason, response) {
|
2454
|
-
this.status = status;
|
2455
|
-
this.value = value;
|
2456
|
-
this.reason = reason;
|
2457
|
-
this._response = response;
|
2458
|
-
} // We subclass Promise.prototype so that we get other methods like .catch
|
2459
|
-
|
2460
|
-
|
2461
|
-
Chunk.prototype = Object.create(Promise.prototype); // TODO: This doesn't return a new Promise chain unlike the real .then
|
2462
|
-
|
2463
|
-
Chunk.prototype.then = function (resolve, reject) {
|
2464
|
-
var chunk = this; // If we have resolved content, we try to initialize it first which
|
2465
|
-
// might put us back into one of the other states.
|
2466
|
-
|
2467
|
-
switch (chunk.status) {
|
2468
|
-
case RESOLVED_MODEL:
|
2469
|
-
initializeModelChunk(chunk);
|
2470
|
-
break;
|
2471
|
-
} // The status might have changed after initialization.
|
2472
|
-
|
2473
|
-
|
2474
|
-
switch (chunk.status) {
|
2475
|
-
case INITIALIZED:
|
2476
|
-
resolve(chunk.value);
|
2477
|
-
break;
|
2478
|
-
|
2479
|
-
case PENDING:
|
2480
|
-
case BLOCKED:
|
2481
|
-
if (resolve) {
|
2482
|
-
if (chunk.value === null) {
|
2483
|
-
chunk.value = [];
|
2484
|
-
}
|
2485
|
-
|
2486
|
-
chunk.value.push(resolve);
|
2487
|
-
}
|
2488
|
-
|
2489
|
-
if (reject) {
|
2490
|
-
if (chunk.reason === null) {
|
2491
|
-
chunk.reason = [];
|
2492
|
-
}
|
2493
|
-
|
2494
|
-
chunk.reason.push(reject);
|
2495
|
-
}
|
2496
|
-
|
2497
|
-
break;
|
2498
|
-
|
2499
|
-
default:
|
2500
|
-
reject(chunk.reason);
|
2501
|
-
break;
|
2502
|
-
}
|
2503
|
-
};
|
2504
|
-
|
2505
|
-
function getRoot(response) {
|
2506
|
-
var chunk = getChunk(response, 0);
|
2507
|
-
return chunk;
|
2508
|
-
}
|
2509
|
-
|
2510
|
-
function createPendingChunk(response) {
|
2511
|
-
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
2512
|
-
return new Chunk(PENDING, null, null, response);
|
2513
|
-
}
|
2514
|
-
|
2515
|
-
function wakeChunk(listeners, value) {
|
2516
|
-
for (var i = 0; i < listeners.length; i++) {
|
2517
|
-
var listener = listeners[i];
|
2518
|
-
listener(value);
|
2519
|
-
}
|
2520
|
-
}
|
2521
|
-
|
2522
|
-
function triggerErrorOnChunk(chunk, error) {
|
2523
|
-
if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
|
2524
|
-
// We already resolved. We didn't expect to see this.
|
2525
|
-
return;
|
2526
|
-
}
|
2527
|
-
|
2528
|
-
var listeners = chunk.reason;
|
2529
|
-
var erroredChunk = chunk;
|
2530
|
-
erroredChunk.status = ERRORED;
|
2531
|
-
erroredChunk.reason = error;
|
2532
|
-
|
2533
|
-
if (listeners !== null) {
|
2534
|
-
wakeChunk(listeners, error);
|
2535
|
-
}
|
2536
|
-
}
|
2537
|
-
|
2538
|
-
function createResolvedModelChunk(response, value) {
|
2539
|
-
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
2540
|
-
return new Chunk(RESOLVED_MODEL, value, null, response);
|
2541
|
-
}
|
2542
|
-
|
2543
|
-
function bindArgs(fn, args) {
|
2544
|
-
return fn.bind.apply(fn, [null].concat(args));
|
2545
|
-
}
|
2546
|
-
|
2547
|
-
function loadServerReference(response, id, bound, parentChunk, parentObject, key) {
|
2548
|
-
var serverReference = resolveServerReference(response._bundlerConfig, id); // We expect most servers to not really need this because you'd just have all
|
2549
|
-
// the relevant modules already loaded but it allows for lazy loading of code
|
2550
|
-
// if needed.
|
2551
|
-
|
2552
|
-
var preloadPromise = preloadModule(serverReference);
|
2553
|
-
var promise;
|
2554
|
-
|
2555
|
-
if (bound) {
|
2556
|
-
promise = Promise.all([bound, preloadPromise]).then(function (_ref) {
|
2557
|
-
var args = _ref[0];
|
2558
|
-
return bindArgs(requireModule(serverReference), args);
|
2559
|
-
});
|
2560
|
-
} else {
|
2561
|
-
if (preloadPromise) {
|
2562
|
-
promise = Promise.resolve(preloadPromise).then(function () {
|
2563
|
-
return requireModule(serverReference);
|
2564
|
-
});
|
2565
|
-
} else {
|
2566
|
-
// Synchronously available
|
2567
|
-
return requireModule(serverReference);
|
2568
|
-
}
|
2569
|
-
}
|
2570
|
-
|
2571
|
-
promise.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk)); // We need a placeholder value that will be replaced later.
|
2572
|
-
|
2573
|
-
return null;
|
2574
|
-
}
|
2575
|
-
|
2576
|
-
var initializingChunk = null;
|
2577
|
-
var initializingChunkBlockedModel = null;
|
2578
|
-
|
2579
|
-
function initializeModelChunk(chunk) {
|
2580
|
-
var prevChunk = initializingChunk;
|
2581
|
-
var prevBlocked = initializingChunkBlockedModel;
|
2582
|
-
initializingChunk = chunk;
|
2583
|
-
initializingChunkBlockedModel = null;
|
2584
|
-
|
2585
|
-
try {
|
2586
|
-
var value = JSON.parse(chunk.value, chunk._response._fromJSON);
|
2587
|
-
|
2588
|
-
if (initializingChunkBlockedModel !== null && initializingChunkBlockedModel.deps > 0) {
|
2589
|
-
initializingChunkBlockedModel.value = value; // We discovered new dependencies on modules that are not yet resolved.
|
2590
|
-
// We have to go the BLOCKED state until they're resolved.
|
2591
|
-
|
2592
|
-
var blockedChunk = chunk;
|
2593
|
-
blockedChunk.status = BLOCKED;
|
2594
|
-
blockedChunk.value = null;
|
2595
|
-
blockedChunk.reason = null;
|
2596
|
-
} else {
|
2597
|
-
var initializedChunk = chunk;
|
2598
|
-
initializedChunk.status = INITIALIZED;
|
2599
|
-
initializedChunk.value = value;
|
2600
|
-
}
|
2601
|
-
} catch (error) {
|
2602
|
-
var erroredChunk = chunk;
|
2603
|
-
erroredChunk.status = ERRORED;
|
2604
|
-
erroredChunk.reason = error;
|
2605
|
-
} finally {
|
2606
|
-
initializingChunk = prevChunk;
|
2607
|
-
initializingChunkBlockedModel = prevBlocked;
|
2608
|
-
}
|
2609
|
-
} // Report that any missing chunks in the model is now going to throw this
|
2610
|
-
// error upon read. Also notify any pending promises.
|
2611
|
-
|
2612
|
-
|
2613
|
-
function reportGlobalError(response, error) {
|
2614
|
-
response._chunks.forEach(function (chunk) {
|
2615
|
-
// If this chunk was already resolved or errored, it won't
|
2616
|
-
// trigger an error but if it wasn't then we need to
|
2617
|
-
// because we won't be getting any new data to resolve it.
|
2618
|
-
if (chunk.status === PENDING) {
|
2619
|
-
triggerErrorOnChunk(chunk, error);
|
2620
|
-
}
|
2621
|
-
});
|
2622
|
-
}
|
2623
|
-
|
2624
|
-
function getChunk(response, id) {
|
2625
|
-
var chunks = response._chunks;
|
2626
|
-
var chunk = chunks.get(id);
|
2627
|
-
|
2628
|
-
if (!chunk) {
|
2629
|
-
var prefix = response._prefix;
|
2630
|
-
var key = prefix + id; // Check if we have this field in the backing store already.
|
2631
|
-
|
2632
|
-
var backingEntry = response._formData.get(key);
|
2633
|
-
|
2634
|
-
if (backingEntry != null) {
|
2635
|
-
// We assume that this is a string entry for now.
|
2636
|
-
chunk = createResolvedModelChunk(response, backingEntry);
|
2637
|
-
} else {
|
2638
|
-
// We're still waiting on this entry to stream in.
|
2639
|
-
chunk = createPendingChunk(response);
|
2640
|
-
}
|
2641
|
-
|
2642
|
-
chunks.set(id, chunk);
|
2643
|
-
}
|
2644
|
-
|
2645
|
-
return chunk;
|
2646
|
-
}
|
2647
|
-
|
2648
|
-
function createModelResolver(chunk, parentObject, key) {
|
2649
|
-
var blocked;
|
2650
|
-
|
2651
|
-
if (initializingChunkBlockedModel) {
|
2652
|
-
blocked = initializingChunkBlockedModel;
|
2653
|
-
blocked.deps++;
|
2654
|
-
} else {
|
2655
|
-
blocked = initializingChunkBlockedModel = {
|
2656
|
-
deps: 1,
|
2657
|
-
value: null
|
2658
|
-
};
|
2659
|
-
}
|
2660
|
-
|
2661
|
-
return function (value) {
|
2662
|
-
parentObject[key] = value;
|
2663
|
-
blocked.deps--;
|
2664
|
-
|
2665
|
-
if (blocked.deps === 0) {
|
2666
|
-
if (chunk.status !== BLOCKED) {
|
2667
|
-
return;
|
2668
|
-
}
|
2669
|
-
|
2670
|
-
var resolveListeners = chunk.value;
|
2671
|
-
var initializedChunk = chunk;
|
2672
|
-
initializedChunk.status = INITIALIZED;
|
2673
|
-
initializedChunk.value = blocked.value;
|
2674
|
-
|
2675
|
-
if (resolveListeners !== null) {
|
2676
|
-
wakeChunk(resolveListeners, blocked.value);
|
2677
|
-
}
|
2678
|
-
}
|
2679
|
-
};
|
2680
|
-
}
|
2681
|
-
|
2682
|
-
function createModelReject(chunk) {
|
2683
|
-
return function (error) {
|
2684
|
-
return triggerErrorOnChunk(chunk, error);
|
2685
|
-
};
|
2686
|
-
}
|
2687
|
-
|
2688
|
-
function parseModelString(response, parentObject, key, value) {
|
2689
|
-
if (value[0] === '$') {
|
2690
|
-
switch (value[1]) {
|
2691
|
-
case '$':
|
2692
|
-
{
|
2693
|
-
// This was an escaped string value.
|
2694
|
-
return value.slice(1);
|
2695
|
-
}
|
2696
|
-
|
2697
|
-
case '@':
|
2698
|
-
{
|
2699
|
-
// Promise
|
2700
|
-
var id = parseInt(value.slice(2), 16);
|
2701
|
-
var chunk = getChunk(response, id);
|
2702
|
-
return chunk;
|
2703
|
-
}
|
2704
|
-
|
2705
|
-
case 'S':
|
2706
|
-
{
|
2707
|
-
// Symbol
|
2708
|
-
return Symbol.for(value.slice(2));
|
2709
|
-
}
|
2710
|
-
|
2711
|
-
case 'F':
|
2712
|
-
{
|
2713
|
-
// Server Reference
|
2714
|
-
var _id = parseInt(value.slice(2), 16);
|
2715
|
-
|
2716
|
-
var _chunk = getChunk(response, _id);
|
2717
|
-
|
2718
|
-
if (_chunk.status === RESOLVED_MODEL) {
|
2719
|
-
initializeModelChunk(_chunk);
|
2720
|
-
}
|
2721
|
-
|
2722
|
-
if (_chunk.status !== INITIALIZED) {
|
2723
|
-
// We know that this is emitted earlier so otherwise it's an error.
|
2724
|
-
throw _chunk.reason;
|
2725
|
-
} // TODO: Just encode this in the reference inline instead of as a model.
|
2726
|
-
|
2727
|
-
|
2728
|
-
var metaData = _chunk.value;
|
2729
|
-
return loadServerReference(response, metaData.id, metaData.bound, initializingChunk, parentObject, key);
|
2730
|
-
}
|
2731
|
-
|
2732
|
-
case 'K':
|
2733
|
-
{
|
2734
|
-
// FormData
|
2735
|
-
var stringId = value.slice(2);
|
2736
|
-
var formPrefix = response._prefix + stringId + '_';
|
2737
|
-
var data = new FormData();
|
2738
|
-
var backingFormData = response._formData; // We assume that the reference to FormData always comes after each
|
2739
|
-
// entry that it references so we can assume they all exist in the
|
2740
|
-
// backing store already.
|
2741
|
-
// $FlowFixMe[prop-missing] FormData has forEach on it.
|
2742
|
-
|
2743
|
-
backingFormData.forEach(function (entry, entryKey) {
|
2744
|
-
if (entryKey.startsWith(formPrefix)) {
|
2745
|
-
data.append(entryKey.slice(formPrefix.length), entry);
|
2746
|
-
}
|
2747
|
-
});
|
2748
|
-
return data;
|
2749
|
-
}
|
2750
|
-
|
2751
|
-
case 'I':
|
2752
|
-
{
|
2753
|
-
// $Infinity
|
2754
|
-
return Infinity;
|
2755
|
-
}
|
2756
|
-
|
2757
|
-
case '-':
|
2758
|
-
{
|
2759
|
-
// $-0 or $-Infinity
|
2760
|
-
if (value === '$-0') {
|
2761
|
-
return -0;
|
2762
|
-
} else {
|
2763
|
-
return -Infinity;
|
2764
|
-
}
|
2765
|
-
}
|
2766
|
-
|
2767
|
-
case 'N':
|
2768
|
-
{
|
2769
|
-
// $NaN
|
2770
|
-
return NaN;
|
2771
|
-
}
|
2772
|
-
|
2773
|
-
case 'u':
|
2774
|
-
{
|
2775
|
-
// matches "$undefined"
|
2776
|
-
// Special encoding for `undefined` which can't be serialized as JSON otherwise.
|
2777
|
-
return undefined;
|
2778
|
-
}
|
2779
|
-
|
2780
|
-
case 'D':
|
2781
|
-
{
|
2782
|
-
// Date
|
2783
|
-
return new Date(Date.parse(value.slice(2)));
|
2784
|
-
}
|
2785
|
-
|
2786
|
-
case 'n':
|
2787
|
-
{
|
2788
|
-
// BigInt
|
2789
|
-
return BigInt(value.slice(2));
|
2790
|
-
}
|
2791
|
-
|
2792
|
-
default:
|
2793
|
-
{
|
2794
|
-
// We assume that anything else is a reference ID.
|
2795
|
-
var _id2 = parseInt(value.slice(1), 16);
|
2796
|
-
|
2797
|
-
var _chunk2 = getChunk(response, _id2);
|
2798
|
-
|
2799
|
-
switch (_chunk2.status) {
|
2800
|
-
case RESOLVED_MODEL:
|
2801
|
-
initializeModelChunk(_chunk2);
|
2802
|
-
break;
|
2803
|
-
} // The status might have changed after initialization.
|
2804
|
-
|
2805
|
-
|
2806
|
-
switch (_chunk2.status) {
|
2807
|
-
case INITIALIZED:
|
2808
|
-
return _chunk2.value;
|
2809
|
-
|
2810
|
-
case PENDING:
|
2811
|
-
case BLOCKED:
|
2812
|
-
var parentChunk = initializingChunk;
|
2813
|
-
|
2814
|
-
_chunk2.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
|
2815
|
-
|
2816
|
-
return null;
|
2817
|
-
|
2818
|
-
default:
|
2819
|
-
throw _chunk2.reason;
|
2820
|
-
}
|
2821
|
-
}
|
2822
|
-
}
|
2823
|
-
}
|
2824
|
-
|
2825
|
-
return value;
|
2826
|
-
}
|
2827
|
-
|
2828
|
-
function createResponse(bundlerConfig, formFieldPrefix) {
|
2829
|
-
var backingFormData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new FormData();
|
2830
|
-
var chunks = new Map();
|
2831
|
-
var response = {
|
2832
|
-
_bundlerConfig: bundlerConfig,
|
2833
|
-
_prefix: formFieldPrefix,
|
2834
|
-
_formData: backingFormData,
|
2835
|
-
_chunks: chunks,
|
2836
|
-
_fromJSON: function (key, value) {
|
2837
|
-
if (typeof value === 'string') {
|
2838
|
-
// We can't use .bind here because we need the "this" value.
|
2839
|
-
return parseModelString(response, this, key, value);
|
2840
|
-
}
|
2841
|
-
|
2842
|
-
return value;
|
2843
|
-
}
|
2844
|
-
};
|
2845
|
-
return response;
|
2846
|
-
}
|
2847
|
-
function close(response) {
|
2848
|
-
// In case there are any remaining unresolved chunks, they won't
|
2849
|
-
// be resolved now. So we need to issue an error to those.
|
2850
|
-
// Ideally we should be able to early bail out if we kept a
|
2851
|
-
// ref count of pending chunks.
|
2852
|
-
reportGlobalError(response, new Error('Connection closed.'));
|
2853
|
-
}
|
2854
|
-
|
2855
|
-
function renderToReadableStream(model, webpackMap, options) {
|
2856
|
-
var request = createRequest(model, webpackMap, options ? options.onError : undefined, options ? options.context : undefined, options ? options.identifierPrefix : undefined);
|
2857
|
-
|
2858
|
-
if (options && options.signal) {
|
2859
|
-
var signal = options.signal;
|
2860
|
-
|
2861
|
-
if (signal.aborted) {
|
2862
|
-
abort(request, signal.reason);
|
2863
|
-
} else {
|
2864
|
-
var listener = function () {
|
2865
|
-
abort(request, signal.reason);
|
2866
|
-
signal.removeEventListener('abort', listener);
|
2867
|
-
};
|
2868
|
-
|
2869
|
-
signal.addEventListener('abort', listener);
|
2870
|
-
}
|
2871
|
-
}
|
2872
|
-
|
2873
|
-
var stream = new ReadableStream({
|
2874
|
-
type: 'bytes',
|
2875
|
-
start: function (controller) {
|
2876
|
-
startWork(request);
|
2877
|
-
},
|
2878
|
-
pull: function (controller) {
|
2879
|
-
startFlowing(request, controller);
|
2880
|
-
},
|
2881
|
-
cancel: function (reason) {}
|
2882
|
-
}, // $FlowFixMe[prop-missing] size() methods are not allowed on byte streams.
|
2883
|
-
{
|
2884
|
-
highWaterMark: 0
|
2885
|
-
});
|
2886
|
-
return stream;
|
2887
|
-
}
|
2888
|
-
|
2889
|
-
function decodeReply(body, webpackMap) {
|
2890
|
-
if (typeof body === 'string') {
|
2891
|
-
var form = new FormData();
|
2892
|
-
form.append('0', body);
|
2893
|
-
body = form;
|
2894
|
-
}
|
2895
|
-
|
2896
|
-
var response = createResponse(webpackMap, '', body);
|
2897
|
-
close(response);
|
2898
|
-
return getRoot(response);
|
2899
|
-
}
|
2900
|
-
|
2901
|
-
exports.decodeReply = decodeReply;
|
2902
|
-
exports.renderToReadableStream = renderToReadableStream;
|
2903
|
-
|
2904
|
-
}));
|