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
@@ -130,7 +130,7 @@ function completeWriting(destination) {
130
130
  writtenBytes = 0;
131
131
  }
132
132
  }
133
- function close(destination) {
133
+ function close$1(destination) {
134
134
  destination.close();
135
135
  }
136
136
  var textEncoder = new TextEncoder();
@@ -1165,779 +1165,779 @@ function getCurrentCache() {
1165
1165
  return currentCache;
1166
1166
  }
1167
1167
 
1168
- var ContextRegistry = ReactSharedInternals.ContextRegistry;
1169
- function getOrCreateServerContext(globalName) {
1170
- if (!ContextRegistry[globalName]) {
1171
- ContextRegistry[globalName] = React.createServerContext(globalName, // $FlowFixMe function signature doesn't reflect the symbol value
1172
- REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
1168
+ // in case they error.
1169
+
1170
+ var jsxPropsParents = new WeakMap();
1171
+ var jsxChildrenParents = new WeakMap();
1172
+
1173
+ function isObjectPrototype(object) {
1174
+ if (!object) {
1175
+ return false;
1173
1176
  }
1174
1177
 
1175
- return ContextRegistry[globalName];
1176
- }
1178
+ var ObjectPrototype = Object.prototype;
1177
1179
 
1178
- // Thenable<ReactClientValue>
1180
+ if (object === ObjectPrototype) {
1181
+ return true;
1182
+ } // It might be an object from a different Realm which is
1183
+ // still just a plain simple object.
1179
1184
 
1180
- var PENDING = 0;
1181
- var COMPLETED = 1;
1182
- var ABORTED = 3;
1183
- var ERRORED = 4;
1184
- var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
1185
- var ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
1186
1185
 
1187
- function defaultErrorHandler(error) {
1188
- console['error'](error); // Don't transform to our wrapper
1186
+ if (Object.getPrototypeOf(object)) {
1187
+ return false;
1188
+ }
1189
+
1190
+ var names = Object.getOwnPropertyNames(object);
1191
+
1192
+ for (var i = 0; i < names.length; i++) {
1193
+ if (!(names[i] in ObjectPrototype)) {
1194
+ return false;
1195
+ }
1196
+ }
1197
+
1198
+ return true;
1189
1199
  }
1190
1200
 
1191
- var OPEN = 0;
1192
- var CLOSING = 1;
1193
- var CLOSED = 2;
1194
- function createRequest(model, bundlerConfig, onError, context, identifierPrefix) {
1195
- if (ReactCurrentCache.current !== null && ReactCurrentCache.current !== DefaultCacheDispatcher) {
1196
- throw new Error('Currently React only supports one RSC renderer at a time.');
1201
+ function isSimpleObject(object) {
1202
+ if (!isObjectPrototype(Object.getPrototypeOf(object))) {
1203
+ return false;
1197
1204
  }
1198
1205
 
1199
- ReactCurrentCache.current = DefaultCacheDispatcher;
1200
- var abortSet = new Set();
1201
- var pingedTasks = [];
1202
- var request = {
1203
- status: OPEN,
1204
- fatalError: null,
1205
- destination: null,
1206
- bundlerConfig: bundlerConfig,
1207
- cache: new Map(),
1208
- nextChunkId: 0,
1209
- pendingChunks: 0,
1210
- abortableTasks: abortSet,
1211
- pingedTasks: pingedTasks,
1212
- completedImportChunks: [],
1213
- completedJSONChunks: [],
1214
- completedErrorChunks: [],
1215
- writtenSymbols: new Map(),
1216
- writtenClientReferences: new Map(),
1217
- writtenServerReferences: new Map(),
1218
- writtenProviders: new Map(),
1219
- identifierPrefix: identifierPrefix || '',
1220
- identifierCount: 1,
1221
- onError: onError === undefined ? defaultErrorHandler : onError,
1222
- // $FlowFixMe[missing-this-annot]
1223
- toJSON: function (key, value) {
1224
- return resolveModelToJSON(request, this, key, value);
1206
+ var names = Object.getOwnPropertyNames(object);
1207
+
1208
+ for (var i = 0; i < names.length; i++) {
1209
+ var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
1210
+
1211
+ if (!descriptor) {
1212
+ return false;
1225
1213
  }
1226
- };
1227
- request.pendingChunks++;
1228
- var rootContext = createRootContext(context);
1229
- var rootTask = createTask(request, model, rootContext, abortSet);
1230
- pingedTasks.push(rootTask);
1231
- return request;
1232
- }
1233
1214
 
1234
- function createRootContext(reqContext) {
1235
- return importServerContexts(reqContext);
1236
- }
1215
+ if (!descriptor.enumerable) {
1216
+ if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
1217
+ // React adds key and ref getters to props objects to issue warnings.
1218
+ // Those getters will not be transferred to the client, but that's ok,
1219
+ // so we'll special case them.
1220
+ continue;
1221
+ }
1237
1222
 
1238
- var POP = {}; // Used for DEV messages to keep track of which parent rendered some props,
1239
- // in case they error.
1223
+ return false;
1224
+ }
1225
+ }
1240
1226
 
1241
- var jsxPropsParents = new WeakMap();
1242
- var jsxChildrenParents = new WeakMap();
1227
+ return true;
1228
+ }
1229
+ function objectName(object) {
1230
+ // $FlowFixMe[method-unbinding]
1231
+ var name = Object.prototype.toString.call(object);
1232
+ return name.replace(/^\[object (.*)\]$/, function (m, p0) {
1233
+ return p0;
1234
+ });
1235
+ }
1243
1236
 
1244
- function serializeThenable(request, thenable) {
1245
- request.pendingChunks++;
1246
- var newTask = createTask(request, null, getActiveContext(), request.abortableTasks);
1237
+ function describeKeyForErrorMessage(key) {
1238
+ var encodedKey = JSON.stringify(key);
1239
+ return '"' + key + '"' === encodedKey ? key : encodedKey;
1240
+ }
1247
1241
 
1248
- switch (thenable.status) {
1249
- case 'fulfilled':
1242
+ function describeValueForErrorMessage(value) {
1243
+ switch (typeof value) {
1244
+ case 'string':
1250
1245
  {
1251
- // We have the resolved value, we can go ahead and schedule it for serialization.
1252
- newTask.model = thenable.value;
1253
- pingTask(request, newTask);
1254
- return newTask.id;
1246
+ return JSON.stringify(value.length <= 10 ? value : value.substr(0, 10) + '...');
1255
1247
  }
1256
1248
 
1257
- case 'rejected':
1249
+ case 'object':
1258
1250
  {
1259
- var x = thenable.reason;
1260
- var digest = logRecoverableError(request, x);
1251
+ if (isArray(value)) {
1252
+ return '[...]';
1253
+ }
1261
1254
 
1262
- {
1263
- var _getErrorMessageAndSt = getErrorMessageAndStackDev(x),
1264
- message = _getErrorMessageAndSt.message,
1265
- stack = _getErrorMessageAndSt.stack;
1255
+ var name = objectName(value);
1266
1256
 
1267
- emitErrorChunkDev(request, newTask.id, digest, message, stack);
1257
+ if (name === 'Object') {
1258
+ return '{...}';
1268
1259
  }
1269
1260
 
1270
- return newTask.id;
1261
+ return name;
1271
1262
  }
1272
1263
 
1264
+ case 'function':
1265
+ return 'function';
1266
+
1273
1267
  default:
1274
- {
1275
- if (typeof thenable.status === 'string') {
1276
- // Only instrument the thenable if the status if not defined. If
1277
- // it's defined, but an unknown value, assume it's been instrumented by
1278
- // some custom userspace implementation. We treat it as "pending".
1279
- break;
1280
- }
1268
+ // eslint-disable-next-line react-internal/safe-string-coercion
1269
+ return String(value);
1270
+ }
1271
+ }
1281
1272
 
1282
- var pendingThenable = thenable;
1283
- pendingThenable.status = 'pending';
1284
- pendingThenable.then(function (fulfilledValue) {
1285
- if (thenable.status === 'pending') {
1286
- var fulfilledThenable = thenable;
1287
- fulfilledThenable.status = 'fulfilled';
1288
- fulfilledThenable.value = fulfilledValue;
1289
- }
1290
- }, function (error) {
1291
- if (thenable.status === 'pending') {
1292
- var rejectedThenable = thenable;
1293
- rejectedThenable.status = 'rejected';
1294
- rejectedThenable.reason = error;
1295
- }
1296
- });
1297
- break;
1298
- }
1273
+ function describeElementType(type) {
1274
+ if (typeof type === 'string') {
1275
+ return type;
1299
1276
  }
1300
1277
 
1301
- thenable.then(function (value) {
1302
- newTask.model = value;
1303
- pingTask(request, newTask);
1304
- }, function (reason) {
1305
- newTask.status = ERRORED; // TODO: We should ideally do this inside performWork so it's scheduled
1278
+ switch (type) {
1279
+ case REACT_SUSPENSE_TYPE:
1280
+ return 'Suspense';
1306
1281
 
1307
- var digest = logRecoverableError(request, reason);
1282
+ case REACT_SUSPENSE_LIST_TYPE:
1283
+ return 'SuspenseList';
1284
+ }
1308
1285
 
1309
- {
1310
- var _getErrorMessageAndSt2 = getErrorMessageAndStackDev(reason),
1311
- _message = _getErrorMessageAndSt2.message,
1312
- _stack = _getErrorMessageAndSt2.stack;
1286
+ if (typeof type === 'object') {
1287
+ switch (type.$$typeof) {
1288
+ case REACT_FORWARD_REF_TYPE:
1289
+ return describeElementType(type.render);
1313
1290
 
1314
- emitErrorChunkDev(request, newTask.id, digest, _message, _stack);
1315
- }
1291
+ case REACT_MEMO_TYPE:
1292
+ return describeElementType(type.type);
1316
1293
 
1317
- if (request.destination !== null) {
1318
- flushCompletedChunks(request, request.destination);
1319
- }
1320
- });
1321
- return newTask.id;
1322
- }
1294
+ case REACT_LAZY_TYPE:
1295
+ {
1296
+ var lazyComponent = type;
1297
+ var payload = lazyComponent._payload;
1298
+ var init = lazyComponent._init;
1323
1299
 
1324
- function readThenable(thenable) {
1325
- if (thenable.status === 'fulfilled') {
1326
- return thenable.value;
1327
- } else if (thenable.status === 'rejected') {
1328
- throw thenable.reason;
1300
+ try {
1301
+ // Lazy may contain any component type so we recursively resolve it.
1302
+ return describeElementType(init(payload));
1303
+ } catch (x) {}
1304
+ }
1305
+ }
1329
1306
  }
1330
1307
 
1331
- throw thenable;
1308
+ return '';
1332
1309
  }
1333
1310
 
1334
- function createLazyWrapperAroundWakeable(wakeable) {
1335
- // This is a temporary fork of the `use` implementation until we accept
1336
- // promises everywhere.
1337
- var thenable = wakeable;
1311
+ function describeObjectForErrorMessage(objectOrArray, expandedName) {
1312
+ var objKind = objectName(objectOrArray);
1338
1313
 
1339
- switch (thenable.status) {
1340
- case 'fulfilled':
1341
- case 'rejected':
1342
- break;
1314
+ if (objKind !== 'Object' && objKind !== 'Array') {
1315
+ return objKind;
1316
+ }
1343
1317
 
1344
- default:
1345
- {
1346
- if (typeof thenable.status === 'string') {
1347
- // Only instrument the thenable if the status if not defined. If
1348
- // it's defined, but an unknown value, assume it's been instrumented by
1349
- // some custom userspace implementation. We treat it as "pending".
1350
- break;
1351
- }
1318
+ var str = '';
1319
+ var start = -1;
1320
+ var length = 0;
1352
1321
 
1353
- var pendingThenable = thenable;
1354
- pendingThenable.status = 'pending';
1355
- pendingThenable.then(function (fulfilledValue) {
1356
- if (thenable.status === 'pending') {
1357
- var fulfilledThenable = thenable;
1358
- fulfilledThenable.status = 'fulfilled';
1359
- fulfilledThenable.value = fulfilledValue;
1360
- }
1361
- }, function (error) {
1362
- if (thenable.status === 'pending') {
1363
- var rejectedThenable = thenable;
1364
- rejectedThenable.status = 'rejected';
1365
- rejectedThenable.reason = error;
1366
- }
1367
- });
1368
- break;
1369
- }
1370
- }
1371
-
1372
- var lazyType = {
1373
- $$typeof: REACT_LAZY_TYPE,
1374
- _payload: thenable,
1375
- _init: readThenable
1376
- };
1377
- return lazyType;
1378
- }
1322
+ if (isArray(objectOrArray)) {
1323
+ if (jsxChildrenParents.has(objectOrArray)) {
1324
+ // Print JSX Children
1325
+ var type = jsxChildrenParents.get(objectOrArray);
1326
+ str = '<' + describeElementType(type) + '>';
1327
+ var array = objectOrArray;
1379
1328
 
1380
- function attemptResolveElement(request, type, key, ref, props, prevThenableState) {
1381
- if (ref !== null && ref !== undefined) {
1382
- // When the ref moves to the regular props object this will implicitly
1383
- // throw for functions. We could probably relax it to a DEV warning for other
1384
- // cases.
1385
- throw new Error('Refs cannot be used in Server Components, nor passed to Client Components.');
1386
- }
1329
+ for (var i = 0; i < array.length; i++) {
1330
+ var value = array[i];
1331
+ var substr = void 0;
1387
1332
 
1388
- {
1389
- jsxPropsParents.set(props, type);
1333
+ if (typeof value === 'string') {
1334
+ substr = value;
1335
+ } else if (typeof value === 'object' && value !== null) {
1336
+ // $FlowFixMe[incompatible-call] found when upgrading Flow
1337
+ substr = '{' + describeObjectForErrorMessage(value) + '}';
1338
+ } else {
1339
+ substr = '{' + describeValueForErrorMessage(value) + '}';
1340
+ }
1390
1341
 
1391
- if (typeof props.children === 'object' && props.children !== null) {
1392
- jsxChildrenParents.set(props.children, type);
1393
- }
1394
- }
1342
+ if ('' + i === expandedName) {
1343
+ start = str.length;
1344
+ length = substr.length;
1345
+ str += substr;
1346
+ } else if (substr.length < 15 && str.length + substr.length < 40) {
1347
+ str += substr;
1348
+ } else {
1349
+ str += '{...}';
1350
+ }
1351
+ }
1395
1352
 
1396
- if (typeof type === 'function') {
1397
- if (isClientReference(type)) {
1398
- // This is a reference to a Client Component.
1399
- return [REACT_ELEMENT_TYPE, type, key, props];
1400
- } // This is a server-side component.
1353
+ str += '</' + describeElementType(type) + '>';
1354
+ } else {
1355
+ // Print Array
1356
+ str = '[';
1357
+ var _array = objectOrArray;
1401
1358
 
1359
+ for (var _i = 0; _i < _array.length; _i++) {
1360
+ if (_i > 0) {
1361
+ str += ', ';
1362
+ }
1402
1363
 
1403
- prepareToUseHooksForComponent(prevThenableState);
1404
- var result = type(props);
1364
+ var _value = _array[_i];
1405
1365
 
1406
- if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
1407
- // When the return value is in children position we can resolve it immediately,
1408
- // to its value without a wrapper if it's synchronously available.
1409
- var thenable = result;
1366
+ var _substr = void 0;
1410
1367
 
1411
- if (thenable.status === 'fulfilled') {
1412
- return thenable.value;
1413
- } // TODO: Once we accept Promises as children on the client, we can just return
1414
- // the thenable here.
1368
+ if (typeof _value === 'object' && _value !== null) {
1369
+ // $FlowFixMe[incompatible-call] found when upgrading Flow
1370
+ _substr = describeObjectForErrorMessage(_value);
1371
+ } else {
1372
+ _substr = describeValueForErrorMessage(_value);
1373
+ }
1415
1374
 
1375
+ if ('' + _i === expandedName) {
1376
+ start = str.length;
1377
+ length = _substr.length;
1378
+ str += _substr;
1379
+ } else if (_substr.length < 10 && str.length + _substr.length < 40) {
1380
+ str += _substr;
1381
+ } else {
1382
+ str += '...';
1383
+ }
1384
+ }
1416
1385
 
1417
- return createLazyWrapperAroundWakeable(result);
1386
+ str += ']';
1418
1387
  }
1388
+ } else {
1389
+ if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
1390
+ str = '<' + describeElementType(objectOrArray.type) + '/>';
1391
+ } else if (jsxPropsParents.has(objectOrArray)) {
1392
+ // Print JSX
1393
+ var _type = jsxPropsParents.get(objectOrArray);
1419
1394
 
1420
- return result;
1421
- } else if (typeof type === 'string') {
1422
- // This is a host element. E.g. HTML.
1423
- return [REACT_ELEMENT_TYPE, type, key, props];
1424
- } else if (typeof type === 'symbol') {
1425
- if (type === REACT_FRAGMENT_TYPE) {
1426
- // For key-less fragments, we add a small optimization to avoid serializing
1427
- // it as a wrapper.
1428
- // TODO: If a key is specified, we should propagate its key to any children.
1429
- // Same as if a Server Component has a key.
1430
- return props.children;
1431
- } // This might be a built-in React component. We'll let the client decide.
1432
- // Any built-in works as long as its props are serializable.
1395
+ str = '<' + (describeElementType(_type) || '...');
1396
+ var object = objectOrArray;
1397
+ var names = Object.keys(object);
1433
1398
 
1399
+ for (var _i2 = 0; _i2 < names.length; _i2++) {
1400
+ str += ' ';
1401
+ var name = names[_i2];
1402
+ str += describeKeyForErrorMessage(name) + '=';
1403
+ var _value2 = object[name];
1434
1404
 
1435
- return [REACT_ELEMENT_TYPE, type, key, props];
1436
- } else if (type != null && typeof type === 'object') {
1437
- if (isClientReference(type)) {
1438
- // This is a reference to a Client Component.
1439
- return [REACT_ELEMENT_TYPE, type, key, props];
1440
- }
1405
+ var _substr2 = void 0;
1441
1406
 
1442
- switch (type.$$typeof) {
1443
- case REACT_LAZY_TYPE:
1444
- {
1445
- var payload = type._payload;
1446
- var init = type._init;
1447
- var wrappedType = init(payload);
1448
- return attemptResolveElement(request, wrappedType, key, ref, props, prevThenableState);
1407
+ if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
1408
+ // $FlowFixMe[incompatible-call] found when upgrading Flow
1409
+ _substr2 = describeObjectForErrorMessage(_value2);
1410
+ } else {
1411
+ _substr2 = describeValueForErrorMessage(_value2);
1449
1412
  }
1450
1413
 
1451
- case REACT_FORWARD_REF_TYPE:
1452
- {
1453
- var render = type.render;
1454
- prepareToUseHooksForComponent(prevThenableState);
1455
- return render(props, undefined);
1414
+ if (typeof _value2 !== 'string') {
1415
+ _substr2 = '{' + _substr2 + '}';
1456
1416
  }
1457
1417
 
1458
- case REACT_MEMO_TYPE:
1459
- {
1460
- return attemptResolveElement(request, type.type, key, ref, props, prevThenableState);
1418
+ if (name === expandedName) {
1419
+ start = str.length;
1420
+ length = _substr2.length;
1421
+ str += _substr2;
1422
+ } else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
1423
+ str += _substr2;
1424
+ } else {
1425
+ str += '...';
1461
1426
  }
1427
+ }
1462
1428
 
1463
- case REACT_PROVIDER_TYPE:
1464
- {
1465
- pushProvider(type._context, props.value);
1429
+ str += '>';
1430
+ } else {
1431
+ // Print Object
1432
+ str = '{';
1433
+ var _object = objectOrArray;
1466
1434
 
1467
- {
1468
- var extraKeys = Object.keys(props).filter(function (value) {
1469
- if (value === 'children' || value === 'value') {
1470
- return false;
1471
- }
1435
+ var _names = Object.keys(_object);
1472
1436
 
1473
- return true;
1474
- });
1437
+ for (var _i3 = 0; _i3 < _names.length; _i3++) {
1438
+ if (_i3 > 0) {
1439
+ str += ', ';
1440
+ }
1475
1441
 
1476
- if (extraKeys.length !== 0) {
1477
- error('ServerContext can only have a value prop and children. Found: %s', JSON.stringify(extraKeys));
1478
- }
1479
- }
1442
+ var _name = _names[_i3];
1443
+ str += describeKeyForErrorMessage(_name) + ': ';
1444
+ var _value3 = _object[_name];
1480
1445
 
1481
- return [REACT_ELEMENT_TYPE, type, key, // Rely on __popProvider being serialized last to pop the provider.
1482
- {
1483
- value: props.value,
1484
- children: props.children,
1485
- __pop: POP
1486
- }];
1446
+ var _substr3 = void 0;
1447
+
1448
+ if (typeof _value3 === 'object' && _value3 !== null) {
1449
+ // $FlowFixMe[incompatible-call] found when upgrading Flow
1450
+ _substr3 = describeObjectForErrorMessage(_value3);
1451
+ } else {
1452
+ _substr3 = describeValueForErrorMessage(_value3);
1453
+ }
1454
+
1455
+ if (_name === expandedName) {
1456
+ start = str.length;
1457
+ length = _substr3.length;
1458
+ str += _substr3;
1459
+ } else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
1460
+ str += _substr3;
1461
+ } else {
1462
+ str += '...';
1487
1463
  }
1464
+ }
1465
+
1466
+ str += '}';
1488
1467
  }
1489
1468
  }
1490
1469
 
1491
- throw new Error("Unsupported Server Component type: " + describeValueForErrorMessage(type));
1492
- }
1493
-
1494
- function pingTask(request, task) {
1495
- var pingedTasks = request.pingedTasks;
1496
- pingedTasks.push(task);
1470
+ if (expandedName === undefined) {
1471
+ return str;
1472
+ }
1497
1473
 
1498
- if (pingedTasks.length === 1) {
1499
- scheduleWork(function () {
1500
- return performWork(request);
1501
- });
1474
+ if (start > -1 && length > 0) {
1475
+ var highlight = ' '.repeat(start) + '^'.repeat(length);
1476
+ return '\n ' + str + '\n ' + highlight;
1502
1477
  }
1503
- }
1504
1478
 
1505
- function createTask(request, model, context, abortSet) {
1506
- var id = request.nextChunkId++;
1507
- var task = {
1508
- id: id,
1509
- status: PENDING,
1510
- model: model,
1511
- context: context,
1512
- ping: function () {
1513
- return pingTask(request, task);
1514
- },
1515
- thenableState: null
1516
- };
1517
- abortSet.add(task);
1518
- return task;
1479
+ return '\n ' + str;
1519
1480
  }
1520
1481
 
1521
- function serializeByValueID(id) {
1522
- return '$' + id.toString(16);
1523
- }
1524
-
1525
- function serializeLazyID(id) {
1526
- return '$L' + id.toString(16);
1527
- }
1528
-
1529
- function serializePromiseID(id) {
1530
- return '$@' + id.toString(16);
1531
- }
1482
+ var ContextRegistry = ReactSharedInternals.ContextRegistry;
1483
+ function getOrCreateServerContext(globalName) {
1484
+ if (!ContextRegistry[globalName]) {
1485
+ ContextRegistry[globalName] = React.createServerContext(globalName, // $FlowFixMe function signature doesn't reflect the symbol value
1486
+ REACT_SERVER_CONTEXT_DEFAULT_VALUE_NOT_LOADED);
1487
+ }
1532
1488
 
1533
- function serializeServerReferenceID(id) {
1534
- return '$F' + id.toString(16);
1489
+ return ContextRegistry[globalName];
1535
1490
  }
1536
1491
 
1537
- function serializeSymbolReference(name) {
1538
- return '$S' + name;
1539
- }
1492
+ // Thenable<ReactClientValue>
1540
1493
 
1541
- function serializeProviderReference(name) {
1542
- return '$P' + name;
1543
- }
1494
+ var PENDING$1 = 0;
1495
+ var COMPLETED = 1;
1496
+ var ABORTED = 3;
1497
+ var ERRORED$1 = 4;
1498
+ var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
1499
+ var ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
1544
1500
 
1545
- function serializeUndefined() {
1546
- return '$undefined';
1501
+ function defaultErrorHandler(error) {
1502
+ console['error'](error); // Don't transform to our wrapper
1547
1503
  }
1548
1504
 
1549
- function serializeClientReference(request, parent, key, clientReference) {
1550
- var clientReferenceKey = getClientReferenceKey(clientReference);
1551
- var writtenClientReferences = request.writtenClientReferences;
1552
- var existingId = writtenClientReferences.get(clientReferenceKey);
1553
-
1554
- if (existingId !== undefined) {
1555
- if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1556
- // If we're encoding the "type" of an element, we can refer
1557
- // to that by a lazy reference instead of directly since React
1558
- // knows how to deal with lazy values. This lets us suspend
1559
- // on this component rather than its parent until the code has
1560
- // loaded.
1561
- return serializeLazyID(existingId);
1562
- }
1563
-
1564
- return serializeByValueID(existingId);
1505
+ var OPEN = 0;
1506
+ var CLOSING = 1;
1507
+ var CLOSED = 2;
1508
+ function createRequest(model, bundlerConfig, onError, context, identifierPrefix) {
1509
+ if (ReactCurrentCache.current !== null && ReactCurrentCache.current !== DefaultCacheDispatcher) {
1510
+ throw new Error('Currently React only supports one RSC renderer at a time.');
1565
1511
  }
1566
1512
 
1567
- try {
1568
- var clientReferenceMetadata = resolveClientReferenceMetadata(request.bundlerConfig, clientReference);
1569
- request.pendingChunks++;
1570
- var importId = request.nextChunkId++;
1571
- emitImportChunk(request, importId, clientReferenceMetadata);
1572
- writtenClientReferences.set(clientReferenceKey, importId);
1573
-
1574
- if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1575
- // If we're encoding the "type" of an element, we can refer
1576
- // to that by a lazy reference instead of directly since React
1577
- // knows how to deal with lazy values. This lets us suspend
1578
- // on this component rather than its parent until the code has
1579
- // loaded.
1580
- return serializeLazyID(importId);
1581
- }
1582
-
1583
- return serializeByValueID(importId);
1584
- } catch (x) {
1585
- request.pendingChunks++;
1586
- var errorId = request.nextChunkId++;
1587
- var digest = logRecoverableError(request, x);
1588
-
1589
- {
1590
- var _getErrorMessageAndSt3 = getErrorMessageAndStackDev(x),
1591
- message = _getErrorMessageAndSt3.message,
1592
- stack = _getErrorMessageAndSt3.stack;
1593
-
1594
- emitErrorChunkDev(request, errorId, digest, message, stack);
1513
+ ReactCurrentCache.current = DefaultCacheDispatcher;
1514
+ var abortSet = new Set();
1515
+ var pingedTasks = [];
1516
+ var request = {
1517
+ status: OPEN,
1518
+ fatalError: null,
1519
+ destination: null,
1520
+ bundlerConfig: bundlerConfig,
1521
+ cache: new Map(),
1522
+ nextChunkId: 0,
1523
+ pendingChunks: 0,
1524
+ abortableTasks: abortSet,
1525
+ pingedTasks: pingedTasks,
1526
+ completedImportChunks: [],
1527
+ completedJSONChunks: [],
1528
+ completedErrorChunks: [],
1529
+ writtenSymbols: new Map(),
1530
+ writtenClientReferences: new Map(),
1531
+ writtenServerReferences: new Map(),
1532
+ writtenProviders: new Map(),
1533
+ identifierPrefix: identifierPrefix || '',
1534
+ identifierCount: 1,
1535
+ onError: onError === undefined ? defaultErrorHandler : onError,
1536
+ // $FlowFixMe[missing-this-annot]
1537
+ toJSON: function (key, value) {
1538
+ return resolveModelToJSON(request, this, key, value);
1595
1539
  }
1596
-
1597
- return serializeByValueID(errorId);
1598
- }
1599
- }
1600
-
1601
- function serializeServerReference(request, parent, key, serverReference) {
1602
- var writtenServerReferences = request.writtenServerReferences;
1603
- var existingId = writtenServerReferences.get(serverReference);
1604
-
1605
- if (existingId !== undefined) {
1606
- return serializeServerReferenceID(existingId);
1607
- }
1608
-
1609
- var bound = getServerReferenceBoundArguments(request.bundlerConfig, serverReference);
1610
- var serverReferenceMetadata = {
1611
- id: getServerReferenceId(request.bundlerConfig, serverReference),
1612
- bound: bound ? Promise.resolve(bound) : null
1613
1540
  };
1614
1541
  request.pendingChunks++;
1615
- var metadataId = request.nextChunkId++; // We assume that this object doesn't suspend.
1616
-
1617
- var processedChunk = processModelChunk(request, metadataId, serverReferenceMetadata);
1618
- request.completedJSONChunks.push(processedChunk);
1619
- writtenServerReferences.set(serverReference, metadataId);
1620
- return serializeServerReferenceID(metadataId);
1542
+ var rootContext = createRootContext(context);
1543
+ var rootTask = createTask(request, model, rootContext, abortSet);
1544
+ pingedTasks.push(rootTask);
1545
+ return request;
1621
1546
  }
1622
1547
 
1623
- function escapeStringValue(value) {
1624
- if (value[0] === '$') {
1625
- // We need to escape $ or @ prefixed strings since we use those to encode
1626
- // references to IDs and as special symbol values.
1627
- return '$' + value;
1628
- } else {
1629
- return value;
1630
- }
1548
+ function createRootContext(reqContext) {
1549
+ return importServerContexts(reqContext);
1631
1550
  }
1632
1551
 
1633
- function isObjectPrototype(object) {
1634
- if (!object) {
1635
- return false;
1636
- }
1552
+ var POP = {};
1637
1553
 
1638
- var ObjectPrototype = Object.prototype;
1554
+ function serializeThenable(request, thenable) {
1555
+ request.pendingChunks++;
1556
+ var newTask = createTask(request, null, getActiveContext(), request.abortableTasks);
1639
1557
 
1640
- if (object === ObjectPrototype) {
1641
- return true;
1642
- } // It might be an object from a different Realm which is
1643
- // still just a plain simple object.
1558
+ switch (thenable.status) {
1559
+ case 'fulfilled':
1560
+ {
1561
+ // We have the resolved value, we can go ahead and schedule it for serialization.
1562
+ newTask.model = thenable.value;
1563
+ pingTask(request, newTask);
1564
+ return newTask.id;
1565
+ }
1644
1566
 
1567
+ case 'rejected':
1568
+ {
1569
+ var x = thenable.reason;
1570
+ var digest = logRecoverableError(request, x);
1645
1571
 
1646
- if (Object.getPrototypeOf(object)) {
1647
- return false;
1648
- }
1572
+ {
1573
+ var _getErrorMessageAndSt = getErrorMessageAndStackDev(x),
1574
+ message = _getErrorMessageAndSt.message,
1575
+ stack = _getErrorMessageAndSt.stack;
1649
1576
 
1650
- var names = Object.getOwnPropertyNames(object);
1577
+ emitErrorChunkDev(request, newTask.id, digest, message, stack);
1578
+ }
1651
1579
 
1652
- for (var i = 0; i < names.length; i++) {
1653
- if (!(names[i] in ObjectPrototype)) {
1654
- return false;
1655
- }
1656
- }
1580
+ return newTask.id;
1581
+ }
1657
1582
 
1658
- return true;
1659
- }
1583
+ default:
1584
+ {
1585
+ if (typeof thenable.status === 'string') {
1586
+ // Only instrument the thenable if the status if not defined. If
1587
+ // it's defined, but an unknown value, assume it's been instrumented by
1588
+ // some custom userspace implementation. We treat it as "pending".
1589
+ break;
1590
+ }
1660
1591
 
1661
- function isSimpleObject(object) {
1662
- if (!isObjectPrototype(Object.getPrototypeOf(object))) {
1663
- return false;
1592
+ var pendingThenable = thenable;
1593
+ pendingThenable.status = 'pending';
1594
+ pendingThenable.then(function (fulfilledValue) {
1595
+ if (thenable.status === 'pending') {
1596
+ var fulfilledThenable = thenable;
1597
+ fulfilledThenable.status = 'fulfilled';
1598
+ fulfilledThenable.value = fulfilledValue;
1599
+ }
1600
+ }, function (error) {
1601
+ if (thenable.status === 'pending') {
1602
+ var rejectedThenable = thenable;
1603
+ rejectedThenable.status = 'rejected';
1604
+ rejectedThenable.reason = error;
1605
+ }
1606
+ });
1607
+ break;
1608
+ }
1664
1609
  }
1665
1610
 
1666
- var names = Object.getOwnPropertyNames(object);
1611
+ thenable.then(function (value) {
1612
+ newTask.model = value;
1613
+ pingTask(request, newTask);
1614
+ }, function (reason) {
1615
+ newTask.status = ERRORED$1; // TODO: We should ideally do this inside performWork so it's scheduled
1667
1616
 
1668
- for (var i = 0; i < names.length; i++) {
1669
- var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
1617
+ var digest = logRecoverableError(request, reason);
1670
1618
 
1671
- if (!descriptor) {
1672
- return false;
1673
- }
1619
+ {
1620
+ var _getErrorMessageAndSt2 = getErrorMessageAndStackDev(reason),
1621
+ _message = _getErrorMessageAndSt2.message,
1622
+ _stack = _getErrorMessageAndSt2.stack;
1674
1623
 
1675
- if (!descriptor.enumerable) {
1676
- if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
1677
- // React adds key and ref getters to props objects to issue warnings.
1678
- // Those getters will not be transferred to the client, but that's ok,
1679
- // so we'll special case them.
1680
- continue;
1681
- }
1624
+ emitErrorChunkDev(request, newTask.id, digest, _message, _stack);
1625
+ }
1682
1626
 
1683
- return false;
1627
+ if (request.destination !== null) {
1628
+ flushCompletedChunks(request, request.destination);
1684
1629
  }
1630
+ });
1631
+ return newTask.id;
1632
+ }
1633
+
1634
+ function readThenable(thenable) {
1635
+ if (thenable.status === 'fulfilled') {
1636
+ return thenable.value;
1637
+ } else if (thenable.status === 'rejected') {
1638
+ throw thenable.reason;
1685
1639
  }
1686
1640
 
1687
- return true;
1641
+ throw thenable;
1688
1642
  }
1689
1643
 
1690
- function objectName(object) {
1691
- // $FlowFixMe[method-unbinding]
1692
- var name = Object.prototype.toString.call(object);
1693
- return name.replace(/^\[object (.*)\]$/, function (m, p0) {
1694
- return p0;
1695
- });
1696
- }
1697
-
1698
- function describeKeyForErrorMessage(key) {
1699
- var encodedKey = JSON.stringify(key);
1700
- return '"' + key + '"' === encodedKey ? key : encodedKey;
1701
- }
1644
+ function createLazyWrapperAroundWakeable(wakeable) {
1645
+ // This is a temporary fork of the `use` implementation until we accept
1646
+ // promises everywhere.
1647
+ var thenable = wakeable;
1702
1648
 
1703
- function describeValueForErrorMessage(value) {
1704
- switch (typeof value) {
1705
- case 'string':
1706
- {
1707
- return JSON.stringify(value.length <= 10 ? value : value.substr(0, 10) + '...');
1708
- }
1649
+ switch (thenable.status) {
1650
+ case 'fulfilled':
1651
+ case 'rejected':
1652
+ break;
1709
1653
 
1710
- case 'object':
1654
+ default:
1711
1655
  {
1712
- if (isArray(value)) {
1713
- return '[...]';
1714
- }
1715
-
1716
- var name = objectName(value);
1717
-
1718
- if (name === 'Object') {
1719
- return '{...}';
1656
+ if (typeof thenable.status === 'string') {
1657
+ // Only instrument the thenable if the status if not defined. If
1658
+ // it's defined, but an unknown value, assume it's been instrumented by
1659
+ // some custom userspace implementation. We treat it as "pending".
1660
+ break;
1720
1661
  }
1721
1662
 
1722
- return name;
1663
+ var pendingThenable = thenable;
1664
+ pendingThenable.status = 'pending';
1665
+ pendingThenable.then(function (fulfilledValue) {
1666
+ if (thenable.status === 'pending') {
1667
+ var fulfilledThenable = thenable;
1668
+ fulfilledThenable.status = 'fulfilled';
1669
+ fulfilledThenable.value = fulfilledValue;
1670
+ }
1671
+ }, function (error) {
1672
+ if (thenable.status === 'pending') {
1673
+ var rejectedThenable = thenable;
1674
+ rejectedThenable.status = 'rejected';
1675
+ rejectedThenable.reason = error;
1676
+ }
1677
+ });
1678
+ break;
1723
1679
  }
1724
-
1725
- case 'function':
1726
- return 'function';
1727
-
1728
- default:
1729
- // eslint-disable-next-line react-internal/safe-string-coercion
1730
- return String(value);
1731
1680
  }
1681
+
1682
+ var lazyType = {
1683
+ $$typeof: REACT_LAZY_TYPE,
1684
+ _payload: thenable,
1685
+ _init: readThenable
1686
+ };
1687
+ return lazyType;
1732
1688
  }
1733
1689
 
1734
- function describeElementType(type) {
1735
- if (typeof type === 'string') {
1736
- return type;
1690
+ function attemptResolveElement(request, type, key, ref, props, prevThenableState) {
1691
+ if (ref !== null && ref !== undefined) {
1692
+ // When the ref moves to the regular props object this will implicitly
1693
+ // throw for functions. We could probably relax it to a DEV warning for other
1694
+ // cases.
1695
+ throw new Error('Refs cannot be used in Server Components, nor passed to Client Components.');
1737
1696
  }
1738
1697
 
1739
- switch (type) {
1740
- case REACT_SUSPENSE_TYPE:
1741
- return 'Suspense';
1698
+ {
1699
+ jsxPropsParents.set(props, type);
1742
1700
 
1743
- case REACT_SUSPENSE_LIST_TYPE:
1744
- return 'SuspenseList';
1701
+ if (typeof props.children === 'object' && props.children !== null) {
1702
+ jsxChildrenParents.set(props.children, type);
1703
+ }
1745
1704
  }
1746
1705
 
1747
- if (typeof type === 'object') {
1748
- switch (type.$$typeof) {
1749
- case REACT_FORWARD_REF_TYPE:
1750
- return describeElementType(type.render);
1706
+ if (typeof type === 'function') {
1707
+ if (isClientReference(type)) {
1708
+ // This is a reference to a Client Component.
1709
+ return [REACT_ELEMENT_TYPE, type, key, props];
1710
+ } // This is a server-side component.
1751
1711
 
1752
- case REACT_MEMO_TYPE:
1753
- return describeElementType(type.type);
1754
1712
 
1755
- case REACT_LAZY_TYPE:
1756
- {
1757
- var lazyComponent = type;
1758
- var payload = lazyComponent._payload;
1759
- var init = lazyComponent._init;
1713
+ prepareToUseHooksForComponent(prevThenableState);
1714
+ var result = type(props);
1760
1715
 
1761
- try {
1762
- // Lazy may contain any component type so we recursively resolve it.
1763
- return describeElementType(init(payload));
1764
- } catch (x) {}
1765
- }
1766
- }
1767
- }
1716
+ if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
1717
+ // When the return value is in children position we can resolve it immediately,
1718
+ // to its value without a wrapper if it's synchronously available.
1719
+ var thenable = result;
1768
1720
 
1769
- return '';
1770
- }
1721
+ if (thenable.status === 'fulfilled') {
1722
+ return thenable.value;
1723
+ } // TODO: Once we accept Promises as children on the client, we can just return
1724
+ // the thenable here.
1771
1725
 
1772
- function describeObjectForErrorMessage(objectOrArray, expandedName) {
1773
- var objKind = objectName(objectOrArray);
1774
1726
 
1775
- if (objKind !== 'Object' && objKind !== 'Array') {
1776
- return objKind;
1777
- }
1727
+ return createLazyWrapperAroundWakeable(result);
1728
+ }
1778
1729
 
1779
- var str = '';
1780
- var start = -1;
1781
- var length = 0;
1730
+ return result;
1731
+ } else if (typeof type === 'string') {
1732
+ // This is a host element. E.g. HTML.
1733
+ return [REACT_ELEMENT_TYPE, type, key, props];
1734
+ } else if (typeof type === 'symbol') {
1735
+ if (type === REACT_FRAGMENT_TYPE) {
1736
+ // For key-less fragments, we add a small optimization to avoid serializing
1737
+ // it as a wrapper.
1738
+ // TODO: If a key is specified, we should propagate its key to any children.
1739
+ // Same as if a Server Component has a key.
1740
+ return props.children;
1741
+ } // This might be a built-in React component. We'll let the client decide.
1742
+ // Any built-in works as long as its props are serializable.
1782
1743
 
1783
- if (isArray(objectOrArray)) {
1784
- if (jsxChildrenParents.has(objectOrArray)) {
1785
- // Print JSX Children
1786
- var type = jsxChildrenParents.get(objectOrArray);
1787
- str = '<' + describeElementType(type) + '>';
1788
- var array = objectOrArray;
1789
1744
 
1790
- for (var i = 0; i < array.length; i++) {
1791
- var value = array[i];
1792
- var substr = void 0;
1745
+ return [REACT_ELEMENT_TYPE, type, key, props];
1746
+ } else if (type != null && typeof type === 'object') {
1747
+ if (isClientReference(type)) {
1748
+ // This is a reference to a Client Component.
1749
+ return [REACT_ELEMENT_TYPE, type, key, props];
1750
+ }
1793
1751
 
1794
- if (typeof value === 'string') {
1795
- substr = value;
1796
- } else if (typeof value === 'object' && value !== null) {
1797
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1798
- substr = '{' + describeObjectForErrorMessage(value) + '}';
1799
- } else {
1800
- substr = '{' + describeValueForErrorMessage(value) + '}';
1752
+ switch (type.$$typeof) {
1753
+ case REACT_LAZY_TYPE:
1754
+ {
1755
+ var payload = type._payload;
1756
+ var init = type._init;
1757
+ var wrappedType = init(payload);
1758
+ return attemptResolveElement(request, wrappedType, key, ref, props, prevThenableState);
1801
1759
  }
1802
1760
 
1803
- if ('' + i === expandedName) {
1804
- start = str.length;
1805
- length = substr.length;
1806
- str += substr;
1807
- } else if (substr.length < 15 && str.length + substr.length < 40) {
1808
- str += substr;
1809
- } else {
1810
- str += '{...}';
1761
+ case REACT_FORWARD_REF_TYPE:
1762
+ {
1763
+ var render = type.render;
1764
+ prepareToUseHooksForComponent(prevThenableState);
1765
+ return render(props, undefined);
1811
1766
  }
1812
- }
1813
-
1814
- str += '</' + describeElementType(type) + '>';
1815
- } else {
1816
- // Print Array
1817
- str = '[';
1818
- var _array = objectOrArray;
1819
1767
 
1820
- for (var _i = 0; _i < _array.length; _i++) {
1821
- if (_i > 0) {
1822
- str += ', ';
1768
+ case REACT_MEMO_TYPE:
1769
+ {
1770
+ return attemptResolveElement(request, type.type, key, ref, props, prevThenableState);
1823
1771
  }
1824
1772
 
1825
- var _value = _array[_i];
1773
+ case REACT_PROVIDER_TYPE:
1774
+ {
1775
+ pushProvider(type._context, props.value);
1826
1776
 
1827
- var _substr = void 0;
1777
+ {
1778
+ var extraKeys = Object.keys(props).filter(function (value) {
1779
+ if (value === 'children' || value === 'value') {
1780
+ return false;
1781
+ }
1828
1782
 
1829
- if (typeof _value === 'object' && _value !== null) {
1830
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1831
- _substr = describeObjectForErrorMessage(_value);
1832
- } else {
1833
- _substr = describeValueForErrorMessage(_value);
1834
- }
1783
+ return true;
1784
+ });
1835
1785
 
1836
- if ('' + _i === expandedName) {
1837
- start = str.length;
1838
- length = _substr.length;
1839
- str += _substr;
1840
- } else if (_substr.length < 10 && str.length + _substr.length < 40) {
1841
- str += _substr;
1842
- } else {
1843
- str += '...';
1844
- }
1845
- }
1786
+ if (extraKeys.length !== 0) {
1787
+ error('ServerContext can only have a value prop and children. Found: %s', JSON.stringify(extraKeys));
1788
+ }
1789
+ }
1846
1790
 
1847
- str += ']';
1791
+ return [REACT_ELEMENT_TYPE, type, key, // Rely on __popProvider being serialized last to pop the provider.
1792
+ {
1793
+ value: props.value,
1794
+ children: props.children,
1795
+ __pop: POP
1796
+ }];
1797
+ }
1848
1798
  }
1849
- } else {
1850
- if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
1851
- str = '<' + describeElementType(objectOrArray.type) + '/>';
1852
- } else if (jsxPropsParents.has(objectOrArray)) {
1853
- // Print JSX
1854
- var _type = jsxPropsParents.get(objectOrArray);
1799
+ }
1855
1800
 
1856
- str = '<' + (describeElementType(_type) || '...');
1857
- var object = objectOrArray;
1858
- var names = Object.keys(object);
1801
+ throw new Error("Unsupported Server Component type: " + describeValueForErrorMessage(type));
1802
+ }
1859
1803
 
1860
- for (var _i2 = 0; _i2 < names.length; _i2++) {
1861
- str += ' ';
1862
- var name = names[_i2];
1863
- str += describeKeyForErrorMessage(name) + '=';
1864
- var _value2 = object[name];
1804
+ function pingTask(request, task) {
1805
+ var pingedTasks = request.pingedTasks;
1806
+ pingedTasks.push(task);
1865
1807
 
1866
- var _substr2 = void 0;
1808
+ if (pingedTasks.length === 1) {
1809
+ scheduleWork(function () {
1810
+ return performWork(request);
1811
+ });
1812
+ }
1813
+ }
1867
1814
 
1868
- if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
1869
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1870
- _substr2 = describeObjectForErrorMessage(_value2);
1871
- } else {
1872
- _substr2 = describeValueForErrorMessage(_value2);
1873
- }
1815
+ function createTask(request, model, context, abortSet) {
1816
+ var id = request.nextChunkId++;
1817
+ var task = {
1818
+ id: id,
1819
+ status: PENDING$1,
1820
+ model: model,
1821
+ context: context,
1822
+ ping: function () {
1823
+ return pingTask(request, task);
1824
+ },
1825
+ thenableState: null
1826
+ };
1827
+ abortSet.add(task);
1828
+ return task;
1829
+ }
1874
1830
 
1875
- if (typeof _value2 !== 'string') {
1876
- _substr2 = '{' + _substr2 + '}';
1877
- }
1831
+ function serializeByValueID(id) {
1832
+ return '$' + id.toString(16);
1833
+ }
1878
1834
 
1879
- if (name === expandedName) {
1880
- start = str.length;
1881
- length = _substr2.length;
1882
- str += _substr2;
1883
- } else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
1884
- str += _substr2;
1885
- } else {
1886
- str += '...';
1887
- }
1888
- }
1835
+ function serializeLazyID(id) {
1836
+ return '$L' + id.toString(16);
1837
+ }
1889
1838
 
1890
- str += '>';
1891
- } else {
1892
- // Print Object
1893
- str = '{';
1894
- var _object = objectOrArray;
1839
+ function serializePromiseID(id) {
1840
+ return '$@' + id.toString(16);
1841
+ }
1895
1842
 
1896
- var _names = Object.keys(_object);
1843
+ function serializeServerReferenceID(id) {
1844
+ return '$F' + id.toString(16);
1845
+ }
1897
1846
 
1898
- for (var _i3 = 0; _i3 < _names.length; _i3++) {
1899
- if (_i3 > 0) {
1900
- str += ', ';
1901
- }
1847
+ function serializeSymbolReference(name) {
1848
+ return '$S' + name;
1849
+ }
1902
1850
 
1903
- var _name = _names[_i3];
1904
- str += describeKeyForErrorMessage(_name) + ': ';
1905
- var _value3 = _object[_name];
1851
+ function serializeProviderReference(name) {
1852
+ return '$P' + name;
1853
+ }
1906
1854
 
1907
- var _substr3 = void 0;
1855
+ function serializeUndefined() {
1856
+ return '$undefined';
1857
+ }
1908
1858
 
1909
- if (typeof _value3 === 'object' && _value3 !== null) {
1910
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1911
- _substr3 = describeObjectForErrorMessage(_value3);
1912
- } else {
1913
- _substr3 = describeValueForErrorMessage(_value3);
1914
- }
1859
+ function serializeClientReference(request, parent, key, clientReference) {
1860
+ var clientReferenceKey = getClientReferenceKey(clientReference);
1861
+ var writtenClientReferences = request.writtenClientReferences;
1862
+ var existingId = writtenClientReferences.get(clientReferenceKey);
1915
1863
 
1916
- if (_name === expandedName) {
1917
- start = str.length;
1918
- length = _substr3.length;
1919
- str += _substr3;
1920
- } else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
1921
- str += _substr3;
1922
- } else {
1923
- str += '...';
1924
- }
1925
- }
1864
+ if (existingId !== undefined) {
1865
+ if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1866
+ // If we're encoding the "type" of an element, we can refer
1867
+ // to that by a lazy reference instead of directly since React
1868
+ // knows how to deal with lazy values. This lets us suspend
1869
+ // on this component rather than its parent until the code has
1870
+ // loaded.
1871
+ return serializeLazyID(existingId);
1872
+ }
1873
+
1874
+ return serializeByValueID(existingId);
1875
+ }
1876
+
1877
+ try {
1878
+ var clientReferenceMetadata = resolveClientReferenceMetadata(request.bundlerConfig, clientReference);
1879
+ request.pendingChunks++;
1880
+ var importId = request.nextChunkId++;
1881
+ emitImportChunk(request, importId, clientReferenceMetadata);
1882
+ writtenClientReferences.set(clientReferenceKey, importId);
1883
+
1884
+ if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1885
+ // If we're encoding the "type" of an element, we can refer
1886
+ // to that by a lazy reference instead of directly since React
1887
+ // knows how to deal with lazy values. This lets us suspend
1888
+ // on this component rather than its parent until the code has
1889
+ // loaded.
1890
+ return serializeLazyID(importId);
1891
+ }
1892
+
1893
+ return serializeByValueID(importId);
1894
+ } catch (x) {
1895
+ request.pendingChunks++;
1896
+ var errorId = request.nextChunkId++;
1897
+ var digest = logRecoverableError(request, x);
1926
1898
 
1927
- str += '}';
1899
+ {
1900
+ var _getErrorMessageAndSt3 = getErrorMessageAndStackDev(x),
1901
+ message = _getErrorMessageAndSt3.message,
1902
+ stack = _getErrorMessageAndSt3.stack;
1903
+
1904
+ emitErrorChunkDev(request, errorId, digest, message, stack);
1928
1905
  }
1929
- }
1930
1906
 
1931
- if (expandedName === undefined) {
1932
- return str;
1907
+ return serializeByValueID(errorId);
1933
1908
  }
1909
+ }
1934
1910
 
1935
- if (start > -1 && length > 0) {
1936
- var highlight = ' '.repeat(start) + '^'.repeat(length);
1937
- return '\n ' + str + '\n ' + highlight;
1911
+ function serializeServerReference(request, parent, key, serverReference) {
1912
+ var writtenServerReferences = request.writtenServerReferences;
1913
+ var existingId = writtenServerReferences.get(serverReference);
1914
+
1915
+ if (existingId !== undefined) {
1916
+ return serializeServerReferenceID(existingId);
1938
1917
  }
1939
1918
 
1940
- return '\n ' + str;
1919
+ var bound = getServerReferenceBoundArguments(request.bundlerConfig, serverReference);
1920
+ var serverReferenceMetadata = {
1921
+ id: getServerReferenceId(request.bundlerConfig, serverReference),
1922
+ bound: bound ? Promise.resolve(bound) : null
1923
+ };
1924
+ request.pendingChunks++;
1925
+ var metadataId = request.nextChunkId++; // We assume that this object doesn't suspend.
1926
+
1927
+ var processedChunk = processModelChunk(request, metadataId, serverReferenceMetadata);
1928
+ request.completedJSONChunks.push(processedChunk);
1929
+ writtenServerReferences.set(serverReference, metadataId);
1930
+ return serializeServerReferenceID(metadataId);
1931
+ }
1932
+
1933
+ function escapeStringValue(value) {
1934
+ if (value[0] === '$') {
1935
+ // We need to escape $ prefixed strings since we use those to encode
1936
+ // references to IDs and as special symbol values.
1937
+ return '$' + value;
1938
+ } else {
1939
+ return value;
1940
+ }
1941
1941
  }
1942
1942
 
1943
1943
  var insideContextProps = null;
@@ -2241,7 +2241,7 @@ function emitProviderChunk(request, id, contextName) {
2241
2241
  }
2242
2242
 
2243
2243
  function retryTask(request, task) {
2244
- if (task.status !== PENDING) {
2244
+ if (task.status !== PENDING$1) {
2245
2245
  // We completed this by other means before we had a chance to retry it.
2246
2246
  return;
2247
2247
  }
@@ -2296,7 +2296,7 @@ function retryTask(request, task) {
2296
2296
  return;
2297
2297
  } else {
2298
2298
  request.abortableTasks.delete(task);
2299
- task.status = ERRORED;
2299
+ task.status = ERRORED$1;
2300
2300
  var digest = logRecoverableError(request, x);
2301
2301
 
2302
2302
  {
@@ -2414,7 +2414,7 @@ function flushCompletedChunks(request, destination) {
2414
2414
 
2415
2415
  if (request.pendingChunks === 0) {
2416
2416
  // We're done.
2417
- close(destination);
2417
+ close$1(destination);
2418
2418
  }
2419
2419
  }
2420
2420
 
@@ -2511,6 +2511,506 @@ function importServerContexts(contexts) {
2511
2511
  return rootContextSnapshot;
2512
2512
  }
2513
2513
 
2514
+ // eslint-disable-next-line no-unused-vars
2515
+ function resolveServerReference(bundlerConfig, id) {
2516
+ // This needs to return async: true if it's an async module.
2517
+ return bundlerConfig[id];
2518
+ } // The chunk cache contains all the chunks we've preloaded so far.
2519
+ // If they're still pending they're a thenable. This map also exists
2520
+ // in Webpack but unfortunately it's not exposed so we have to
2521
+ // replicate it in user space. null means that it has already loaded.
2522
+
2523
+ var chunkCache = new Map();
2524
+ var asyncModuleCache = new Map();
2525
+
2526
+ function ignoreReject() {// We rely on rejected promises to be handled by another listener.
2527
+ } // Start preloading the modules since we might need them soon.
2528
+ // This function doesn't suspend.
2529
+
2530
+
2531
+ function preloadModule(metadata) {
2532
+ var chunks = metadata.chunks;
2533
+ var promises = [];
2534
+
2535
+ for (var i = 0; i < chunks.length; i++) {
2536
+ var chunkId = chunks[i];
2537
+ var entry = chunkCache.get(chunkId);
2538
+
2539
+ if (entry === undefined) {
2540
+ var thenable = __webpack_chunk_load__(chunkId);
2541
+
2542
+ promises.push(thenable); // $FlowFixMe[method-unbinding]
2543
+
2544
+ var resolve = chunkCache.set.bind(chunkCache, chunkId, null);
2545
+ thenable.then(resolve, ignoreReject);
2546
+ chunkCache.set(chunkId, thenable);
2547
+ } else if (entry !== null) {
2548
+ promises.push(entry);
2549
+ }
2550
+ }
2551
+
2552
+ if (metadata.async) {
2553
+ var existingPromise = asyncModuleCache.get(metadata.id);
2554
+
2555
+ if (existingPromise) {
2556
+ if (existingPromise.status === 'fulfilled') {
2557
+ return null;
2558
+ }
2559
+
2560
+ return existingPromise;
2561
+ } else {
2562
+ var modulePromise = Promise.all(promises).then(function () {
2563
+ return __webpack_require__(metadata.id);
2564
+ });
2565
+ modulePromise.then(function (value) {
2566
+ var fulfilledThenable = modulePromise;
2567
+ fulfilledThenable.status = 'fulfilled';
2568
+ fulfilledThenable.value = value;
2569
+ }, function (reason) {
2570
+ var rejectedThenable = modulePromise;
2571
+ rejectedThenable.status = 'rejected';
2572
+ rejectedThenable.reason = reason;
2573
+ });
2574
+ asyncModuleCache.set(metadata.id, modulePromise);
2575
+ return modulePromise;
2576
+ }
2577
+ } else if (promises.length > 0) {
2578
+ return Promise.all(promises);
2579
+ } else {
2580
+ return null;
2581
+ }
2582
+ } // Actually require the module or suspend if it's not yet ready.
2583
+ // Increase priority if necessary.
2584
+
2585
+ function requireModule(metadata) {
2586
+ var moduleExports;
2587
+
2588
+ if (metadata.async) {
2589
+ // We assume that preloadModule has been called before, which
2590
+ // should have added something to the module cache.
2591
+ var promise = asyncModuleCache.get(metadata.id);
2592
+
2593
+ if (promise.status === 'fulfilled') {
2594
+ moduleExports = promise.value;
2595
+ } else {
2596
+ throw promise.reason;
2597
+ }
2598
+ } else {
2599
+ moduleExports = __webpack_require__(metadata.id);
2600
+ }
2601
+
2602
+ if (metadata.name === '*') {
2603
+ // This is a placeholder value that represents that the caller imported this
2604
+ // as a CommonJS module as is.
2605
+ return moduleExports;
2606
+ }
2607
+
2608
+ if (metadata.name === '') {
2609
+ // This is a placeholder value that represents that the caller accessed the
2610
+ // default property of this if it was an ESM interop module.
2611
+ return moduleExports.__esModule ? moduleExports.default : moduleExports;
2612
+ }
2613
+
2614
+ return moduleExports[metadata.name];
2615
+ }
2616
+
2617
+ // The server acts as a Client of itself when resolving Server References.
2618
+ var PENDING = 'pending';
2619
+ var BLOCKED = 'blocked';
2620
+ var RESOLVED_MODEL = 'resolved_model';
2621
+ var INITIALIZED = 'fulfilled';
2622
+ var ERRORED = 'rejected'; // $FlowFixMe[missing-this-annot]
2623
+
2624
+ function Chunk(status, value, reason, response) {
2625
+ this.status = status;
2626
+ this.value = value;
2627
+ this.reason = reason;
2628
+ this._response = response;
2629
+ } // We subclass Promise.prototype so that we get other methods like .catch
2630
+
2631
+
2632
+ Chunk.prototype = Object.create(Promise.prototype); // TODO: This doesn't return a new Promise chain unlike the real .then
2633
+
2634
+ Chunk.prototype.then = function (resolve, reject) {
2635
+ var chunk = this; // If we have resolved content, we try to initialize it first which
2636
+ // might put us back into one of the other states.
2637
+
2638
+ switch (chunk.status) {
2639
+ case RESOLVED_MODEL:
2640
+ initializeModelChunk(chunk);
2641
+ break;
2642
+ } // The status might have changed after initialization.
2643
+
2644
+
2645
+ switch (chunk.status) {
2646
+ case INITIALIZED:
2647
+ resolve(chunk.value);
2648
+ break;
2649
+
2650
+ case PENDING:
2651
+ case BLOCKED:
2652
+ if (resolve) {
2653
+ if (chunk.value === null) {
2654
+ chunk.value = [];
2655
+ }
2656
+
2657
+ chunk.value.push(resolve);
2658
+ }
2659
+
2660
+ if (reject) {
2661
+ if (chunk.reason === null) {
2662
+ chunk.reason = [];
2663
+ }
2664
+
2665
+ chunk.reason.push(reject);
2666
+ }
2667
+
2668
+ break;
2669
+
2670
+ default:
2671
+ reject(chunk.reason);
2672
+ break;
2673
+ }
2674
+ };
2675
+
2676
+ function getRoot(response) {
2677
+ var chunk = getChunk(response, 0);
2678
+ return chunk;
2679
+ }
2680
+
2681
+ function createPendingChunk(response) {
2682
+ // $FlowFixMe Flow doesn't support functions as constructors
2683
+ return new Chunk(PENDING, null, null, response);
2684
+ }
2685
+
2686
+ function wakeChunk(listeners, value) {
2687
+ for (var i = 0; i < listeners.length; i++) {
2688
+ var listener = listeners[i];
2689
+ listener(value);
2690
+ }
2691
+ }
2692
+
2693
+ function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
2694
+ switch (chunk.status) {
2695
+ case INITIALIZED:
2696
+ wakeChunk(resolveListeners, chunk.value);
2697
+ break;
2698
+
2699
+ case PENDING:
2700
+ case BLOCKED:
2701
+ chunk.value = resolveListeners;
2702
+ chunk.reason = rejectListeners;
2703
+ break;
2704
+
2705
+ case ERRORED:
2706
+ if (rejectListeners) {
2707
+ wakeChunk(rejectListeners, chunk.reason);
2708
+ }
2709
+
2710
+ break;
2711
+ }
2712
+ }
2713
+
2714
+ function triggerErrorOnChunk(chunk, error) {
2715
+ if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
2716
+ // We already resolved. We didn't expect to see this.
2717
+ return;
2718
+ }
2719
+
2720
+ var listeners = chunk.reason;
2721
+ var erroredChunk = chunk;
2722
+ erroredChunk.status = ERRORED;
2723
+ erroredChunk.reason = error;
2724
+
2725
+ if (listeners !== null) {
2726
+ wakeChunk(listeners, error);
2727
+ }
2728
+ }
2729
+
2730
+ function createResolvedModelChunk(response, value) {
2731
+ // $FlowFixMe Flow doesn't support functions as constructors
2732
+ return new Chunk(RESOLVED_MODEL, value, null, response);
2733
+ }
2734
+
2735
+ function resolveModelChunk(chunk, value) {
2736
+ if (chunk.status !== PENDING) {
2737
+ // We already resolved. We didn't expect to see this.
2738
+ return;
2739
+ }
2740
+
2741
+ var resolveListeners = chunk.value;
2742
+ var rejectListeners = chunk.reason;
2743
+ var resolvedChunk = chunk;
2744
+ resolvedChunk.status = RESOLVED_MODEL;
2745
+ resolvedChunk.value = value;
2746
+
2747
+ if (resolveListeners !== null) {
2748
+ // This is unfortunate that we're reading this eagerly if
2749
+ // we already have listeners attached since they might no
2750
+ // longer be rendered or might not be the highest pri.
2751
+ initializeModelChunk(resolvedChunk); // The status might have changed after initialization.
2752
+
2753
+ wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
2754
+ }
2755
+ }
2756
+
2757
+ function bindArgs(fn, args) {
2758
+ return fn.bind.apply(fn, [null].concat(args));
2759
+ }
2760
+
2761
+ function loadServerReference(response, id, bound, parentChunk, parentObject, key) {
2762
+ var serverReference = resolveServerReference(response._bundlerConfig, id); // We expect most servers to not really need this because you'd just have all
2763
+ // the relevant modules already loaded but it allows for lazy loading of code
2764
+ // if needed.
2765
+
2766
+ var preloadPromise = preloadModule(serverReference);
2767
+ var promise;
2768
+
2769
+ if (bound) {
2770
+ promise = Promise.all([bound, preloadPromise]).then(function (_ref) {
2771
+ var args = _ref[0];
2772
+ return bindArgs(requireModule(serverReference), args);
2773
+ });
2774
+ } else {
2775
+ if (preloadPromise) {
2776
+ promise = Promise.resolve(preloadPromise).then(function () {
2777
+ return requireModule(serverReference);
2778
+ });
2779
+ } else {
2780
+ // Synchronously available
2781
+ return requireModule(serverReference);
2782
+ }
2783
+ }
2784
+
2785
+ promise.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk)); // We need a placeholder value that will be replaced later.
2786
+
2787
+ return null;
2788
+ }
2789
+
2790
+ var initializingChunk = null;
2791
+ var initializingChunkBlockedModel = null;
2792
+
2793
+ function initializeModelChunk(chunk) {
2794
+ var prevChunk = initializingChunk;
2795
+ var prevBlocked = initializingChunkBlockedModel;
2796
+ initializingChunk = chunk;
2797
+ initializingChunkBlockedModel = null;
2798
+
2799
+ try {
2800
+ var value = JSON.parse(chunk.value, chunk._response._fromJSON);
2801
+
2802
+ if (initializingChunkBlockedModel !== null && initializingChunkBlockedModel.deps > 0) {
2803
+ initializingChunkBlockedModel.value = value; // We discovered new dependencies on modules that are not yet resolved.
2804
+ // We have to go the BLOCKED state until they're resolved.
2805
+
2806
+ var blockedChunk = chunk;
2807
+ blockedChunk.status = BLOCKED;
2808
+ blockedChunk.value = null;
2809
+ blockedChunk.reason = null;
2810
+ } else {
2811
+ var initializedChunk = chunk;
2812
+ initializedChunk.status = INITIALIZED;
2813
+ initializedChunk.value = value;
2814
+ }
2815
+ } catch (error) {
2816
+ var erroredChunk = chunk;
2817
+ erroredChunk.status = ERRORED;
2818
+ erroredChunk.reason = error;
2819
+ } finally {
2820
+ initializingChunk = prevChunk;
2821
+ initializingChunkBlockedModel = prevBlocked;
2822
+ }
2823
+ } // Report that any missing chunks in the model is now going to throw this
2824
+ // error upon read. Also notify any pending promises.
2825
+
2826
+
2827
+ function reportGlobalError(response, error) {
2828
+ response._chunks.forEach(function (chunk) {
2829
+ // If this chunk was already resolved or errored, it won't
2830
+ // trigger an error but if it wasn't then we need to
2831
+ // because we won't be getting any new data to resolve it.
2832
+ if (chunk.status === PENDING) {
2833
+ triggerErrorOnChunk(chunk, error);
2834
+ }
2835
+ });
2836
+ }
2837
+
2838
+ function getChunk(response, id) {
2839
+ var chunks = response._chunks;
2840
+ var chunk = chunks.get(id);
2841
+
2842
+ if (!chunk) {
2843
+ chunk = createPendingChunk(response);
2844
+ chunks.set(id, chunk);
2845
+ }
2846
+
2847
+ return chunk;
2848
+ }
2849
+
2850
+ function createModelResolver(chunk, parentObject, key) {
2851
+ var blocked;
2852
+
2853
+ if (initializingChunkBlockedModel) {
2854
+ blocked = initializingChunkBlockedModel;
2855
+ blocked.deps++;
2856
+ } else {
2857
+ blocked = initializingChunkBlockedModel = {
2858
+ deps: 1,
2859
+ value: null
2860
+ };
2861
+ }
2862
+
2863
+ return function (value) {
2864
+ parentObject[key] = value;
2865
+ blocked.deps--;
2866
+
2867
+ if (blocked.deps === 0) {
2868
+ if (chunk.status !== BLOCKED) {
2869
+ return;
2870
+ }
2871
+
2872
+ var resolveListeners = chunk.value;
2873
+ var initializedChunk = chunk;
2874
+ initializedChunk.status = INITIALIZED;
2875
+ initializedChunk.value = blocked.value;
2876
+
2877
+ if (resolveListeners !== null) {
2878
+ wakeChunk(resolveListeners, blocked.value);
2879
+ }
2880
+ }
2881
+ };
2882
+ }
2883
+
2884
+ function createModelReject(chunk) {
2885
+ return function (error) {
2886
+ return triggerErrorOnChunk(chunk, error);
2887
+ };
2888
+ }
2889
+
2890
+ function parseModelString(response, parentObject, key, value) {
2891
+ if (value[0] === '$') {
2892
+ switch (value[1]) {
2893
+ case '$':
2894
+ {
2895
+ // This was an escaped string value.
2896
+ return value.substring(1);
2897
+ }
2898
+
2899
+ case '@':
2900
+ {
2901
+ // Promise
2902
+ var id = parseInt(value.substring(2), 16);
2903
+ var chunk = getChunk(response, id);
2904
+ return chunk;
2905
+ }
2906
+
2907
+ case 'S':
2908
+ {
2909
+ // Symbol
2910
+ return Symbol.for(value.substring(2));
2911
+ }
2912
+
2913
+ case 'F':
2914
+ {
2915
+ // Server Reference
2916
+ var _id = parseInt(value.substring(2), 16);
2917
+
2918
+ var _chunk = getChunk(response, _id);
2919
+
2920
+ if (_chunk.status === RESOLVED_MODEL) {
2921
+ initializeModelChunk(_chunk);
2922
+ }
2923
+
2924
+ if (_chunk.status !== INITIALIZED) {
2925
+ // We know that this is emitted earlier so otherwise it's an error.
2926
+ throw _chunk.reason;
2927
+ } // TODO: Just encode this in the reference inline instead of as a model.
2928
+
2929
+
2930
+ var metaData = _chunk.value;
2931
+ return loadServerReference(response, metaData.id, metaData.bound, initializingChunk, parentObject, key);
2932
+ }
2933
+
2934
+ case 'u':
2935
+ {
2936
+ // matches "$undefined"
2937
+ // Special encoding for `undefined` which can't be serialized as JSON otherwise.
2938
+ return undefined;
2939
+ }
2940
+
2941
+ default:
2942
+ {
2943
+ // We assume that anything else is a reference ID.
2944
+ var _id2 = parseInt(value.substring(1), 16);
2945
+
2946
+ var _chunk2 = getChunk(response, _id2);
2947
+
2948
+ switch (_chunk2.status) {
2949
+ case RESOLVED_MODEL:
2950
+ initializeModelChunk(_chunk2);
2951
+ break;
2952
+ } // The status might have changed after initialization.
2953
+
2954
+
2955
+ switch (_chunk2.status) {
2956
+ case INITIALIZED:
2957
+ return _chunk2.value;
2958
+
2959
+ case PENDING:
2960
+ case BLOCKED:
2961
+ var parentChunk = initializingChunk;
2962
+
2963
+ _chunk2.then(createModelResolver(parentChunk, parentObject, key), createModelReject(parentChunk));
2964
+
2965
+ return null;
2966
+
2967
+ default:
2968
+ throw _chunk2.reason;
2969
+ }
2970
+ }
2971
+ }
2972
+ }
2973
+
2974
+ return value;
2975
+ }
2976
+
2977
+ function createResponse(bundlerConfig) {
2978
+ var chunks = new Map();
2979
+ var response = {
2980
+ _bundlerConfig: bundlerConfig,
2981
+ _chunks: chunks,
2982
+ _fromJSON: function (key, value) {
2983
+ if (typeof value === 'string') {
2984
+ // We can't use .bind here because we need the "this" value.
2985
+ return parseModelString(response, this, key, value);
2986
+ }
2987
+
2988
+ return value;
2989
+ }
2990
+ };
2991
+ return response;
2992
+ }
2993
+ function resolveField(response, id, model) {
2994
+ var chunks = response._chunks;
2995
+ var chunk = chunks.get(id);
2996
+
2997
+ if (!chunk) {
2998
+ chunks.set(id, createResolvedModelChunk(response, model));
2999
+ } else {
3000
+ resolveModelChunk(chunk, model);
3001
+ }
3002
+ }
3003
+ function resolveFile(response, id, file) {
3004
+ throw new Error('Not implemented.');
3005
+ }
3006
+ function close(response) {
3007
+ // In case there are any remaining unresolved chunks, they won't
3008
+ // be resolved now. So we need to issue an error to those.
3009
+ // Ideally we should be able to early bail out if we kept a
3010
+ // ref count of pending chunks.
3011
+ reportGlobalError(response, new Error('Connection closed.'));
3012
+ }
3013
+
2514
3014
  function renderToReadableStream(model, webpackMap, options) {
2515
3015
  var request = createRequest(model, webpackMap, options ? options.onError : undefined, options ? options.context : undefined, options ? options.identifierPrefix : undefined);
2516
3016
 
@@ -2545,6 +3045,29 @@ function renderToReadableStream(model, webpackMap, options) {
2545
3045
  return stream;
2546
3046
  }
2547
3047
 
3048
+ function decodeReply(body, webpackMap) {
3049
+ var response = createResponse(webpackMap);
3050
+
3051
+ if (typeof body === 'string') {
3052
+ resolveField(response, 0, body);
3053
+ } else {
3054
+ // $FlowFixMe[prop-missing] Flow doesn't know that forEach exists.
3055
+ body.forEach(function (value, key) {
3056
+ var id = +key;
3057
+
3058
+ if (typeof value === 'string') {
3059
+ resolveField(response, id, value);
3060
+ } else {
3061
+ resolveFile();
3062
+ }
3063
+ });
3064
+ }
3065
+
3066
+ close(response);
3067
+ return getRoot(response);
3068
+ }
3069
+
3070
+ exports.decodeReply = decodeReply;
2548
3071
  exports.renderToReadableStream = renderToReadableStream;
2549
3072
  })();
2550
3073
  }