react-server-dom-webpack 18.3.0-next-a8875eab7-20230310 → 18.3.0-next-f828bad38-20230313

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