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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. package/cjs/react-server-dom-webpack-client.browser.development.js +589 -1
  2. package/cjs/react-server-dom-webpack-client.browser.production.min.js +22 -19
  3. package/cjs/react-server-dom-webpack-client.edge.development.js +11 -1
  4. package/cjs/react-server-dom-webpack-client.edge.production.min.js +16 -16
  5. package/cjs/react-server-dom-webpack-client.node.development.js +11 -1
  6. package/cjs/react-server-dom-webpack-client.node.production.min.js +18 -18
  7. package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +10 -0
  8. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +15 -15
  9. package/cjs/react-server-dom-webpack-server.browser.development.js +1140 -609
  10. package/cjs/react-server-dom-webpack-server.browser.production.min.js +57 -46
  11. package/cjs/react-server-dom-webpack-server.edge.development.js +1140 -609
  12. package/cjs/react-server-dom-webpack-server.edge.production.min.js +54 -43
  13. package/cjs/react-server-dom-webpack-server.node.development.js +1181 -611
  14. package/cjs/react-server-dom-webpack-server.node.production.min.js +57 -45
  15. package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1139 -609
  16. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +51 -40
  17. package/package.json +3 -3
  18. package/umd/react-server-dom-webpack-client.browser.development.js +589 -1
  19. package/umd/react-server-dom-webpack-client.browser.production.min.js +17 -14
  20. package/umd/react-server-dom-webpack-server.browser.development.js +1140 -609
  21. package/umd/react-server-dom-webpack-server.browser.production.min.js +42 -35
@@ -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,775 +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
- }
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
+ }
1517
1477
 
1518
- function serializePromiseID(id) {
1519
- return '$@' + id.toString(16);
1478
+ return ContextRegistry[globalName];
1520
1479
  }
1521
1480
 
1522
- function serializeServerReferenceID(id) {
1523
- return '$F' + id.toString(16);
1524
- }
1481
+ // Thenable<ReactClientValue>
1525
1482
 
1526
- function serializeSymbolReference(name) {
1527
- return '$S' + name;
1528
- }
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;
1529
1489
 
1530
- function serializeProviderReference(name) {
1531
- return '$P' + name;
1490
+ function defaultErrorHandler(error) {
1491
+ console['error'](error); // Don't transform to our wrapper
1532
1492
  }
1533
1493
 
1534
- function serializeClientReference(request, parent, key, clientReference) {
1535
- var clientReferenceKey = getClientReferenceKey(clientReference);
1536
- var writtenClientReferences = request.writtenClientReferences;
1537
- var existingId = writtenClientReferences.get(clientReferenceKey);
1538
-
1539
- if (existingId !== undefined) {
1540
- if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1541
- // If we're encoding the "type" of an element, we can refer
1542
- // to that by a lazy reference instead of directly since React
1543
- // knows how to deal with lazy values. This lets us suspend
1544
- // on this component rather than its parent until the code has
1545
- // loaded.
1546
- return serializeLazyID(existingId);
1547
- }
1548
-
1549
- 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.');
1550
1500
  }
1551
1501
 
1552
- try {
1553
- var clientReferenceMetadata = resolveClientReferenceMetadata(request.bundlerConfig, clientReference);
1554
- request.pendingChunks++;
1555
- var importId = request.nextChunkId++;
1556
- emitImportChunk(request, importId, clientReferenceMetadata);
1557
- writtenClientReferences.set(clientReferenceKey, importId);
1558
-
1559
- if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1560
- // If we're encoding the "type" of an element, we can refer
1561
- // to that by a lazy reference instead of directly since React
1562
- // knows how to deal with lazy values. This lets us suspend
1563
- // on this component rather than its parent until the code has
1564
- // loaded.
1565
- return serializeLazyID(importId);
1566
- }
1567
-
1568
- return serializeByValueID(importId);
1569
- } catch (x) {
1570
- request.pendingChunks++;
1571
- var errorId = request.nextChunkId++;
1572
- var digest = logRecoverableError(request, x);
1573
-
1574
- {
1575
- var _getErrorMessageAndSt3 = getErrorMessageAndStackDev(x),
1576
- message = _getErrorMessageAndSt3.message,
1577
- stack = _getErrorMessageAndSt3.stack;
1578
-
1579
- 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);
1580
1528
  }
1581
-
1582
- return serializeByValueID(errorId);
1583
- }
1584
- }
1585
-
1586
- function serializeServerReference(request, parent, key, serverReference) {
1587
- var writtenServerReferences = request.writtenServerReferences;
1588
- var existingId = writtenServerReferences.get(serverReference);
1589
-
1590
- if (existingId !== undefined) {
1591
- return serializeServerReferenceID(existingId);
1592
- }
1593
-
1594
- var bound = getServerReferenceBoundArguments(request.bundlerConfig, serverReference);
1595
- var serverReferenceMetadata = {
1596
- id: getServerReferenceId(request.bundlerConfig, serverReference),
1597
- bound: bound ? Promise.resolve(bound) : null
1598
1529
  };
1599
1530
  request.pendingChunks++;
1600
- var metadataId = request.nextChunkId++; // We assume that this object doesn't suspend.
1601
-
1602
- var processedChunk = processModelChunk(request, metadataId, serverReferenceMetadata);
1603
- request.completedJSONChunks.push(processedChunk);
1604
- writtenServerReferences.set(serverReference, metadataId);
1605
- return serializeServerReferenceID(metadataId);
1531
+ var rootContext = createRootContext(context);
1532
+ var rootTask = createTask(request, model, rootContext, abortSet);
1533
+ pingedTasks.push(rootTask);
1534
+ return request;
1606
1535
  }
1607
1536
 
1608
- function escapeStringValue(value) {
1609
- if (value[0] === '$') {
1610
- // We need to escape $ or @ prefixed strings since we use those to encode
1611
- // references to IDs and as special symbol values.
1612
- return '$' + value;
1613
- } else {
1614
- return value;
1615
- }
1537
+ function createRootContext(reqContext) {
1538
+ return importServerContexts(reqContext);
1616
1539
  }
1617
1540
 
1618
- function isObjectPrototype(object) {
1619
- if (!object) {
1620
- return false;
1621
- }
1541
+ var POP = {};
1622
1542
 
1623
- var ObjectPrototype = Object.prototype;
1543
+ function serializeThenable(request, thenable) {
1544
+ request.pendingChunks++;
1545
+ var newTask = createTask(request, null, getActiveContext(), request.abortableTasks);
1624
1546
 
1625
- if (object === ObjectPrototype) {
1626
- return true;
1627
- } // It might be an object from a different Realm which is
1628
- // 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
+ }
1629
1555
 
1556
+ case 'rejected':
1557
+ {
1558
+ var x = thenable.reason;
1559
+ var digest = logRecoverableError(request, x);
1630
1560
 
1631
- if (Object.getPrototypeOf(object)) {
1632
- return false;
1633
- }
1561
+ {
1562
+ var _getErrorMessageAndSt = getErrorMessageAndStackDev(x),
1563
+ message = _getErrorMessageAndSt.message,
1564
+ stack = _getErrorMessageAndSt.stack;
1634
1565
 
1635
- var names = Object.getOwnPropertyNames(object);
1566
+ emitErrorChunkDev(request, newTask.id, digest, message, stack);
1567
+ }
1636
1568
 
1637
- for (var i = 0; i < names.length; i++) {
1638
- if (!(names[i] in ObjectPrototype)) {
1639
- return false;
1640
- }
1641
- }
1569
+ return newTask.id;
1570
+ }
1642
1571
 
1643
- return true;
1644
- }
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
+ }
1645
1580
 
1646
- function isSimpleObject(object) {
1647
- if (!isObjectPrototype(Object.getPrototypeOf(object))) {
1648
- 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
+ }
1649
1598
  }
1650
1599
 
1651
- 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
1652
1605
 
1653
- for (var i = 0; i < names.length; i++) {
1654
- var descriptor = Object.getOwnPropertyDescriptor(object, names[i]);
1606
+ var digest = logRecoverableError(request, reason);
1655
1607
 
1656
- if (!descriptor) {
1657
- return false;
1658
- }
1608
+ {
1609
+ var _getErrorMessageAndSt2 = getErrorMessageAndStackDev(reason),
1610
+ _message = _getErrorMessageAndSt2.message,
1611
+ _stack = _getErrorMessageAndSt2.stack;
1659
1612
 
1660
- if (!descriptor.enumerable) {
1661
- if ((names[i] === 'key' || names[i] === 'ref') && typeof descriptor.get === 'function') {
1662
- // React adds key and ref getters to props objects to issue warnings.
1663
- // Those getters will not be transferred to the client, but that's ok,
1664
- // so we'll special case them.
1665
- continue;
1666
- }
1613
+ emitErrorChunkDev(request, newTask.id, digest, _message, _stack);
1614
+ }
1667
1615
 
1668
- return false;
1616
+ if (request.destination !== null) {
1617
+ flushCompletedChunks(request, request.destination);
1669
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;
1670
1628
  }
1671
1629
 
1672
- return true;
1630
+ throw thenable;
1673
1631
  }
1674
1632
 
1675
- function objectName(object) {
1676
- // $FlowFixMe[method-unbinding]
1677
- var name = Object.prototype.toString.call(object);
1678
- return name.replace(/^\[object (.*)\]$/, function (m, p0) {
1679
- return p0;
1680
- });
1681
- }
1682
-
1683
- function describeKeyForErrorMessage(key) {
1684
- var encodedKey = JSON.stringify(key);
1685
- return '"' + key + '"' === encodedKey ? key : encodedKey;
1686
- }
1633
+ function createLazyWrapperAroundWakeable(wakeable) {
1634
+ // This is a temporary fork of the `use` implementation until we accept
1635
+ // promises everywhere.
1636
+ var thenable = wakeable;
1687
1637
 
1688
- function describeValueForErrorMessage(value) {
1689
- switch (typeof value) {
1690
- case 'string':
1691
- {
1692
- return JSON.stringify(value.length <= 10 ? value : value.substr(0, 10) + '...');
1693
- }
1638
+ switch (thenable.status) {
1639
+ case 'fulfilled':
1640
+ case 'rejected':
1641
+ break;
1694
1642
 
1695
- case 'object':
1643
+ default:
1696
1644
  {
1697
- if (isArray(value)) {
1698
- return '[...]';
1699
- }
1700
-
1701
- var name = objectName(value);
1702
-
1703
- if (name === 'Object') {
1704
- 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;
1705
1650
  }
1706
1651
 
1707
- 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;
1708
1668
  }
1709
-
1710
- case 'function':
1711
- return 'function';
1712
-
1713
- default:
1714
- // eslint-disable-next-line react-internal/safe-string-coercion
1715
- return String(value);
1716
1669
  }
1670
+
1671
+ var lazyType = {
1672
+ $$typeof: REACT_LAZY_TYPE,
1673
+ _payload: thenable,
1674
+ _init: readThenable
1675
+ };
1676
+ return lazyType;
1717
1677
  }
1718
1678
 
1719
- function describeElementType(type) {
1720
- if (typeof type === 'string') {
1721
- 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.');
1722
1685
  }
1723
1686
 
1724
- switch (type) {
1725
- case REACT_SUSPENSE_TYPE:
1726
- return 'Suspense';
1687
+ {
1688
+ jsxPropsParents.set(props, type);
1727
1689
 
1728
- case REACT_SUSPENSE_LIST_TYPE:
1729
- return 'SuspenseList';
1690
+ if (typeof props.children === 'object' && props.children !== null) {
1691
+ jsxChildrenParents.set(props.children, type);
1692
+ }
1730
1693
  }
1731
1694
 
1732
- if (typeof type === 'object') {
1733
- switch (type.$$typeof) {
1734
- case REACT_FORWARD_REF_TYPE:
1735
- 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.
1736
1700
 
1737
- case REACT_MEMO_TYPE:
1738
- return describeElementType(type.type);
1739
1701
 
1740
- case REACT_LAZY_TYPE:
1741
- {
1742
- var lazyComponent = type;
1743
- var payload = lazyComponent._payload;
1744
- var init = lazyComponent._init;
1702
+ prepareToUseHooksForComponent(prevThenableState);
1703
+ var result = type(props);
1745
1704
 
1746
- try {
1747
- // Lazy may contain any component type so we recursively resolve it.
1748
- return describeElementType(init(payload));
1749
- } catch (x) {}
1750
- }
1751
- }
1752
- }
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;
1753
1709
 
1754
- return '';
1755
- }
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.
1756
1714
 
1757
- function describeObjectForErrorMessage(objectOrArray, expandedName) {
1758
- var objKind = objectName(objectOrArray);
1759
1715
 
1760
- if (objKind !== 'Object' && objKind !== 'Array') {
1761
- return objKind;
1762
- }
1716
+ return createLazyWrapperAroundWakeable(result);
1717
+ }
1763
1718
 
1764
- var str = '';
1765
- var start = -1;
1766
- 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.
1767
1732
 
1768
- if (isArray(objectOrArray)) {
1769
- if (jsxChildrenParents.has(objectOrArray)) {
1770
- // Print JSX Children
1771
- var type = jsxChildrenParents.get(objectOrArray);
1772
- str = '<' + describeElementType(type) + '>';
1773
- var array = objectOrArray;
1774
1733
 
1775
- for (var i = 0; i < array.length; i++) {
1776
- var value = array[i];
1777
- 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
+ }
1778
1740
 
1779
- if (typeof value === 'string') {
1780
- substr = value;
1781
- } else if (typeof value === 'object' && value !== null) {
1782
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1783
- substr = '{' + describeObjectForErrorMessage(value) + '}';
1784
- } else {
1785
- 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);
1786
1748
  }
1787
1749
 
1788
- if ('' + i === expandedName) {
1789
- start = str.length;
1790
- length = substr.length;
1791
- str += substr;
1792
- } else if (substr.length < 15 && str.length + substr.length < 40) {
1793
- str += substr;
1794
- } else {
1795
- str += '{...}';
1750
+ case REACT_FORWARD_REF_TYPE:
1751
+ {
1752
+ var render = type.render;
1753
+ prepareToUseHooksForComponent(prevThenableState);
1754
+ return render(props, undefined);
1796
1755
  }
1797
- }
1798
-
1799
- str += '</' + describeElementType(type) + '>';
1800
- } else {
1801
- // Print Array
1802
- str = '[';
1803
- var _array = objectOrArray;
1804
1756
 
1805
- for (var _i = 0; _i < _array.length; _i++) {
1806
- if (_i > 0) {
1807
- str += ', ';
1757
+ case REACT_MEMO_TYPE:
1758
+ {
1759
+ return attemptResolveElement(request, type.type, key, ref, props, prevThenableState);
1808
1760
  }
1809
1761
 
1810
- var _value = _array[_i];
1762
+ case REACT_PROVIDER_TYPE:
1763
+ {
1764
+ pushProvider(type._context, props.value);
1811
1765
 
1812
- var _substr = void 0;
1766
+ {
1767
+ var extraKeys = Object.keys(props).filter(function (value) {
1768
+ if (value === 'children' || value === 'value') {
1769
+ return false;
1770
+ }
1813
1771
 
1814
- if (typeof _value === 'object' && _value !== null) {
1815
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1816
- _substr = describeObjectForErrorMessage(_value);
1817
- } else {
1818
- _substr = describeValueForErrorMessage(_value);
1819
- }
1772
+ return true;
1773
+ });
1820
1774
 
1821
- if ('' + _i === expandedName) {
1822
- start = str.length;
1823
- length = _substr.length;
1824
- str += _substr;
1825
- } else if (_substr.length < 10 && str.length + _substr.length < 40) {
1826
- str += _substr;
1827
- } else {
1828
- str += '...';
1829
- }
1830
- }
1775
+ if (extraKeys.length !== 0) {
1776
+ error('ServerContext can only have a value prop and children. Found: %s', JSON.stringify(extraKeys));
1777
+ }
1778
+ }
1831
1779
 
1832
- 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
+ }
1833
1787
  }
1834
- } else {
1835
- if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
1836
- str = '<' + describeElementType(objectOrArray.type) + '/>';
1837
- } else if (jsxPropsParents.has(objectOrArray)) {
1838
- // Print JSX
1839
- var _type = jsxPropsParents.get(objectOrArray);
1788
+ }
1840
1789
 
1841
- str = '<' + (describeElementType(_type) || '...');
1842
- var object = objectOrArray;
1843
- var names = Object.keys(object);
1790
+ throw new Error("Unsupported Server Component type: " + describeValueForErrorMessage(type));
1791
+ }
1844
1792
 
1845
- for (var _i2 = 0; _i2 < names.length; _i2++) {
1846
- str += ' ';
1847
- var name = names[_i2];
1848
- str += describeKeyForErrorMessage(name) + '=';
1849
- var _value2 = object[name];
1793
+ function pingTask(request, task) {
1794
+ var pingedTasks = request.pingedTasks;
1795
+ pingedTasks.push(task);
1850
1796
 
1851
- var _substr2 = void 0;
1797
+ if (pingedTasks.length === 1) {
1798
+ scheduleWork(function () {
1799
+ return performWork(request);
1800
+ });
1801
+ }
1802
+ }
1852
1803
 
1853
- if (name === expandedName && typeof _value2 === 'object' && _value2 !== null) {
1854
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1855
- _substr2 = describeObjectForErrorMessage(_value2);
1856
- } else {
1857
- _substr2 = describeValueForErrorMessage(_value2);
1858
- }
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
+ }
1859
1819
 
1860
- if (typeof _value2 !== 'string') {
1861
- _substr2 = '{' + _substr2 + '}';
1862
- }
1820
+ function serializeByValueID(id) {
1821
+ return '$' + id.toString(16);
1822
+ }
1863
1823
 
1864
- if (name === expandedName) {
1865
- start = str.length;
1866
- length = _substr2.length;
1867
- str += _substr2;
1868
- } else if (_substr2.length < 10 && str.length + _substr2.length < 40) {
1869
- str += _substr2;
1870
- } else {
1871
- str += '...';
1872
- }
1873
- }
1824
+ function serializeLazyID(id) {
1825
+ return '$L' + id.toString(16);
1826
+ }
1874
1827
 
1875
- str += '>';
1876
- } else {
1877
- // Print Object
1878
- str = '{';
1879
- var _object = objectOrArray;
1828
+ function serializePromiseID(id) {
1829
+ return '$@' + id.toString(16);
1830
+ }
1880
1831
 
1881
- var _names = Object.keys(_object);
1832
+ function serializeServerReferenceID(id) {
1833
+ return '$F' + id.toString(16);
1834
+ }
1882
1835
 
1883
- for (var _i3 = 0; _i3 < _names.length; _i3++) {
1884
- if (_i3 > 0) {
1885
- str += ', ';
1886
- }
1836
+ function serializeSymbolReference(name) {
1837
+ return '$S' + name;
1838
+ }
1887
1839
 
1888
- var _name = _names[_i3];
1889
- str += describeKeyForErrorMessage(_name) + ': ';
1890
- var _value3 = _object[_name];
1840
+ function serializeProviderReference(name) {
1841
+ return '$P' + name;
1842
+ }
1891
1843
 
1892
- var _substr3 = void 0;
1844
+ function serializeUndefined() {
1845
+ return '$undefined';
1846
+ }
1893
1847
 
1894
- if (typeof _value3 === 'object' && _value3 !== null) {
1895
- // $FlowFixMe[incompatible-call] found when upgrading Flow
1896
- _substr3 = describeObjectForErrorMessage(_value3);
1897
- } else {
1898
- _substr3 = describeValueForErrorMessage(_value3);
1899
- }
1848
+ function serializeClientReference(request, parent, key, clientReference) {
1849
+ var clientReferenceKey = getClientReferenceKey(clientReference);
1850
+ var writtenClientReferences = request.writtenClientReferences;
1851
+ var existingId = writtenClientReferences.get(clientReferenceKey);
1900
1852
 
1901
- if (_name === expandedName) {
1902
- start = str.length;
1903
- length = _substr3.length;
1904
- str += _substr3;
1905
- } else if (_substr3.length < 10 && str.length + _substr3.length < 40) {
1906
- str += _substr3;
1907
- } else {
1908
- str += '...';
1909
- }
1910
- }
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);
1911
1887
 
1912
- str += '}';
1888
+ {
1889
+ var _getErrorMessageAndSt3 = getErrorMessageAndStackDev(x),
1890
+ message = _getErrorMessageAndSt3.message,
1891
+ stack = _getErrorMessageAndSt3.stack;
1892
+
1893
+ emitErrorChunkDev(request, errorId, digest, message, stack);
1913
1894
  }
1914
- }
1915
1895
 
1916
- if (expandedName === undefined) {
1917
- return str;
1896
+ return serializeByValueID(errorId);
1918
1897
  }
1898
+ }
1919
1899
 
1920
- if (start > -1 && length > 0) {
1921
- var highlight = ' '.repeat(start) + '^'.repeat(length);
1922
- 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);
1923
1906
  }
1924
1907
 
1925
- 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
+ }
1926
1930
  }
1927
1931
 
1928
1932
  var insideContextProps = null;
@@ -2096,10 +2100,14 @@
2096
2100
  return escapeStringValue(value);
2097
2101
  }
2098
2102
 
2099
- if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'undefined') {
2103
+ if (typeof value === 'boolean' || typeof value === 'number') {
2100
2104
  return value;
2101
2105
  }
2102
2106
 
2107
+ if (typeof value === 'undefined') {
2108
+ return serializeUndefined();
2109
+ }
2110
+
2103
2111
  if (typeof value === 'function') {
2104
2112
  if (isClientReference(value)) {
2105
2113
  return serializeClientReference(request, parent, key, value);
@@ -2222,7 +2230,7 @@
2222
2230
  }
2223
2231
 
2224
2232
  function retryTask(request, task) {
2225
- if (task.status !== PENDING) {
2233
+ if (task.status !== PENDING$1) {
2226
2234
  // We completed this by other means before we had a chance to retry it.
2227
2235
  return;
2228
2236
  }
@@ -2277,7 +2285,7 @@
2277
2285
  return;
2278
2286
  } else {
2279
2287
  request.abortableTasks.delete(task);
2280
- task.status = ERRORED;
2288
+ task.status = ERRORED$1;
2281
2289
  var digest = logRecoverableError(request, x);
2282
2290
 
2283
2291
  {
@@ -2395,7 +2403,7 @@
2395
2403
 
2396
2404
  if (request.pendingChunks === 0) {
2397
2405
  // We're done.
2398
- close(destination);
2406
+ close$1(destination);
2399
2407
  }
2400
2408
  }
2401
2409
 
@@ -2488,6 +2496,506 @@
2488
2496
  return rootContextSnapshot;
2489
2497
  }
2490
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
+
2491
2999
  function renderToReadableStream(model, webpackMap, options) {
2492
3000
  var request = createRequest(model, webpackMap, options ? options.onError : undefined, options ? options.context : undefined, options ? options.identifierPrefix : undefined);
2493
3001
 
@@ -2522,6 +3030,29 @@
2522
3030
  return stream;
2523
3031
  }
2524
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;
2525
3056
  exports.renderToReadableStream = renderToReadableStream;
2526
3057
 
2527
3058
  }));