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