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