react-server-dom-webpack 18.3.0-next-a8875eab7-20230310 → 18.3.0-next-56a3c18e5-20230314

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.
Files changed (21) hide show
  1. package/cjs/react-server-dom-webpack-client.browser.development.js +582 -1
  2. package/cjs/react-server-dom-webpack-client.browser.production.min.js +22 -19
  3. package/cjs/react-server-dom-webpack-client.edge.development.js +4 -1
  4. package/cjs/react-server-dom-webpack-client.edge.production.min.js +16 -16
  5. package/cjs/react-server-dom-webpack-client.node.development.js +4 -1
  6. package/cjs/react-server-dom-webpack-client.node.production.min.js +18 -18
  7. package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +3 -0
  8. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +15 -15
  9. package/cjs/react-server-dom-webpack-server.browser.development.js +1146 -617
  10. package/cjs/react-server-dom-webpack-server.browser.production.min.js +57 -46
  11. package/cjs/react-server-dom-webpack-server.edge.development.js +1146 -617
  12. package/cjs/react-server-dom-webpack-server.edge.production.min.js +55 -44
  13. package/cjs/react-server-dom-webpack-server.node.development.js +1181 -613
  14. package/cjs/react-server-dom-webpack-server.node.production.min.js +58 -46
  15. package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1145 -617
  16. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +52 -41
  17. package/package.json +3 -3
  18. package/umd/react-server-dom-webpack-client.browser.development.js +582 -1
  19. package/umd/react-server-dom-webpack-client.browser.production.min.js +17 -14
  20. package/umd/react-server-dom-webpack-server.browser.development.js +1146 -617
  21. package/umd/react-server-dom-webpack-server.browser.production.min.js +44 -37
@@ -205,7 +205,7 @@ function completeWriting(destination) {
205
205
  writtenBytes = 0;
206
206
  destinationHasCapacity = true;
207
207
  }
208
- function close(destination) {
208
+ function close$1(destination) {
209
209
  destination.end();
210
210
  }
211
211
  var textEncoder = new util.TextEncoder();
@@ -541,7 +541,13 @@ var capitalize = function (token) {
541
541
  new PropertyInfoRecord('xlinkHref', STRING, false, // mustUseProperty
542
542
  'xlink:href', 'http://www.w3.org/1999/xlink', true, // sanitizeURL
543
543
  false);
544
- ['src', 'href', 'action', 'formAction'].forEach(function (attributeName) {
544
+
545
+ new PropertyInfoRecord('formAction', STRING, false, // mustUseProperty
546
+ 'formaction', // attributeName
547
+ null, // attributeNamespace
548
+ true, // sanitizeURL
549
+ false);
550
+ ['src', 'href', 'action'].forEach(function (attributeName) {
545
551
  // $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
546
552
  new PropertyInfoRecord(attributeName, STRING, false, // mustUseProperty
547
553
  attributeName.toLowerCase(), // attributeName
@@ -1231,779 +1237,779 @@ function getCurrentCache() {
1231
1237
  return currentCache;
1232
1238
  }
1233
1239
 
1234
- var ContextRegistry = ReactSharedInternals.ContextRegistry;
1235
- function getOrCreateServerContext(globalName) {
1236
- if (!ContextRegistry[globalName]) {
1237
- ContextRegistry[globalName] = React.createServerContext(globalName, // $FlowFixMe function signature doesn't reflect the symbol value
1238
- REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
1240
+ // in case they error.
1241
+
1242
+ var jsxPropsParents = new WeakMap();
1243
+ var jsxChildrenParents = new WeakMap();
1244
+
1245
+ function isObjectPrototype(object) {
1246
+ if (!object) {
1247
+ return false;
1239
1248
  }
1240
1249
 
1241
- return ContextRegistry[globalName];
1242
- }
1250
+ var ObjectPrototype = Object.prototype;
1243
1251
 
1244
- // Thenable<ReactClientValue>
1252
+ if (object === ObjectPrototype) {
1253
+ return true;
1254
+ } // It might be an object from a different Realm which is
1255
+ // still just a plain simple object.
1245
1256
 
1246
- var PENDING = 0;
1247
- var COMPLETED = 1;
1248
- var ABORTED = 3;
1249
- var ERRORED = 4;
1250
- var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
1251
- var ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
1252
1257
 
1253
- function defaultErrorHandler(error) {
1254
- console['error'](error); // Don't transform to our wrapper
1258
+ if (Object.getPrototypeOf(object)) {
1259
+ return false;
1260
+ }
1261
+
1262
+ var names = Object.getOwnPropertyNames(object);
1263
+
1264
+ for (var i = 0; i < names.length; i++) {
1265
+ if (!(names[i] in ObjectPrototype)) {
1266
+ return false;
1267
+ }
1268
+ }
1269
+
1270
+ return true;
1255
1271
  }
1256
1272
 
1257
- var OPEN = 0;
1258
- var CLOSING = 1;
1259
- var CLOSED = 2;
1260
- function createRequest(model, bundlerConfig, onError, context, identifierPrefix) {
1261
- if (ReactCurrentCache.current !== null && ReactCurrentCache.current !== DefaultCacheDispatcher) {
1262
- throw new Error('Currently React only supports one RSC renderer at a time.');
1273
+ function isSimpleObject(object) {
1274
+ if (!isObjectPrototype(Object.getPrototypeOf(object))) {
1275
+ return false;
1263
1276
  }
1264
1277
 
1265
- ReactCurrentCache.current = DefaultCacheDispatcher;
1266
- var abortSet = new Set();
1267
- var pingedTasks = [];
1268
- var request = {
1269
- status: OPEN,
1270
- fatalError: null,
1271
- destination: null,
1272
- bundlerConfig: bundlerConfig,
1273
- cache: new Map(),
1274
- nextChunkId: 0,
1275
- pendingChunks: 0,
1276
- abortableTasks: abortSet,
1277
- pingedTasks: pingedTasks,
1278
- completedImportChunks: [],
1279
- completedJSONChunks: [],
1280
- completedErrorChunks: [],
1281
- writtenSymbols: new Map(),
1282
- writtenClientReferences: new Map(),
1283
- writtenServerReferences: new Map(),
1284
- writtenProviders: new Map(),
1285
- identifierPrefix: identifierPrefix || '',
1286
- identifierCount: 1,
1287
- onError: onError === undefined ? defaultErrorHandler : onError,
1288
- // $FlowFixMe[missing-this-annot]
1289
- toJSON: function (key, value) {
1290
- return resolveModelToJSON(request, this, key, value);
1278
+ var names = Object.getOwnPropertyNames(object);
1279
+
1280
+ for (var i = 0; i < names.length; i++) {
1281
+ var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
1282
+
1283
+ if (!descriptor) {
1284
+ return false;
1291
1285
  }
1292
- };
1293
- request.pendingChunks++;
1294
- var rootContext = createRootContext(context);
1295
- var rootTask = createTask(request, model, rootContext, abortSet);
1296
- pingedTasks.push(rootTask);
1297
- return request;
1298
- }
1299
1286
 
1300
- function createRootContext(reqContext) {
1301
- return importServerContexts(reqContext);
1302
- }
1287
+ if (!descriptor.enumerable) {
1288
+ if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
1289
+ // React adds key and ref getters to props objects to issue warnings.
1290
+ // Those getters will not be transferred to the client, but that's ok,
1291
+ // so we'll special case them.
1292
+ continue;
1293
+ }
1303
1294
 
1304
- var POP = {}; // Used for DEV messages to keep track of which parent rendered some props,
1305
- // in case they error.
1295
+ return false;
1296
+ }
1297
+ }
1306
1298
 
1307
- var jsxPropsParents = new WeakMap();
1308
- var jsxChildrenParents = new WeakMap();
1299
+ return true;
1300
+ }
1301
+ function objectName(object) {
1302
+ // $FlowFixMe[method-unbinding]
1303
+ var name = Object.prototype.toString.call(object);
1304
+ return name.replace(/^\[object (.*)\]$/, function (m, p0) {
1305
+ return p0;
1306
+ });
1307
+ }
1309
1308
 
1310
- function serializeThenable(request, thenable) {
1311
- request.pendingChunks++;
1312
- var newTask = createTask(request, null, getActiveContext(), request.abortableTasks);
1309
+ function describeKeyForErrorMessage(key) {
1310
+ var encodedKey = JSON.stringify(key);
1311
+ return '"' + key + '"' === encodedKey ? key : encodedKey;
1312
+ }
1313
1313
 
1314
- switch (thenable.status) {
1315
- case 'fulfilled':
1314
+ function describeValueForErrorMessage(value) {
1315
+ switch (typeof value) {
1316
+ case 'string':
1316
1317
  {
1317
- // We have the resolved value, we can go ahead and schedule it for serialization.
1318
- newTask.model = thenable.value;
1319
- pingTask(request, newTask);
1320
- return newTask.id;
1318
+ return JSON.stringify(value.length <= 10 ? value : value.substr(0, 10) + '...');
1321
1319
  }
1322
1320
 
1323
- case 'rejected':
1321
+ case 'object':
1324
1322
  {
1325
- var x = thenable.reason;
1326
- var digest = logRecoverableError(request, x);
1323
+ if (isArray(value)) {
1324
+ return '[...]';
1325
+ }
1327
1326
 
1328
- {
1329
- var _getErrorMessageAndSt = getErrorMessageAndStackDev(x),
1330
- message = _getErrorMessageAndSt.message,
1331
- stack = _getErrorMessageAndSt.stack;
1327
+ var name = objectName(value);
1332
1328
 
1333
- emitErrorChunkDev(request, newTask.id, digest, message, stack);
1329
+ if (name === 'Object') {
1330
+ return '{...}';
1334
1331
  }
1335
1332
 
1336
- return newTask.id;
1333
+ return name;
1337
1334
  }
1338
1335
 
1336
+ case 'function':
1337
+ return 'function';
1338
+
1339
1339
  default:
1340
- {
1341
- if (typeof thenable.status === 'string') {
1342
- // Only instrument the thenable if the status if not defined. If
1343
- // it's defined, but an unknown value, assume it's been instrumented by
1344
- // some custom userspace implementation. We treat it as "pending".
1345
- break;
1346
- }
1340
+ // eslint-disable-next-line react-internal/safe-string-coercion
1341
+ return String(value);
1342
+ }
1343
+ }
1347
1344
 
1348
- var pendingThenable = thenable;
1349
- pendingThenable.status = 'pending';
1350
- pendingThenable.then(function (fulfilledValue) {
1351
- if (thenable.status === 'pending') {
1352
- var fulfilledThenable = thenable;
1353
- fulfilledThenable.status = 'fulfilled';
1354
- fulfilledThenable.value = fulfilledValue;
1355
- }
1356
- }, function (error) {
1357
- if (thenable.status === 'pending') {
1358
- var rejectedThenable = thenable;
1359
- rejectedThenable.status = 'rejected';
1360
- rejectedThenable.reason = error;
1361
- }
1362
- });
1363
- break;
1364
- }
1345
+ function describeElementType(type) {
1346
+ if (typeof type === 'string') {
1347
+ return type;
1365
1348
  }
1366
1349
 
1367
- thenable.then(function (value) {
1368
- newTask.model = value;
1369
- pingTask(request, newTask);
1370
- }, function (reason) {
1371
- newTask.status = ERRORED; // TODO: We should ideally do this inside performWork so it's scheduled
1350
+ switch (type) {
1351
+ case REACT_SUSPENSE_TYPE:
1352
+ return 'Suspense';
1372
1353
 
1373
- var digest = logRecoverableError(request, reason);
1354
+ case REACT_SUSPENSE_LIST_TYPE:
1355
+ return 'SuspenseList';
1356
+ }
1374
1357
 
1375
- {
1376
- var _getErrorMessageAndSt2 = getErrorMessageAndStackDev(reason),
1377
- _message = _getErrorMessageAndSt2.message,
1378
- _stack = _getErrorMessageAndSt2.stack;
1358
+ if (typeof type === 'object') {
1359
+ switch (type.$$typeof) {
1360
+ case REACT_FORWARD_REF_TYPE:
1361
+ return describeElementType(type.render);
1379
1362
 
1380
- emitErrorChunkDev(request, newTask.id, digest, _message, _stack);
1381
- }
1363
+ case REACT_MEMO_TYPE:
1364
+ return describeElementType(type.type);
1382
1365
 
1383
- if (request.destination !== null) {
1384
- flushCompletedChunks(request, request.destination);
1385
- }
1386
- });
1387
- return newTask.id;
1388
- }
1366
+ case REACT_LAZY_TYPE:
1367
+ {
1368
+ var lazyComponent = type;
1369
+ var payload = lazyComponent._payload;
1370
+ var init = lazyComponent._init;
1389
1371
 
1390
- function readThenable(thenable) {
1391
- if (thenable.status === 'fulfilled') {
1392
- return thenable.value;
1393
- } else if (thenable.status === 'rejected') {
1394
- throw thenable.reason;
1372
+ try {
1373
+ // Lazy may contain any component type so we recursively resolve it.
1374
+ return describeElementType(init(payload));
1375
+ } catch (x) {}
1376
+ }
1377
+ }
1395
1378
  }
1396
1379
 
1397
- throw thenable;
1380
+ return '';
1398
1381
  }
1399
1382
 
1400
- function createLazyWrapperAroundWakeable(wakeable) {
1401
- // This is a temporary fork of the `use` implementation until we accept
1402
- // promises everywhere.
1403
- var thenable = wakeable;
1383
+ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1384
+ var objKind = objectName(objectOrArray);
1404
1385
 
1405
- switch (thenable.status) {
1406
- case 'fulfilled':
1407
- case 'rejected':
1408
- break;
1386
+ if (objKind !== 'Object' && objKind !== 'Array') {
1387
+ return objKind;
1388
+ }
1409
1389
 
1410
- default:
1411
- {
1412
- if (typeof thenable.status === 'string') {
1413
- // Only instrument the thenable if the status if not defined. If
1414
- // it's defined, but an unknown value, assume it's been instrumented by
1415
- // some custom userspace implementation. We treat it as "pending".
1416
- break;
1417
- }
1390
+ var str = '';
1391
+ var start = -1;
1392
+ var length = 0;
1418
1393
 
1419
- var pendingThenable = thenable;
1420
- pendingThenable.status = 'pending';
1421
- pendingThenable.then(function (fulfilledValue) {
1422
- if (thenable.status === 'pending') {
1423
- var fulfilledThenable = thenable;
1424
- fulfilledThenable.status = 'fulfilled';
1425
- fulfilledThenable.value = fulfilledValue;
1426
- }
1427
- }, function (error) {
1428
- if (thenable.status === 'pending') {
1429
- var rejectedThenable = thenable;
1430
- rejectedThenable.status = 'rejected';
1431
- rejectedThenable.reason = error;
1432
- }
1433
- });
1434
- break;
1435
- }
1436
- }
1437
-
1438
- var lazyType = {
1439
- $$typeof: REACT_LAZY_TYPE,
1440
- _payload: thenable,
1441
- _init: readThenable
1442
- };
1443
- return lazyType;
1444
- }
1394
+ if (isArray(objectOrArray)) {
1395
+ if (jsxChildrenParents.has(objectOrArray)) {
1396
+ // Print JSX Children
1397
+ var type = jsxChildrenParents.get(objectOrArray);
1398
+ str = '<' + describeElementType(type) + '>';
1399
+ var array = objectOrArray;
1445
1400
 
1446
- function attemptResolveElement(request, type, key, ref, props, prevThenableState) {
1447
- if (ref !== null && ref !== undefined) {
1448
- // When the ref moves to the regular props object this will implicitly
1449
- // throw for functions. We could probably relax it to a DEV warning for other
1450
- // cases.
1451
- throw new Error('Refs cannot be used in Server Components, nor passed to Client Components.');
1452
- }
1401
+ for (var i = 0; i < array.length; i++) {
1402
+ var value = array[i];
1403
+ var substr = void 0;
1453
1404
 
1454
- {
1455
- jsxPropsParents.set(props, type);
1405
+ if (typeof value === 'string') {
1406
+ substr = value;
1407
+ } else if (typeof value === 'object' && value !== null) {
1408
+ // $FlowFixMe[incompatible-call] found when upgrading Flow
1409
+ substr = '{' + describeObjectForErrorMessage(value) + '}';
1410
+ } else {
1411
+ substr = '{' + describeValueForErrorMessage(value) + '}';
1412
+ }
1456
1413
 
1457
- if (typeof props.children === 'object' && props.children !== null) {
1458
- jsxChildrenParents.set(props.children, type);
1459
- }
1460
- }
1414
+ if ('' + i === expandedName) {
1415
+ start = str.length;
1416
+ length = substr.length;
1417
+ str += substr;
1418
+ } else if (substr.length < 15 && str.length + substr.length < 40) {
1419
+ str += substr;
1420
+ } else {
1421
+ str += '{...}';
1422
+ }
1423
+ }
1461
1424
 
1462
- if (typeof type === 'function') {
1463
- if (isClientReference(type)) {
1464
- // This is a reference to a Client Component.
1465
- return [REACT_ELEMENT_TYPE, type, key, props];
1466
- } // This is a server-side component.
1425
+ str += '</' + describeElementType(type) + '>';
1426
+ } else {
1427
+ // Print Array
1428
+ str = '[';
1429
+ var _array = objectOrArray;
1467
1430
 
1431
+ for (var _i = 0; _i < _array.length; _i++) {
1432
+ if (_i > 0) {
1433
+ str += ', ';
1434
+ }
1468
1435
 
1469
- prepareToUseHooksForComponent(prevThenableState);
1470
- var result = type(props);
1436
+ var _value = _array[_i];
1471
1437
 
1472
- if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
1473
- // When the return value is in children position we can resolve it immediately,
1474
- // to its value without a wrapper if it's synchronously available.
1475
- var thenable = result;
1438
+ var _substr = void 0;
1476
1439
 
1477
- if (thenable.status === 'fulfilled') {
1478
- return thenable.value;
1479
- } // TODO: Once we accept Promises as children on the client, we can just return
1480
- // the thenable here.
1440
+ if (typeof _value === 'object' && _value !== null) {
1441
+ // $FlowFixMe[incompatible-call] found when upgrading Flow
1442
+ _substr = describeObjectForErrorMessage(_value);
1443
+ } else {
1444
+ _substr = describeValueForErrorMessage(_value);
1445
+ }
1481
1446
 
1447
+ if ('' + _i === expandedName) {
1448
+ start = str.length;
1449
+ length = _substr.length;
1450
+ str += _substr;
1451
+ } else if (_substr.length < 10 && str.length + _substr.length < 40) {
1452
+ str += _substr;
1453
+ } else {
1454
+ str += '...';
1455
+ }
1456
+ }
1482
1457
 
1483
- return createLazyWrapperAroundWakeable(result);
1458
+ str += ']';
1484
1459
  }
1460
+ } else {
1461
+ if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
1462
+ str = '<' + describeElementType(objectOrArray.type) + '/>';
1463
+ } else if (jsxPropsParents.has(objectOrArray)) {
1464
+ // Print JSX
1465
+ var _type = jsxPropsParents.get(objectOrArray);
1485
1466
 
1486
- return result;
1487
- } else if (typeof type === 'string') {
1488
- // This is a host element. E.g. HTML.
1489
- return [REACT_ELEMENT_TYPE, type, key, props];
1490
- } else if (typeof type === 'symbol') {
1491
- if (type === REACT_FRAGMENT_TYPE) {
1492
- // For key-less fragments, we add a small optimization to avoid serializing
1493
- // it as a wrapper.
1494
- // TODO: If a key is specified, we should propagate its key to any children.
1495
- // Same as if a Server Component has a key.
1496
- return props.children;
1497
- } // This might be a built-in React component. We'll let the client decide.
1498
- // Any built-in works as long as its props are serializable.
1467
+ str = '<' + (describeElementType(_type) || '...');
1468
+ var object = objectOrArray;
1469
+ var names = Object.keys(object);
1499
1470
 
1471
+ for (var _i2 = 0; _i2 < names.length; _i2++) {
1472
+ str += ' ';
1473
+ var name = names[_i2];
1474
+ str += describeKeyForErrorMessage(name) + '=';
1475
+ var _value2 = object[name];
1500
1476
 
1501
- return [REACT_ELEMENT_TYPE, type, key, props];
1502
- } else if (type != null && typeof type === 'object') {
1503
- if (isClientReference(type)) {
1504
- // This is a reference to a Client Component.
1505
- return [REACT_ELEMENT_TYPE, type, key, props];
1506
- }
1477
+ var _substr2 = void 0;
1507
1478
 
1508
- switch (type.$$typeof) {
1509
- case REACT_LAZY_TYPE:
1510
- {
1511
- var payload = type._payload;
1512
- var init = type._init;
1513
- var wrappedType = init(payload);
1514
- return attemptResolveElement(request, wrappedType, key, ref, props, prevThenableState);
1479
+ if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
1480
+ // $FlowFixMe[incompatible-call] found when upgrading Flow
1481
+ _substr2 = describeObjectForErrorMessage(_value2);
1482
+ } else {
1483
+ _substr2 = describeValueForErrorMessage(_value2);
1515
1484
  }
1516
1485
 
1517
- case REACT_FORWARD_REF_TYPE:
1518
- {
1519
- var render = type.render;
1520
- prepareToUseHooksForComponent(prevThenableState);
1521
- return render(props, undefined);
1486
+ if (typeof _value2 !== 'string') {
1487
+ _substr2 = '{' + _substr2 + '}';
1522
1488
  }
1523
1489
 
1524
- case REACT_MEMO_TYPE:
1525
- {
1526
- return attemptResolveElement(request, type.type, key, ref, props, prevThenableState);
1490
+ if (name === expandedName) {
1491
+ start = str.length;
1492
+ length = _substr2.length;
1493
+ str += _substr2;
1494
+ } else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
1495
+ str += _substr2;
1496
+ } else {
1497
+ str += '...';
1527
1498
  }
1499
+ }
1528
1500
 
1529
- case REACT_PROVIDER_TYPE:
1530
- {
1531
- pushProvider(type._context, props.value);
1501
+ str += '>';
1502
+ } else {
1503
+ // Print Object
1504
+ str = '{';
1505
+ var _object = objectOrArray;
1532
1506
 
1533
- {
1534
- var extraKeys = Object.keys(props).filter(function (value) {
1535
- if (value === 'children' || value === 'value') {
1536
- return false;
1537
- }
1507
+ var _names = Object.keys(_object);
1538
1508
 
1539
- return true;
1540
- });
1509
+ for (var _i3 = 0; _i3 < _names.length; _i3++) {
1510
+ if (_i3 > 0) {
1511
+ str += ', ';
1512
+ }
1541
1513
 
1542
- if (extraKeys.length !== 0) {
1543
- error('ServerContext can only have a value prop and children. Found: %s', JSON.stringify(extraKeys));
1544
- }
1545
- }
1514
+ var _name = _names[_i3];
1515
+ str += describeKeyForErrorMessage(_name) + ': ';
1516
+ var _value3 = _object[_name];
1546
1517
 
1547
- return [REACT_ELEMENT_TYPE, type, key, // Rely on __popProvider being serialized last to pop the provider.
1548
- {
1549
- value: props.value,
1550
- children: props.children,
1551
- __pop: POP
1552
- }];
1518
+ var _substr3 = void 0;
1519
+
1520
+ if (typeof _value3 === 'object' && _value3 !== null) {
1521
+ // $FlowFixMe[incompatible-call] found when upgrading Flow
1522
+ _substr3 = describeObjectForErrorMessage(_value3);
1523
+ } else {
1524
+ _substr3 = describeValueForErrorMessage(_value3);
1525
+ }
1526
+
1527
+ if (_name === expandedName) {
1528
+ start = str.length;
1529
+ length = _substr3.length;
1530
+ str += _substr3;
1531
+ } else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
1532
+ str += _substr3;
1533
+ } else {
1534
+ str += '...';
1553
1535
  }
1536
+ }
1537
+
1538
+ str += '}';
1554
1539
  }
1555
1540
  }
1556
1541
 
1557
- throw new Error("Unsupported Server Component type: " + describeValueForErrorMessage(type));
1558
- }
1542
+ if (expandedName === undefined) {
1543
+ return str;
1544
+ }
1559
1545
 
1560
- function pingTask(request, task) {
1561
- var pingedTasks = request.pingedTasks;
1562
- pingedTasks.push(task);
1546
+ if (start > -1 && length > 0) {
1547
+ var highlight = ' '.repeat(start) + '^'.repeat(length);
1548
+ return '\n ' + str + '\n ' + highlight;
1549
+ }
1563
1550
 
1564
- if (pingedTasks.length === 1) {
1565
- scheduleWork(function () {
1566
- return performWork(request);
1567
- });
1551
+ return '\n ' + str;
1552
+ }
1553
+
1554
+ var ContextRegistry = ReactSharedInternals.ContextRegistry;
1555
+ function getOrCreateServerContext(globalName) {
1556
+ if (!ContextRegistry[globalName]) {
1557
+ ContextRegistry[globalName] = React.createServerContext(globalName, // $FlowFixMe function signature doesn't reflect the symbol value
1558
+ REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
1568
1559
  }
1560
+
1561
+ return ContextRegistry[globalName];
1569
1562
  }
1570
1563
 
1571
- function createTask(request, model, context, abortSet) {
1572
- var id = request.nextChunkId++;
1573
- var task = {
1574
- id: id,
1575
- status: PENDING,
1576
- model: model,
1577
- context: context,
1578
- ping: function () {
1579
- return pingTask(request, task);
1580
- },
1581
- thenableState: null
1582
- };
1583
- abortSet.add(task);
1584
- return task;
1585
- }
1586
-
1587
- function serializeByValueID(id) {
1588
- return '$' + id.toString(16);
1589
- }
1590
-
1591
- function serializeLazyID(id) {
1592
- return '$L' + id.toString(16);
1593
- }
1564
+ // Thenable<ReactClientValue>
1594
1565
 
1595
- function serializePromiseID(id) {
1596
- return '$@' + id.toString(16);
1597
- }
1566
+ var PENDING$1 = 0;
1567
+ var COMPLETED = 1;
1568
+ var ABORTED = 3;
1569
+ var ERRORED$1 = 4;
1570
+ var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
1571
+ var ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
1598
1572
 
1599
- function serializeServerReferenceID(id) {
1600
- return '$F' + id.toString(16);
1573
+ function defaultErrorHandler(error) {
1574
+ console['error'](error); // Don't transform to our wrapper
1601
1575
  }
1602
1576
 
1603
- function serializeSymbolReference(name) {
1604
- return '$S' + name;
1605
- }
1577
+ var OPEN = 0;
1578
+ var CLOSING = 1;
1579
+ var CLOSED = 2;
1580
+ function createRequest(model, bundlerConfig, onError, context, identifierPrefix) {
1581
+ if (ReactCurrentCache.current !== null && ReactCurrentCache.current !== DefaultCacheDispatcher) {
1582
+ throw new Error('Currently React only supports one RSC renderer at a time.');
1583
+ }
1606
1584
 
1607
- function serializeProviderReference(name) {
1608
- return '$P' + name;
1585
+ ReactCurrentCache.current = DefaultCacheDispatcher;
1586
+ var abortSet = new Set();
1587
+ var pingedTasks = [];
1588
+ var request = {
1589
+ status: OPEN,
1590
+ fatalError: null,
1591
+ destination: null,
1592
+ bundlerConfig: bundlerConfig,
1593
+ cache: new Map(),
1594
+ nextChunkId: 0,
1595
+ pendingChunks: 0,
1596
+ abortableTasks: abortSet,
1597
+ pingedTasks: pingedTasks,
1598
+ completedImportChunks: [],
1599
+ completedJSONChunks: [],
1600
+ completedErrorChunks: [],
1601
+ writtenSymbols: new Map(),
1602
+ writtenClientReferences: new Map(),
1603
+ writtenServerReferences: new Map(),
1604
+ writtenProviders: new Map(),
1605
+ identifierPrefix: identifierPrefix || '',
1606
+ identifierCount: 1,
1607
+ onError: onError === undefined ? defaultErrorHandler : onError,
1608
+ // $FlowFixMe[missing-this-annot]
1609
+ toJSON: function (key, value) {
1610
+ return resolveModelToJSON(request, this, key, value);
1611
+ }
1612
+ };
1613
+ request.pendingChunks++;
1614
+ var rootContext = createRootContext(context);
1615
+ var rootTask = createTask(request, model, rootContext, abortSet);
1616
+ pingedTasks.push(rootTask);
1617
+ return request;
1609
1618
  }
1610
1619
 
1611
- function serializeUndefined() {
1612
- return '$undefined';
1620
+ function createRootContext(reqContext) {
1621
+ return importServerContexts(reqContext);
1613
1622
  }
1614
1623
 
1615
- function serializeClientReference(request, parent, key, clientReference) {
1616
- var clientReferenceKey = getClientReferenceKey(clientReference);
1617
- var writtenClientReferences = request.writtenClientReferences;
1618
- var existingId = writtenClientReferences.get(clientReferenceKey);
1624
+ var POP = {};
1619
1625
 
1620
- if (existingId !== undefined) {
1621
- if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1622
- // If we're encoding the "type" of an element, we can refer
1623
- // to that by a lazy reference instead of directly since React
1624
- // knows how to deal with lazy values. This lets us suspend
1625
- // on this component rather than its parent until the code has
1626
- // loaded.
1627
- return serializeLazyID(existingId);
1628
- }
1626
+ function serializeThenable(request, thenable) {
1627
+ request.pendingChunks++;
1628
+ var newTask = createTask(request, null, getActiveContext(), request.abortableTasks);
1629
1629
 
1630
- return serializeByValueID(existingId);
1631
- }
1630
+ switch (thenable.status) {
1631
+ case 'fulfilled':
1632
+ {
1633
+ // We have the resolved value, we can go ahead and schedule it for serialization.
1634
+ newTask.model = thenable.value;
1635
+ pingTask(request, newTask);
1636
+ return newTask.id;
1637
+ }
1632
1638
 
1633
- try {
1634
- var clientReferenceMetadata = resolveClientReferenceMetadata(request.bundlerConfig, clientReference);
1635
- request.pendingChunks++;
1636
- var importId = request.nextChunkId++;
1637
- emitImportChunk(request, importId, clientReferenceMetadata);
1638
- writtenClientReferences.set(clientReferenceKey, importId);
1639
+ case 'rejected':
1640
+ {
1641
+ var x = thenable.reason;
1642
+ var digest = logRecoverableError(request, x);
1639
1643
 
1640
- if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1641
- // If we're encoding the "type" of an element, we can refer
1642
- // to that by a lazy reference instead of directly since React
1643
- // knows how to deal with lazy values. This lets us suspend
1644
- // on this component rather than its parent until the code has
1645
- // loaded.
1646
- return serializeLazyID(importId);
1647
- }
1644
+ {
1645
+ var _getErrorMessageAndSt = getErrorMessageAndStackDev(x),
1646
+ message = _getErrorMessageAndSt.message,
1647
+ stack = _getErrorMessageAndSt.stack;
1648
1648
 
1649
- return serializeByValueID(importId);
1650
- } catch (x) {
1651
- request.pendingChunks++;
1652
- var errorId = request.nextChunkId++;
1653
- var digest = logRecoverableError(request, x);
1649
+ emitErrorChunkDev(request, newTask.id, digest, message, stack);
1650
+ }
1654
1651
 
1655
- {
1656
- var _getErrorMessageAndSt3 = getErrorMessageAndStackDev(x),
1657
- message = _getErrorMessageAndSt3.message,
1658
- stack = _getErrorMessageAndSt3.stack;
1652
+ return newTask.id;
1653
+ }
1659
1654
 
1660
- emitErrorChunkDev(request, errorId, digest, message, stack);
1661
- }
1655
+ default:
1656
+ {
1657
+ if (typeof thenable.status === 'string') {
1658
+ // Only instrument the thenable if the status if not defined. If
1659
+ // it's defined, but an unknown value, assume it's been instrumented by
1660
+ // some custom userspace implementation. We treat it as "pending".
1661
+ break;
1662
+ }
1662
1663
 
1663
- return serializeByValueID(errorId);
1664
+ var pendingThenable = thenable;
1665
+ pendingThenable.status = 'pending';
1666
+ pendingThenable.then(function (fulfilledValue) {
1667
+ if (thenable.status === 'pending') {
1668
+ var fulfilledThenable = thenable;
1669
+ fulfilledThenable.status = 'fulfilled';
1670
+ fulfilledThenable.value = fulfilledValue;
1671
+ }
1672
+ }, function (error) {
1673
+ if (thenable.status === 'pending') {
1674
+ var rejectedThenable = thenable;
1675
+ rejectedThenable.status = 'rejected';
1676
+ rejectedThenable.reason = error;
1677
+ }
1678
+ });
1679
+ break;
1680
+ }
1664
1681
  }
1665
- }
1666
1682
 
1667
- function serializeServerReference(request, parent, key, serverReference) {
1668
- var writtenServerReferences = request.writtenServerReferences;
1669
- var existingId = writtenServerReferences.get(serverReference);
1683
+ thenable.then(function (value) {
1684
+ newTask.model = value;
1685
+ pingTask(request, newTask);
1686
+ }, function (reason) {
1687
+ newTask.status = ERRORED$1; // TODO: We should ideally do this inside performWork so it's scheduled
1670
1688
 
1671
- if (existingId !== undefined) {
1672
- return serializeServerReferenceID(existingId);
1673
- }
1689
+ var digest = logRecoverableError(request, reason);
1674
1690
 
1675
- var bound = getServerReferenceBoundArguments(request.bundlerConfig, serverReference);
1676
- var serverReferenceMetadata = {
1677
- id: getServerReferenceId(request.bundlerConfig, serverReference),
1678
- bound: bound ? Promise.resolve(bound) : null
1679
- };
1680
- request.pendingChunks++;
1681
- var metadataId = request.nextChunkId++; // We assume that this object doesn't suspend.
1691
+ {
1692
+ var _getErrorMessageAndSt2 = getErrorMessageAndStackDev(reason),
1693
+ _message = _getErrorMessageAndSt2.message,
1694
+ _stack = _getErrorMessageAndSt2.stack;
1682
1695
 
1683
- var processedChunk = processModelChunk(request, metadataId, serverReferenceMetadata);
1684
- request.completedJSONChunks.push(processedChunk);
1685
- writtenServerReferences.set(serverReference, metadataId);
1686
- return serializeServerReferenceID(metadataId);
1687
- }
1696
+ emitErrorChunkDev(request, newTask.id, digest, _message, _stack);
1697
+ }
1688
1698
 
1689
- function escapeStringValue(value) {
1690
- if (value[0] === '$') {
1691
- // We need to escape $ or @ prefixed strings since we use those to encode
1692
- // references to IDs and as special symbol values.
1693
- return '$' + value;
1694
- } else {
1695
- return value;
1696
- }
1699
+ if (request.destination !== null) {
1700
+ flushCompletedChunks(request, request.destination);
1701
+ }
1702
+ });
1703
+ return newTask.id;
1697
1704
  }
1698
1705
 
1699
- function isObjectPrototype(object) {
1700
- if (!object) {
1701
- return false;
1702
- }
1703
-
1704
- var ObjectPrototype = Object.prototype;
1705
-
1706
- if (object === ObjectPrototype) {
1707
- return true;
1708
- } // It might be an object from a different Realm which is
1709
- // still just a plain simple object.
1710
-
1711
-
1712
- if (Object.getPrototypeOf(object)) {
1713
- return false;
1714
- }
1715
-
1716
- var names = Object.getOwnPropertyNames(object);
1717
-
1718
- for (var i = 0; i < names.length; i++) {
1719
- if (!(names[i] in ObjectPrototype)) {
1720
- return false;
1721
- }
1706
+ function readThenable(thenable) {
1707
+ if (thenable.status === 'fulfilled') {
1708
+ return thenable.value;
1709
+ } else if (thenable.status === 'rejected') {
1710
+ throw thenable.reason;
1722
1711
  }
1723
1712
 
1724
- return true;
1713
+ throw thenable;
1725
1714
  }
1726
1715
 
1727
- function isSimpleObject(object) {
1728
- if (!isObjectPrototype(Object.getPrototypeOf(object))) {
1729
- return false;
1730
- }
1716
+ function createLazyWrapperAroundWakeable(wakeable) {
1717
+ // This is a temporary fork of the `use` implementation until we accept
1718
+ // promises everywhere.
1719
+ var thenable = wakeable;
1731
1720
 
1732
- var names = Object.getOwnPropertyNames(object);
1721
+ switch (thenable.status) {
1722
+ case 'fulfilled':
1723
+ case 'rejected':
1724
+ break;
1733
1725
 
1734
- for (var i = 0; i < names.length; i++) {
1735
- var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
1736
-
1737
- if (!descriptor) {
1738
- return false;
1739
- }
1726
+ default:
1727
+ {
1728
+ if (typeof thenable.status === 'string') {
1729
+ // Only instrument the thenable if the status if not defined. If
1730
+ // it's defined, but an unknown value, assume it's been instrumented by
1731
+ // some custom userspace implementation. We treat it as "pending".
1732
+ break;
1733
+ }
1740
1734
 
1741
- if (!descriptor.enumerable) {
1742
- if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
1743
- // React adds key and ref getters to props objects to issue warnings.
1744
- // Those getters will not be transferred to the client, but that's ok,
1745
- // so we'll special case them.
1746
- continue;
1735
+ var pendingThenable = thenable;
1736
+ pendingThenable.status = 'pending';
1737
+ pendingThenable.then(function (fulfilledValue) {
1738
+ if (thenable.status === 'pending') {
1739
+ var fulfilledThenable = thenable;
1740
+ fulfilledThenable.status = 'fulfilled';
1741
+ fulfilledThenable.value = fulfilledValue;
1742
+ }
1743
+ }, function (error) {
1744
+ if (thenable.status === 'pending') {
1745
+ var rejectedThenable = thenable;
1746
+ rejectedThenable.status = 'rejected';
1747
+ rejectedThenable.reason = error;
1748
+ }
1749
+ });
1750
+ break;
1747
1751
  }
1748
-
1749
- return false;
1750
- }
1751
1752
  }
1752
1753
 
1753
- return true;
1754
+ var lazyType = {
1755
+ $$typeof: REACT_LAZY_TYPE,
1756
+ _payload: thenable,
1757
+ _init: readThenable
1758
+ };
1759
+ return lazyType;
1754
1760
  }
1755
1761
 
1756
- function objectName(object) {
1757
- // $FlowFixMe[method-unbinding]
1758
- var name = Object.prototype.toString.call(object);
1759
- return name.replace(/^\[object (.*)\]$/, function (m, p0) {
1760
- return p0;
1761
- });
1762
- }
1762
+ function attemptResolveElement(request, type, key, ref, props, prevThenableState) {
1763
+ if (ref !== null && ref !== undefined) {
1764
+ // When the ref moves to the regular props object this will implicitly
1765
+ // throw for functions. We could probably relax it to a DEV warning for other
1766
+ // cases.
1767
+ throw new Error('Refs cannot be used in Server Components, nor passed to Client Components.');
1768
+ }
1763
1769
 
1764
- function describeKeyForErrorMessage(key) {
1765
- var encodedKey = JSON.stringify(key);
1766
- return '"' + key + '"' === encodedKey ? key : encodedKey;
1767
- }
1770
+ {
1771
+ jsxPropsParents.set(props, type);
1768
1772
 
1769
- function describeValueForErrorMessage(value) {
1770
- switch (typeof value) {
1771
- case 'string':
1772
- {
1773
- return JSON.stringify(value.length <= 10 ? value : value.substr(0, 10) + '...');
1774
- }
1773
+ if (typeof props.children === 'object' && props.children !== null) {
1774
+ jsxChildrenParents.set(props.children, type);
1775
+ }
1776
+ }
1775
1777
 
1776
- case 'object':
1777
- {
1778
- if (isArray(value)) {
1779
- return '[...]';
1780
- }
1778
+ if (typeof type === 'function') {
1779
+ if (isClientReference(type)) {
1780
+ // This is a reference to a Client Component.
1781
+ return [REACT_ELEMENT_TYPE, type, key, props];
1782
+ } // This is a server-side component.
1781
1783
 
1782
- var name = objectName(value);
1783
1784
 
1784
- if (name === 'Object') {
1785
- return '{...}';
1786
- }
1785
+ prepareToUseHooksForComponent(prevThenableState);
1786
+ var result = type(props);
1787
1787
 
1788
- return name;
1789
- }
1788
+ if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
1789
+ // When the return value is in children position we can resolve it immediately,
1790
+ // to its value without a wrapper if it's synchronously available.
1791
+ var thenable = result;
1790
1792
 
1791
- case 'function':
1792
- return 'function';
1793
+ if (thenable.status === 'fulfilled') {
1794
+ return thenable.value;
1795
+ } // TODO: Once we accept Promises as children on the client, we can just return
1796
+ // the thenable here.
1793
1797
 
1794
- default:
1795
- // eslint-disable-next-line react-internal/safe-string-coercion
1796
- return String(value);
1797
- }
1798
- }
1799
1798
 
1800
- function describeElementType(type) {
1801
- if (typeof type === 'string') {
1802
- return type;
1803
- }
1799
+ return createLazyWrapperAroundWakeable(result);
1800
+ }
1804
1801
 
1805
- switch (type) {
1806
- case REACT_SUSPENSE_TYPE:
1807
- return 'Suspense';
1802
+ return result;
1803
+ } else if (typeof type === 'string') {
1804
+ // This is a host element. E.g. HTML.
1805
+ return [REACT_ELEMENT_TYPE, type, key, props];
1806
+ } else if (typeof type === 'symbol') {
1807
+ if (type === REACT_FRAGMENT_TYPE) {
1808
+ // For key-less fragments, we add a small optimization to avoid serializing
1809
+ // it as a wrapper.
1810
+ // TODO: If a key is specified, we should propagate its key to any children.
1811
+ // Same as if a Server Component has a key.
1812
+ return props.children;
1813
+ } // This might be a built-in React component. We'll let the client decide.
1814
+ // Any built-in works as long as its props are serializable.
1808
1815
 
1809
- case REACT_SUSPENSE_LIST_TYPE:
1810
- return 'SuspenseList';
1811
- }
1812
1816
 
1813
- if (typeof type === 'object') {
1817
+ return [REACT_ELEMENT_TYPE, type, key, props];
1818
+ } else if (type != null && typeof type === 'object') {
1819
+ if (isClientReference(type)) {
1820
+ // This is a reference to a Client Component.
1821
+ return [REACT_ELEMENT_TYPE, type, key, props];
1822
+ }
1823
+
1814
1824
  switch (type.$$typeof) {
1825
+ case REACT_LAZY_TYPE:
1826
+ {
1827
+ var payload = type._payload;
1828
+ var init = type._init;
1829
+ var wrappedType = init(payload);
1830
+ return attemptResolveElement(request, wrappedType, key, ref, props, prevThenableState);
1831
+ }
1832
+
1815
1833
  case REACT_FORWARD_REF_TYPE:
1816
- return describeElementType(type.render);
1834
+ {
1835
+ var render = type.render;
1836
+ prepareToUseHooksForComponent(prevThenableState);
1837
+ return render(props, undefined);
1838
+ }
1817
1839
 
1818
1840
  case REACT_MEMO_TYPE:
1819
- return describeElementType(type.type);
1841
+ {
1842
+ return attemptResolveElement(request, type.type, key, ref, props, prevThenableState);
1843
+ }
1820
1844
 
1821
- case REACT_LAZY_TYPE:
1845
+ case REACT_PROVIDER_TYPE:
1822
1846
  {
1823
- var lazyComponent = type;
1824
- var payload = lazyComponent._payload;
1825
- var init = lazyComponent._init;
1847
+ pushProvider(type._context, props.value);
1826
1848
 
1827
- try {
1828
- // Lazy may contain any component type so we recursively resolve it.
1829
- return describeElementType(init(payload));
1830
- } catch (x) {}
1849
+ {
1850
+ var extraKeys = Object.keys(props).filter(function (value) {
1851
+ if (value === 'children' || value === 'value') {
1852
+ return false;
1853
+ }
1854
+
1855
+ return true;
1856
+ });
1857
+
1858
+ if (extraKeys.length !== 0) {
1859
+ error('ServerContext can only have a value prop and children. Found: %s', JSON.stringify(extraKeys));
1860
+ }
1861
+ }
1862
+
1863
+ return [REACT_ELEMENT_TYPE, type, key, // Rely on __popProvider being serialized last to pop the provider.
1864
+ {
1865
+ value: props.value,
1866
+ children: props.children,
1867
+ __pop: POP
1868
+ }];
1831
1869
  }
1832
1870
  }
1833
1871
  }
1834
1872
 
1835
- return '';
1873
+ throw new Error("Unsupported Server Component type: " + describeValueForErrorMessage(type));
1836
1874
  }
1837
1875
 
1838
- function describeObjectForErrorMessage(objectOrArray, expandedName) {
1839
- var objKind = objectName(objectOrArray);
1876
+ function pingTask(request, task) {
1877
+ var pingedTasks = request.pingedTasks;
1878
+ pingedTasks.push(task);
1840
1879
 
1841
- if (objKind !== 'Object' && objKind !== 'Array') {
1842
- return objKind;
1880
+ if (pingedTasks.length === 1) {
1881
+ scheduleWork(function () {
1882
+ return performWork(request);
1883
+ });
1843
1884
  }
1885
+ }
1844
1886
 
1845
- var str = '';
1846
- var start = -1;
1847
- var length = 0;
1848
-
1849
- if (isArray(objectOrArray)) {
1850
- if (jsxChildrenParents.has(objectOrArray)) {
1851
- // Print JSX Children
1852
- var type = jsxChildrenParents.get(objectOrArray);
1853
- str = '<' + describeElementType(type) + '>';
1854
- var array = objectOrArray;
1855
-
1856
- for (var i = 0; i < array.length; i++) {
1857
- var value = array[i];
1858
- var substr = void 0;
1887
+ function createTask(request, model, context, abortSet) {
1888
+ var id = request.nextChunkId++;
1889
+ var task = {
1890
+ id: id,
1891
+ status: PENDING$1,
1892
+ model: model,
1893
+ context: context,
1894
+ ping: function () {
1895
+ return pingTask(request, task);
1896
+ },
1897
+ thenableState: null
1898
+ };
1899
+ abortSet.add(task);
1900
+ return task;
1901
+ }
1859
1902
 
1860
- if (typeof value === 'string') {
1861
- substr = value;
1862
- } else if (typeof value === 'object' && value !== null) {
1863
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1864
- substr = '{' + describeObjectForErrorMessage(value) + '}';
1865
- } else {
1866
- substr = '{' + describeValueForErrorMessage(value) + '}';
1867
- }
1903
+ function serializeByValueID(id) {
1904
+ return '$' + id.toString(16);
1905
+ }
1868
1906
 
1869
- if ('' + i === expandedName) {
1870
- start = str.length;
1871
- length = substr.length;
1872
- str += substr;
1873
- } else if (substr.length < 15 && str.length + substr.length < 40) {
1874
- str += substr;
1875
- } else {
1876
- str += '{...}';
1877
- }
1878
- }
1907
+ function serializeLazyID(id) {
1908
+ return '$L' + id.toString(16);
1909
+ }
1879
1910
 
1880
- str += '</' + describeElementType(type) + '>';
1881
- } else {
1882
- // Print Array
1883
- str = '[';
1884
- var _array = objectOrArray;
1911
+ function serializePromiseID(id) {
1912
+ return '$@' + id.toString(16);
1913
+ }
1885
1914
 
1886
- for (var _i = 0; _i < _array.length; _i++) {
1887
- if (_i > 0) {
1888
- str += ', ';
1889
- }
1915
+ function serializeServerReferenceID(id) {
1916
+ return '$F' + id.toString(16);
1917
+ }
1890
1918
 
1891
- var _value = _array[_i];
1919
+ function serializeSymbolReference(name) {
1920
+ return '$S' + name;
1921
+ }
1892
1922
 
1893
- var _substr = void 0;
1923
+ function serializeProviderReference(name) {
1924
+ return '$P' + name;
1925
+ }
1894
1926
 
1895
- if (typeof _value === 'object' && _value !== null) {
1896
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1897
- _substr = describeObjectForErrorMessage(_value);
1898
- } else {
1899
- _substr = describeValueForErrorMessage(_value);
1900
- }
1927
+ function serializeUndefined() {
1928
+ return '$undefined';
1929
+ }
1901
1930
 
1902
- if ('' + _i === expandedName) {
1903
- start = str.length;
1904
- length = _substr.length;
1905
- str += _substr;
1906
- } else if (_substr.length < 10 && str.length + _substr.length < 40) {
1907
- str += _substr;
1908
- } else {
1909
- str += '...';
1910
- }
1911
- }
1931
+ function serializeClientReference(request, parent, key, clientReference) {
1932
+ var clientReferenceKey = getClientReferenceKey(clientReference);
1933
+ var writtenClientReferences = request.writtenClientReferences;
1934
+ var existingId = writtenClientReferences.get(clientReferenceKey);
1912
1935
 
1913
- str += ']';
1936
+ if (existingId !== undefined) {
1937
+ if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1938
+ // If we're encoding the "type" of an element, we can refer
1939
+ // to that by a lazy reference instead of directly since React
1940
+ // knows how to deal with lazy values. This lets us suspend
1941
+ // on this component rather than its parent until the code has
1942
+ // loaded.
1943
+ return serializeLazyID(existingId);
1914
1944
  }
1915
- } else {
1916
- if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
1917
- str = '<' + describeElementType(objectOrArray.type) + '/>';
1918
- } else if (jsxPropsParents.has(objectOrArray)) {
1919
- // Print JSX
1920
- var _type = jsxPropsParents.get(objectOrArray);
1921
-
1922
- str = '<' + (describeElementType(_type) || '...');
1923
- var object = objectOrArray;
1924
- var names = Object.keys(object);
1925
-
1926
- for (var _i2 = 0; _i2 < names.length; _i2++) {
1927
- str += ' ';
1928
- var name = names[_i2];
1929
- str += describeKeyForErrorMessage(name) + '=';
1930
- var _value2 = object[name];
1931
-
1932
- var _substr2 = void 0;
1933
-
1934
- if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
1935
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1936
- _substr2 = describeObjectForErrorMessage(_value2);
1937
- } else {
1938
- _substr2 = describeValueForErrorMessage(_value2);
1939
- }
1940
-
1941
- if (typeof _value2 !== 'string') {
1942
- _substr2 = '{' + _substr2 + '}';
1943
- }
1944
-
1945
- if (name === expandedName) {
1946
- start = str.length;
1947
- length = _substr2.length;
1948
- str += _substr2;
1949
- } else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
1950
- str += _substr2;
1951
- } else {
1952
- str += '...';
1953
- }
1954
- }
1955
1945
 
1956
- str += '>';
1957
- } else {
1958
- // Print Object
1959
- str = '{';
1960
- var _object = objectOrArray;
1961
-
1962
- var _names = Object.keys(_object);
1963
-
1964
- for (var _i3 = 0; _i3 < _names.length; _i3++) {
1965
- if (_i3 > 0) {
1966
- str += ', ';
1967
- }
1968
-
1969
- var _name = _names[_i3];
1970
- str += describeKeyForErrorMessage(_name) + ': ';
1971
- var _value3 = _object[_name];
1946
+ return serializeByValueID(existingId);
1947
+ }
1972
1948
 
1973
- var _substr3 = void 0;
1949
+ try {
1950
+ var clientReferenceMetadata = resolveClientReferenceMetadata(request.bundlerConfig, clientReference);
1951
+ request.pendingChunks++;
1952
+ var importId = request.nextChunkId++;
1953
+ emitImportChunk(request, importId, clientReferenceMetadata);
1954
+ writtenClientReferences.set(clientReferenceKey, importId);
1974
1955
 
1975
- if (typeof _value3 === 'object' && _value3 !== null) {
1976
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1977
- _substr3 = describeObjectForErrorMessage(_value3);
1978
- } else {
1979
- _substr3 = describeValueForErrorMessage(_value3);
1980
- }
1956
+ if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1957
+ // If we're encoding the "type" of an element, we can refer
1958
+ // to that by a lazy reference instead of directly since React
1959
+ // knows how to deal with lazy values. This lets us suspend
1960
+ // on this component rather than its parent until the code has
1961
+ // loaded.
1962
+ return serializeLazyID(importId);
1963
+ }
1981
1964
 
1982
- if (_name === expandedName) {
1983
- start = str.length;
1984
- length = _substr3.length;
1985
- str += _substr3;
1986
- } else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
1987
- str += _substr3;
1988
- } else {
1989
- str += '...';
1990
- }
1991
- }
1965
+ return serializeByValueID(importId);
1966
+ } catch (x) {
1967
+ request.pendingChunks++;
1968
+ var errorId = request.nextChunkId++;
1969
+ var digest = logRecoverableError(request, x);
1992
1970
 
1993
- str += '}';
1971
+ {
1972
+ var _getErrorMessageAndSt3 = getErrorMessageAndStackDev(x),
1973
+ message = _getErrorMessageAndSt3.message,
1974
+ stack = _getErrorMessageAndSt3.stack;
1975
+
1976
+ emitErrorChunkDev(request, errorId, digest, message, stack);
1994
1977
  }
1995
- }
1996
1978
 
1997
- if (expandedName === undefined) {
1998
- return str;
1979
+ return serializeByValueID(errorId);
1999
1980
  }
1981
+ }
2000
1982
 
2001
- if (start > -1 && length > 0) {
2002
- var highlight = ' '.repeat(start) + '^'.repeat(length);
2003
- return '\n ' + str + '\n ' + highlight;
1983
+ function serializeServerReference(request, parent, key, serverReference) {
1984
+ var writtenServerReferences = request.writtenServerReferences;
1985
+ var existingId = writtenServerReferences.get(serverReference);
1986
+
1987
+ if (existingId !== undefined) {
1988
+ return serializeServerReferenceID(existingId);
2004
1989
  }
2005
1990
 
2006
- return '\n ' + str;
1991
+ var bound = getServerReferenceBoundArguments(request.bundlerConfig, serverReference);
1992
+ var serverReferenceMetadata = {
1993
+ id: getServerReferenceId(request.bundlerConfig, serverReference),
1994
+ bound: bound ? Promise.resolve(bound) : null
1995
+ };
1996
+ request.pendingChunks++;
1997
+ var metadataId = request.nextChunkId++; // We assume that this object doesn't suspend.
1998
+
1999
+ var processedChunk = processModelChunk(request, metadataId, serverReferenceMetadata);
2000
+ request.completedJSONChunks.push(processedChunk);
2001
+ writtenServerReferences.set(serverReference, metadataId);
2002
+ return serializeServerReferenceID(metadataId);
2003
+ }
2004
+
2005
+ function escapeStringValue(value) {
2006
+ if (value[0] === '$') {
2007
+ // We need to escape $ prefixed strings since we use those to encode
2008
+ // references to IDs and as special symbol values.
2009
+ return '$' + value;
2010
+ } else {
2011
+ return value;
2012
+ }
2007
2013
  }
2008
2014
 
2009
2015
  var insideContextProps = null;
@@ -2307,7 +2313,7 @@ function emitProviderChunk(request, id, contextName) {
2307
2313
  }
2308
2314
 
2309
2315
  function retryTask(request, task) {
2310
- if (task.status !== PENDING) {
2316
+ if (task.status !== PENDING$1) {
2311
2317
  // We completed this by other means before we had a chance to retry it.
2312
2318
  return;
2313
2319
  }
@@ -2362,7 +2368,7 @@ function retryTask(request, task) {
2362
2368
  return;
2363
2369
  } else {
2364
2370
  request.abortableTasks.delete(task);
2365
- task.status = ERRORED;
2371
+ task.status = ERRORED$1;
2366
2372
  var digest = logRecoverableError(request, x);
2367
2373
 
2368
2374
  {
@@ -2482,7 +2488,7 @@ function flushCompletedChunks(request, destination) {
2482
2488
 
2483
2489
  if (request.pendingChunks === 0) {
2484
2490
  // We're done.
2485
- close(destination);
2491
+ close$1(destination);
2486
2492
  }
2487
2493
  }
2488
2494
 
@@ -2575,6 +2581,475 @@ function importServerContexts(contexts) {
2575
2581
  return rootContextSnapshot;
2576
2582
  }
2577
2583
 
2584
+ // eslint-disable-next-line no-unused-vars
2585
+ function resolveServerReference(bundlerConfig, id) {
2586
+ var idx = id.lastIndexOf('#');
2587
+ var specifier = id.substr(0, idx);
2588
+ var name = id.substr(idx + 1);
2589
+ return {
2590
+ specifier: specifier,
2591
+ name: name
2592
+ };
2593
+ }
2594
+ var asyncModuleCache = new Map();
2595
+ function preloadModule(metadata) {
2596
+ var existingPromise = asyncModuleCache.get(metadata.specifier);
2597
+
2598
+ if (existingPromise) {
2599
+ if (existingPromise.status === 'fulfilled') {
2600
+ return null;
2601
+ }
2602
+
2603
+ return existingPromise;
2604
+ } else {
2605
+ // $FlowFixMe[unsupported-syntax]
2606
+ var modulePromise = import(metadata.specifier);
2607
+ modulePromise.then(function (value) {
2608
+ var fulfilledThenable = modulePromise;
2609
+ fulfilledThenable.status = 'fulfilled';
2610
+ fulfilledThenable.value = value;
2611
+ }, function (reason) {
2612
+ var rejectedThenable = modulePromise;
2613
+ rejectedThenable.status = 'rejected';
2614
+ rejectedThenable.reason = reason;
2615
+ });
2616
+ asyncModuleCache.set(metadata.specifier, modulePromise);
2617
+ return modulePromise;
2618
+ }
2619
+ }
2620
+ function requireModule(metadata) {
2621
+ var moduleExports; // We assume that preloadModule has been called before, which
2622
+ // should have added something to the module cache.
2623
+
2624
+ var promise = asyncModuleCache.get(metadata.specifier);
2625
+
2626
+ if (promise.status === 'fulfilled') {
2627
+ moduleExports = promise.value;
2628
+ } else {
2629
+ throw promise.reason;
2630
+ }
2631
+
2632
+ if (metadata.name === '*') {
2633
+ // This is a placeholder value that represents that the caller imported this
2634
+ // as a CommonJS module as is.
2635
+ return moduleExports;
2636
+ }
2637
+
2638
+ if (metadata.name === '') {
2639
+ // This is a placeholder value that represents that the caller accessed the
2640
+ // default property of this if it was an ESM interop module.
2641
+ return moduleExports.default;
2642
+ }
2643
+
2644
+ return moduleExports[metadata.name];
2645
+ }
2646
+
2647
+ // The server acts as a Client of itself when resolving Server References.
2648
+ var PENDING = 'pending';
2649
+ var BLOCKED = 'blocked';
2650
+ var RESOLVED_MODEL = 'resolved_model';
2651
+ var INITIALIZED = 'fulfilled';
2652
+ var ERRORED = 'rejected'; // $FlowFixMe[missing-this-annot]
2653
+
2654
+ function Chunk(status, value, reason, response) {
2655
+ this.status = status;
2656
+ this.value = value;
2657
+ this.reason = reason;
2658
+ this._response = response;
2659
+ } // We subclass Promise.prototype so that we get other methods like .catch
2660
+
2661
+
2662
+ Chunk.prototype = Object.create(Promise.prototype); // TODO: This doesn't return a new Promise chain unlike the real .then
2663
+
2664
+ Chunk.prototype.then = function (resolve, reject) {
2665
+ var chunk = this; // If we have resolved content, we try to initialize it first which
2666
+ // might put us back into one of the other states.
2667
+
2668
+ switch (chunk.status) {
2669
+ case RESOLVED_MODEL:
2670
+ initializeModelChunk(chunk);
2671
+ break;
2672
+ } // The status might have changed after initialization.
2673
+
2674
+
2675
+ switch (chunk.status) {
2676
+ case INITIALIZED:
2677
+ resolve(chunk.value);
2678
+ break;
2679
+
2680
+ case PENDING:
2681
+ case BLOCKED:
2682
+ if (resolve) {
2683
+ if (chunk.value === null) {
2684
+ chunk.value = [];
2685
+ }
2686
+
2687
+ chunk.value.push(resolve);
2688
+ }
2689
+
2690
+ if (reject) {
2691
+ if (chunk.reason === null) {
2692
+ chunk.reason = [];
2693
+ }
2694
+
2695
+ chunk.reason.push(reject);
2696
+ }
2697
+
2698
+ break;
2699
+
2700
+ default:
2701
+ reject(chunk.reason);
2702
+ break;
2703
+ }
2704
+ };
2705
+
2706
+ function getRoot(response) {
2707
+ var chunk = getChunk(response, 0);
2708
+ return chunk;
2709
+ }
2710
+
2711
+ function createPendingChunk(response) {
2712
+ // $FlowFixMe Flow doesn't support functions as constructors
2713
+ return new Chunk(PENDING, null, null, response);
2714
+ }
2715
+
2716
+ function wakeChunk(listeners, value) {
2717
+ for (var i = 0; i < listeners.length; i++) {
2718
+ var listener = listeners[i];
2719
+ listener(value);
2720
+ }
2721
+ }
2722
+
2723
+ function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
2724
+ switch (chunk.status) {
2725
+ case INITIALIZED:
2726
+ wakeChunk(resolveListeners, chunk.value);
2727
+ break;
2728
+
2729
+ case PENDING:
2730
+ case BLOCKED:
2731
+ chunk.value = resolveListeners;
2732
+ chunk.reason = rejectListeners;
2733
+ break;
2734
+
2735
+ case ERRORED:
2736
+ if (rejectListeners) {
2737
+ wakeChunk(rejectListeners, chunk.reason);
2738
+ }
2739
+
2740
+ break;
2741
+ }
2742
+ }
2743
+
2744
+ function triggerErrorOnChunk(chunk, error) {
2745
+ if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
2746
+ // We already resolved. We didn't expect to see this.
2747
+ return;
2748
+ }
2749
+
2750
+ var listeners = chunk.reason;
2751
+ var erroredChunk = chunk;
2752
+ erroredChunk.status = ERRORED;
2753
+ erroredChunk.reason = error;
2754
+
2755
+ if (listeners !== null) {
2756
+ wakeChunk(listeners, error);
2757
+ }
2758
+ }
2759
+
2760
+ function createResolvedModelChunk(response, value) {
2761
+ // $FlowFixMe Flow doesn't support functions as constructors
2762
+ return new Chunk(RESOLVED_MODEL, value, null, response);
2763
+ }
2764
+
2765
+ function resolveModelChunk(chunk, value) {
2766
+ if (chunk.status !== PENDING) {
2767
+ // We already resolved. We didn't expect to see this.
2768
+ return;
2769
+ }
2770
+
2771
+ var resolveListeners = chunk.value;
2772
+ var rejectListeners = chunk.reason;
2773
+ var resolvedChunk = chunk;
2774
+ resolvedChunk.status = RESOLVED_MODEL;
2775
+ resolvedChunk.value = value;
2776
+
2777
+ if (resolveListeners !== null) {
2778
+ // This is unfortunate that we're reading this eagerly if
2779
+ // we already have listeners attached since they might no
2780
+ // longer be rendered or might not be the highest pri.
2781
+ initializeModelChunk(resolvedChunk); // The status might have changed after initialization.
2782
+
2783
+ wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
2784
+ }
2785
+ }
2786
+
2787
+ function bindArgs(fn, args) {
2788
+ return fn.bind.apply(fn, [null].concat(args));
2789
+ }
2790
+
2791
+ function loadServerReference(response, id, bound, parentChunk, parentObject, key) {
2792
+ var serverReference = resolveServerReference(response._bundlerConfig, id); // We expect most servers to not really need this because you'd just have all
2793
+ // the relevant modules already loaded but it allows for lazy loading of code
2794
+ // if needed.
2795
+
2796
+ var preloadPromise = preloadModule(serverReference);
2797
+ var promise;
2798
+
2799
+ if (bound) {
2800
+ promise = Promise.all([bound, preloadPromise]).then(function (_ref) {
2801
+ var args = _ref[0];
2802
+ return bindArgs(requireModule(serverReference), args);
2803
+ });
2804
+ } else {
2805
+ if (preloadPromise) {
2806
+ promise = Promise.resolve(preloadPromise).then(function () {
2807
+ return requireModule(serverReference);
2808
+ });
2809
+ } else {
2810
+ // Synchronously available
2811
+ return requireModule(serverReference);
2812
+ }
2813
+ }
2814
+
2815
+ promise.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk)); // We need a placeholder value that will be replaced later.
2816
+
2817
+ return null;
2818
+ }
2819
+
2820
+ var initializingChunk = null;
2821
+ var initializingChunkBlockedModel = null;
2822
+
2823
+ function initializeModelChunk(chunk) {
2824
+ var prevChunk = initializingChunk;
2825
+ var prevBlocked = initializingChunkBlockedModel;
2826
+ initializingChunk = chunk;
2827
+ initializingChunkBlockedModel = null;
2828
+
2829
+ try {
2830
+ var value = JSON.parse(chunk.value, chunk._response._fromJSON);
2831
+
2832
+ if (initializingChunkBlockedModel !== null && initializingChunkBlockedModel.deps > 0) {
2833
+ initializingChunkBlockedModel.value = value; // We discovered new dependencies on modules that are not yet resolved.
2834
+ // We have to go the BLOCKED state until they're resolved.
2835
+
2836
+ var blockedChunk = chunk;
2837
+ blockedChunk.status = BLOCKED;
2838
+ blockedChunk.value = null;
2839
+ blockedChunk.reason = null;
2840
+ } else {
2841
+ var initializedChunk = chunk;
2842
+ initializedChunk.status = INITIALIZED;
2843
+ initializedChunk.value = value;
2844
+ }
2845
+ } catch (error) {
2846
+ var erroredChunk = chunk;
2847
+ erroredChunk.status = ERRORED;
2848
+ erroredChunk.reason = error;
2849
+ } finally {
2850
+ initializingChunk = prevChunk;
2851
+ initializingChunkBlockedModel = prevBlocked;
2852
+ }
2853
+ } // Report that any missing chunks in the model is now going to throw this
2854
+ // error upon read. Also notify any pending promises.
2855
+
2856
+
2857
+ function reportGlobalError(response, error) {
2858
+ response._chunks.forEach(function (chunk) {
2859
+ // If this chunk was already resolved or errored, it won't
2860
+ // trigger an error but if it wasn't then we need to
2861
+ // because we won't be getting any new data to resolve it.
2862
+ if (chunk.status === PENDING) {
2863
+ triggerErrorOnChunk(chunk, error);
2864
+ }
2865
+ });
2866
+ }
2867
+
2868
+ function getChunk(response, id) {
2869
+ var chunks = response._chunks;
2870
+ var chunk = chunks.get(id);
2871
+
2872
+ if (!chunk) {
2873
+ chunk = createPendingChunk(response);
2874
+ chunks.set(id, chunk);
2875
+ }
2876
+
2877
+ return chunk;
2878
+ }
2879
+
2880
+ function createModelResolver(chunk, parentObject, key) {
2881
+ var blocked;
2882
+
2883
+ if (initializingChunkBlockedModel) {
2884
+ blocked = initializingChunkBlockedModel;
2885
+ blocked.deps++;
2886
+ } else {
2887
+ blocked = initializingChunkBlockedModel = {
2888
+ deps: 1,
2889
+ value: null
2890
+ };
2891
+ }
2892
+
2893
+ return function (value) {
2894
+ parentObject[key] = value;
2895
+ blocked.deps--;
2896
+
2897
+ if (blocked.deps === 0) {
2898
+ if (chunk.status !== BLOCKED) {
2899
+ return;
2900
+ }
2901
+
2902
+ var resolveListeners = chunk.value;
2903
+ var initializedChunk = chunk;
2904
+ initializedChunk.status = INITIALIZED;
2905
+ initializedChunk.value = blocked.value;
2906
+
2907
+ if (resolveListeners !== null) {
2908
+ wakeChunk(resolveListeners, blocked.value);
2909
+ }
2910
+ }
2911
+ };
2912
+ }
2913
+
2914
+ function createModelReject(chunk) {
2915
+ return function (error) {
2916
+ return triggerErrorOnChunk(chunk, error);
2917
+ };
2918
+ }
2919
+
2920
+ function parseModelString(response, parentObject, key, value) {
2921
+ if (value[0] === '$') {
2922
+ switch (value[1]) {
2923
+ case '$':
2924
+ {
2925
+ // This was an escaped string value.
2926
+ return value.substring(1);
2927
+ }
2928
+
2929
+ case '@':
2930
+ {
2931
+ // Promise
2932
+ var id = parseInt(value.substring(2), 16);
2933
+ var chunk = getChunk(response, id);
2934
+ return chunk;
2935
+ }
2936
+
2937
+ case 'S':
2938
+ {
2939
+ // Symbol
2940
+ return Symbol.for(value.substring(2));
2941
+ }
2942
+
2943
+ case 'F':
2944
+ {
2945
+ // Server Reference
2946
+ var _id = parseInt(value.substring(2), 16);
2947
+
2948
+ var _chunk = getChunk(response, _id);
2949
+
2950
+ if (_chunk.status === RESOLVED_MODEL) {
2951
+ initializeModelChunk(_chunk);
2952
+ }
2953
+
2954
+ if (_chunk.status !== INITIALIZED) {
2955
+ // We know that this is emitted earlier so otherwise it's an error.
2956
+ throw _chunk.reason;
2957
+ } // TODO: Just encode this in the reference inline instead of as a model.
2958
+
2959
+
2960
+ var metaData = _chunk.value;
2961
+ return loadServerReference(response, metaData.id, metaData.bound, initializingChunk, parentObject, key);
2962
+ }
2963
+
2964
+ case 'u':
2965
+ {
2966
+ // matches "$undefined"
2967
+ // Special encoding for `undefined` which can't be serialized as JSON otherwise.
2968
+ return undefined;
2969
+ }
2970
+
2971
+ default:
2972
+ {
2973
+ // We assume that anything else is a reference ID.
2974
+ var _id2 = parseInt(value.substring(1), 16);
2975
+
2976
+ var _chunk2 = getChunk(response, _id2);
2977
+
2978
+ switch (_chunk2.status) {
2979
+ case RESOLVED_MODEL:
2980
+ initializeModelChunk(_chunk2);
2981
+ break;
2982
+ } // The status might have changed after initialization.
2983
+
2984
+
2985
+ switch (_chunk2.status) {
2986
+ case INITIALIZED:
2987
+ return _chunk2.value;
2988
+
2989
+ case PENDING:
2990
+ case BLOCKED:
2991
+ var parentChunk = initializingChunk;
2992
+
2993
+ _chunk2.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
2994
+
2995
+ return null;
2996
+
2997
+ default:
2998
+ throw _chunk2.reason;
2999
+ }
3000
+ }
3001
+ }
3002
+ }
3003
+
3004
+ return value;
3005
+ }
3006
+
3007
+ function createResponse(bundlerConfig) {
3008
+ var chunks = new Map();
3009
+ var response = {
3010
+ _bundlerConfig: bundlerConfig,
3011
+ _chunks: chunks,
3012
+ _fromJSON: function (key, value) {
3013
+ if (typeof value === 'string') {
3014
+ // We can't use .bind here because we need the "this" value.
3015
+ return parseModelString(response, this, key, value);
3016
+ }
3017
+
3018
+ return value;
3019
+ }
3020
+ };
3021
+ return response;
3022
+ }
3023
+ function resolveField(response, id, model) {
3024
+ var chunks = response._chunks;
3025
+ var chunk = chunks.get(id);
3026
+
3027
+ if (!chunk) {
3028
+ chunks.set(id, createResolvedModelChunk(response, model));
3029
+ } else {
3030
+ resolveModelChunk(chunk, model);
3031
+ }
3032
+ }
3033
+ function resolveFile(response, id, file) {
3034
+ throw new Error('Not implemented.');
3035
+ }
3036
+ function resolveFileInfo(response, id, filename, mime) {
3037
+ throw new Error('Not implemented.');
3038
+ }
3039
+ function resolveFileChunk(response, handle, chunk) {
3040
+ throw new Error('Not implemented.');
3041
+ }
3042
+ function resolveFileComplete(response, handle) {
3043
+ throw new Error('Not implemented.');
3044
+ }
3045
+ function close(response) {
3046
+ // In case there are any remaining unresolved chunks, they won't
3047
+ // be resolved now. So we need to issue an error to those.
3048
+ // Ideally we should be able to early bail out if we kept a
3049
+ // ref count of pending chunks.
3050
+ reportGlobalError(response, new Error('Connection closed.'));
3051
+ }
3052
+
2578
3053
  function createDrainHandler(destination, request) {
2579
3054
  return function () {
2580
3055
  return startFlowing(request, destination);
@@ -2602,6 +3077,59 @@ function renderToPipeableStream(model, webpackMap, options) {
2602
3077
  };
2603
3078
  }
2604
3079
 
3080
+ function decodeReplyFromBusboy(busboyStream, webpackMap) {
3081
+ var response = createResponse(webpackMap);
3082
+ busboyStream.on('field', function (name, value) {
3083
+ var id = +name;
3084
+ resolveField(response, id, value);
3085
+ });
3086
+ busboyStream.on('file', function (name, value, _ref) {
3087
+ var encoding = _ref.encoding;
3088
+
3089
+ if (encoding.toLowerCase() === 'base64') {
3090
+ throw new Error("React doesn't accept base64 encoded file uploads because we don't expect " + "form data passed from a browser to ever encode data that way. If that's " + 'the wrong assumption, we can easily fix it.');
3091
+ }
3092
+ resolveFileInfo();
3093
+ value.on('data', function (chunk) {
3094
+ resolveFileChunk();
3095
+ });
3096
+ value.on('end', function () {
3097
+ resolveFileComplete();
3098
+ });
3099
+ });
3100
+ busboyStream.on('finish', function () {
3101
+ close(response);
3102
+ });
3103
+ busboyStream.on('error', function (err) {
3104
+ reportGlobalError(response, err);
3105
+ });
3106
+ return getRoot(response);
3107
+ }
3108
+
3109
+ function decodeReply(body, webpackMap) {
3110
+ var response = createResponse(webpackMap);
3111
+
3112
+ if (typeof body === 'string') {
3113
+ resolveField(response, 0, body);
3114
+ } else {
3115
+ // $FlowFixMe[prop-missing] Flow doesn't know that forEach exists.
3116
+ body.forEach(function (value, key) {
3117
+ var id = +key;
3118
+
3119
+ if (typeof value === 'string') {
3120
+ resolveField(response, id, value);
3121
+ } else {
3122
+ resolveFile();
3123
+ }
3124
+ });
3125
+ }
3126
+
3127
+ close(response);
3128
+ return getRoot(response);
3129
+ }
3130
+
3131
+ exports.decodeReply = decodeReply;
3132
+ exports.decodeReplyFromBusboy = decodeReplyFromBusboy;
2605
3133
  exports.renderToPipeableStream = renderToPipeableStream;
2606
3134
  })();
2607
3135
  }