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