react-server-dom-webpack 18.3.0-next-a8875eab7-20230310 → 18.3.0-next-56a3c18e5-20230314

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