react-server-dom-webpack 18.3.0-next-3706edb81-20230308 → 18.3.0-next-f828bad38-20230313

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