react-server-dom-webpack 18.3.0-next-a8875eab7-20230310 → 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 +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 +1135 -612
  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 +1135 -612
  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 +1176 -614
  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 +1134 -612
  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 +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 +1135 -612
  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,779 +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
- }
1594
-
1595
- function serializePromiseID(id) {
1596
- return '$@' + id.toString(16);
1597
- }
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
+ }
1598
1554
 
1599
- function serializeServerReferenceID(id) {
1600
- return '$F' + id.toString(16);
1555
+ return ContextRegistry[globalName];
1601
1556
  }
1602
1557
 
1603
- function serializeSymbolReference(name) {
1604
- return '$S' + name;
1605
- }
1558
+ // Thenable<ReactClientValue>
1606
1559
 
1607
- function serializeProviderReference(name) {
1608
- return '$P' + name;
1609
- }
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;
1610
1566
 
1611
- function serializeUndefined() {
1612
- return '$undefined';
1567
+ function defaultErrorHandler(error) {
1568
+ console['error'](error); // Don't transform to our wrapper
1613
1569
  }
1614
1570
 
1615
- function serializeClientReference(request, parent, key, clientReference) {
1616
- var clientReferenceKey = getClientReferenceKey(clientReference);
1617
- var writtenClientReferences = request.writtenClientReferences;
1618
- var existingId = writtenClientReferences.get(clientReferenceKey);
1619
-
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
- }
1629
-
1630
- 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.');
1631
1577
  }
1632
1578
 
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
-
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
- }
1648
-
1649
- return serializeByValueID(importId);
1650
- } catch (x) {
1651
- request.pendingChunks++;
1652
- var errorId = request.nextChunkId++;
1653
- var digest = logRecoverableError(request, x);
1654
-
1655
- {
1656
- var _getErrorMessageAndSt3 = getErrorMessageAndStackDev(x),
1657
- message = _getErrorMessageAndSt3.message,
1658
- stack = _getErrorMessageAndSt3.stack;
1659
-
1660
- 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);
1661
1605
  }
1662
-
1663
- return serializeByValueID(errorId);
1664
- }
1665
- }
1666
-
1667
- function serializeServerReference(request, parent, key, serverReference) {
1668
- var writtenServerReferences = request.writtenServerReferences;
1669
- var existingId = writtenServerReferences.get(serverReference);
1670
-
1671
- if (existingId !== undefined) {
1672
- return serializeServerReferenceID(existingId);
1673
- }
1674
-
1675
- var bound = getServerReferenceBoundArguments(request.bundlerConfig, serverReference);
1676
- var serverReferenceMetadata = {
1677
- id: getServerReferenceId(request.bundlerConfig, serverReference),
1678
- bound: bound ? Promise.resolve(bound) : null
1679
1606
  };
1680
1607
  request.pendingChunks++;
1681
- var metadataId = request.nextChunkId++; // We assume that this object doesn't suspend.
1682
-
1683
- var processedChunk = processModelChunk(request, metadataId, serverReferenceMetadata);
1684
- request.completedJSONChunks.push(processedChunk);
1685
- writtenServerReferences.set(serverReference, metadataId);
1686
- return serializeServerReferenceID(metadataId);
1608
+ var rootContext = createRootContext(context);
1609
+ var rootTask = createTask(request, model, rootContext, abortSet);
1610
+ pingedTasks.push(rootTask);
1611
+ return request;
1687
1612
  }
1688
1613
 
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
- }
1614
+ function createRootContext(reqContext) {
1615
+ return importServerContexts(reqContext);
1697
1616
  }
1698
1617
 
1699
- function isObjectPrototype(object) {
1700
- if (!object) {
1701
- return false;
1702
- }
1618
+ var POP = {};
1703
1619
 
1704
- var ObjectPrototype = Object.prototype;
1620
+ function serializeThenable(request, thenable) {
1621
+ request.pendingChunks++;
1622
+ var newTask = createTask(request, null, getActiveContext(), request.abortableTasks);
1705
1623
 
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.
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
+ }
1710
1632
 
1633
+ case 'rejected':
1634
+ {
1635
+ var x = thenable.reason;
1636
+ var digest = logRecoverableError(request, x);
1711
1637
 
1712
- if (Object.getPrototypeOf(object)) {
1713
- return false;
1714
- }
1638
+ {
1639
+ var _getErrorMessageAndSt = getErrorMessageAndStackDev(x),
1640
+ message = _getErrorMessageAndSt.message,
1641
+ stack = _getErrorMessageAndSt.stack;
1715
1642
 
1716
- var names = Object.getOwnPropertyNames(object);
1643
+ emitErrorChunkDev(request, newTask.id, digest, message, stack);
1644
+ }
1717
1645
 
1718
- for (var i = 0; i < names.length; i++) {
1719
- if (!(names[i] in ObjectPrototype)) {
1720
- return false;
1721
- }
1722
- }
1646
+ return newTask.id;
1647
+ }
1723
1648
 
1724
- return true;
1725
- }
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
+ }
1726
1657
 
1727
- function isSimpleObject(object) {
1728
- if (!isObjectPrototype(Object.getPrototypeOf(object))) {
1729
- 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
+ }
1730
1675
  }
1731
1676
 
1732
- 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
1733
1682
 
1734
- for (var i = 0; i < names.length; i++) {
1735
- var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
1683
+ var digest = logRecoverableError(request, reason);
1736
1684
 
1737
- if (!descriptor) {
1738
- return false;
1739
- }
1685
+ {
1686
+ var _getErrorMessageAndSt2 = getErrorMessageAndStackDev(reason),
1687
+ _message = _getErrorMessageAndSt2.message,
1688
+ _stack = _getErrorMessageAndSt2.stack;
1740
1689
 
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;
1747
- }
1690
+ emitErrorChunkDev(request, newTask.id, digest, _message, _stack);
1691
+ }
1748
1692
 
1749
- return false;
1693
+ if (request.destination !== null) {
1694
+ flushCompletedChunks(request, request.destination);
1750
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;
1751
1705
  }
1752
1706
 
1753
- return true;
1707
+ throw thenable;
1754
1708
  }
1755
1709
 
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
- }
1763
-
1764
- function describeKeyForErrorMessage(key) {
1765
- var encodedKey = JSON.stringify(key);
1766
- return '"' + key + '"' === encodedKey ? key : encodedKey;
1767
- }
1710
+ function createLazyWrapperAroundWakeable(wakeable) {
1711
+ // This is a temporary fork of the `use` implementation until we accept
1712
+ // promises everywhere.
1713
+ var thenable = wakeable;
1768
1714
 
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
- }
1715
+ switch (thenable.status) {
1716
+ case 'fulfilled':
1717
+ case 'rejected':
1718
+ break;
1775
1719
 
1776
- case 'object':
1720
+ default:
1777
1721
  {
1778
- if (isArray(value)) {
1779
- return '[...]';
1780
- }
1781
-
1782
- var name = objectName(value);
1783
-
1784
- if (name === 'Object') {
1785
- 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;
1786
1727
  }
1787
1728
 
1788
- 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;
1789
1745
  }
1790
-
1791
- case 'function':
1792
- return 'function';
1793
-
1794
- default:
1795
- // eslint-disable-next-line react-internal/safe-string-coercion
1796
- return String(value);
1797
1746
  }
1747
+
1748
+ var lazyType = {
1749
+ $$typeof: REACT_LAZY_TYPE,
1750
+ _payload: thenable,
1751
+ _init: readThenable
1752
+ };
1753
+ return lazyType;
1798
1754
  }
1799
1755
 
1800
- function describeElementType(type) {
1801
- if (typeof type === 'string') {
1802
- 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.');
1803
1762
  }
1804
1763
 
1805
- switch (type) {
1806
- case REACT_SUSPENSE_TYPE:
1807
- return 'Suspense';
1764
+ {
1765
+ jsxPropsParents.set(props, type);
1808
1766
 
1809
- case REACT_SUSPENSE_LIST_TYPE:
1810
- return 'SuspenseList';
1767
+ if (typeof props.children === 'object' && props.children !== null) {
1768
+ jsxChildrenParents.set(props.children, type);
1769
+ }
1811
1770
  }
1812
1771
 
1813
- if (typeof type === 'object') {
1814
- switch (type.$$typeof) {
1815
- case REACT_FORWARD_REF_TYPE:
1816
- 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.
1817
1777
 
1818
- case REACT_MEMO_TYPE:
1819
- return describeElementType(type.type);
1820
1778
 
1821
- case REACT_LAZY_TYPE:
1822
- {
1823
- var lazyComponent = type;
1824
- var payload = lazyComponent._payload;
1825
- var init = lazyComponent._init;
1779
+ prepareToUseHooksForComponent(prevThenableState);
1780
+ var result = type(props);
1826
1781
 
1827
- try {
1828
- // Lazy may contain any component type so we recursively resolve it.
1829
- return describeElementType(init(payload));
1830
- } catch (x) {}
1831
- }
1832
- }
1833
- }
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;
1834
1786
 
1835
- return '';
1836
- }
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.
1837
1791
 
1838
- function describeObjectForErrorMessage(objectOrArray, expandedName) {
1839
- var objKind = objectName(objectOrArray);
1840
1792
 
1841
- if (objKind !== 'Object' && objKind !== 'Array') {
1842
- return objKind;
1843
- }
1793
+ return createLazyWrapperAroundWakeable(result);
1794
+ }
1844
1795
 
1845
- var str = '';
1846
- var start = -1;
1847
- 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.
1848
1809
 
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
1810
 
1856
- for (var i = 0; i < array.length; i++) {
1857
- var value = array[i];
1858
- 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
+ }
1859
1817
 
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) + '}';
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);
1867
1825
  }
1868
1826
 
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 += '{...}';
1827
+ case REACT_FORWARD_REF_TYPE:
1828
+ {
1829
+ var render = type.render;
1830
+ prepareToUseHooksForComponent(prevThenableState);
1831
+ return render(props, undefined);
1877
1832
  }
1878
- }
1879
-
1880
- str += '</' + describeElementType(type) + '>';
1881
- } else {
1882
- // Print Array
1883
- str = '[';
1884
- var _array = objectOrArray;
1885
1833
 
1886
- for (var _i = 0; _i < _array.length; _i++) {
1887
- if (_i > 0) {
1888
- str += ', ';
1834
+ case REACT_MEMO_TYPE:
1835
+ {
1836
+ return attemptResolveElement(request, type.type, key, ref, props, prevThenableState);
1889
1837
  }
1890
1838
 
1891
- var _value = _array[_i];
1839
+ case REACT_PROVIDER_TYPE:
1840
+ {
1841
+ pushProvider(type._context, props.value);
1892
1842
 
1893
- var _substr = void 0;
1843
+ {
1844
+ var extraKeys = Object.keys(props).filter(function (value) {
1845
+ if (value === 'children' || value === 'value') {
1846
+ return false;
1847
+ }
1894
1848
 
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
- }
1849
+ return true;
1850
+ });
1901
1851
 
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
- }
1852
+ if (extraKeys.length !== 0) {
1853
+ error('ServerContext can only have a value prop and children. Found: %s', JSON.stringify(extraKeys));
1854
+ }
1855
+ }
1912
1856
 
1913
- 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
+ }
1914
1864
  }
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);
1865
+ }
1921
1866
 
1922
- str = '<' + (describeElementType(_type) || '...');
1923
- var object = objectOrArray;
1924
- var names = Object.keys(object);
1867
+ throw new Error("Unsupported Server Component type: " + describeValueForErrorMessage(type));
1868
+ }
1925
1869
 
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];
1870
+ function pingTask(request, task) {
1871
+ var pingedTasks = request.pingedTasks;
1872
+ pingedTasks.push(task);
1931
1873
 
1932
- var _substr2 = void 0;
1874
+ if (pingedTasks.length === 1) {
1875
+ scheduleWork(function () {
1876
+ return performWork(request);
1877
+ });
1878
+ }
1879
+ }
1933
1880
 
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
- }
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
+ }
1940
1896
 
1941
- if (typeof _value2 !== 'string') {
1942
- _substr2 = '{' + _substr2 + '}';
1943
- }
1897
+ function serializeByValueID(id) {
1898
+ return '$' + id.toString(16);
1899
+ }
1944
1900
 
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
- }
1901
+ function serializeLazyID(id) {
1902
+ return '$L' + id.toString(16);
1903
+ }
1955
1904
 
1956
- str += '>';
1957
- } else {
1958
- // Print Object
1959
- str = '{';
1960
- var _object = objectOrArray;
1905
+ function serializePromiseID(id) {
1906
+ return '$@' + id.toString(16);
1907
+ }
1961
1908
 
1962
- var _names = Object.keys(_object);
1909
+ function serializeServerReferenceID(id) {
1910
+ return '$F' + id.toString(16);
1911
+ }
1963
1912
 
1964
- for (var _i3 = 0; _i3 < _names.length; _i3++) {
1965
- if (_i3 > 0) {
1966
- str += ', ';
1967
- }
1913
+ function serializeSymbolReference(name) {
1914
+ return '$S' + name;
1915
+ }
1968
1916
 
1969
- var _name = _names[_i3];
1970
- str += describeKeyForErrorMessage(_name) + ': ';
1971
- var _value3 = _object[_name];
1917
+ function serializeProviderReference(name) {
1918
+ return '$P' + name;
1919
+ }
1972
1920
 
1973
- var _substr3 = void 0;
1921
+ function serializeUndefined() {
1922
+ return '$undefined';
1923
+ }
1974
1924
 
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
- }
1925
+ function serializeClientReference(request, parent, key, clientReference) {
1926
+ var clientReferenceKey = getClientReferenceKey(clientReference);
1927
+ var writtenClientReferences = request.writtenClientReferences;
1928
+ var existingId = writtenClientReferences.get(clientReferenceKey);
1981
1929
 
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
- }
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);
1992
1964
 
1993
- str += '}';
1965
+ {
1966
+ var _getErrorMessageAndSt3 = getErrorMessageAndStackDev(x),
1967
+ message = _getErrorMessageAndSt3.message,
1968
+ stack = _getErrorMessageAndSt3.stack;
1969
+
1970
+ emitErrorChunkDev(request, errorId, digest, message, stack);
1994
1971
  }
1995
- }
1996
1972
 
1997
- if (expandedName === undefined) {
1998
- return str;
1973
+ return serializeByValueID(errorId);
1999
1974
  }
1975
+ }
2000
1976
 
2001
- if (start > -1 && length > 0) {
2002
- var highlight = ' '.repeat(start) + '^'.repeat(length);
2003
- 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);
2004
1983
  }
2005
1984
 
2006
- 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
+ }
2007
2007
  }
2008
2008
 
2009
2009
  var insideContextProps = null;
@@ -2307,7 +2307,7 @@ function emitProviderChunk(request, id, contextName) {
2307
2307
  }
2308
2308
 
2309
2309
  function retryTask(request, task) {
2310
- if (task.status !== PENDING) {
2310
+ if (task.status !== PENDING$1) {
2311
2311
  // We completed this by other means before we had a chance to retry it.
2312
2312
  return;
2313
2313
  }
@@ -2362,7 +2362,7 @@ function retryTask(request, task) {
2362
2362
  return;
2363
2363
  } else {
2364
2364
  request.abortableTasks.delete(task);
2365
- task.status = ERRORED;
2365
+ task.status = ERRORED$1;
2366
2366
  var digest = logRecoverableError(request, x);
2367
2367
 
2368
2368
  {
@@ -2482,7 +2482,7 @@ function flushCompletedChunks(request, destination) {
2482
2482
 
2483
2483
  if (request.pendingChunks === 0) {
2484
2484
  // We're done.
2485
- close(destination);
2485
+ close$1(destination);
2486
2486
  }
2487
2487
  }
2488
2488
 
@@ -2575,6 +2575,475 @@ function importServerContexts(contexts) {
2575
2575
  return rootContextSnapshot;
2576
2576
  }
2577
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
+
2578
3047
  function createDrainHandler(destination, request) {
2579
3048
  return function () {
2580
3049
  return startFlowing(request, destination);
@@ -2602,6 +3071,59 @@ function renderToPipeableStream(model, webpackMap, options) {
2602
3071
  };
2603
3072
  }
2604
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;
2605
3127
  exports.renderToPipeableStream = renderToPipeableStream;
2606
3128
  })();
2607
3129
  }