react-server-dom-webpack 18.3.0-canary-14898b6a9-20240318 → 18.3.0-canary-4b84f1161-20240318

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 (39) hide show
  1. package/cjs/react-server-dom-webpack-client.browser.development.js +91 -189
  2. package/cjs/react-server-dom-webpack-client.browser.production.js +60 -43
  3. package/cjs/react-server-dom-webpack-client.browser.production.min.js +24 -23
  4. package/cjs/react-server-dom-webpack-client.browser.production.min.js.map +1 -1
  5. package/cjs/react-server-dom-webpack-client.edge.development.js +96 -241
  6. package/cjs/react-server-dom-webpack-client.edge.production.js +65 -84
  7. package/cjs/react-server-dom-webpack-client.edge.production.min.js +29 -29
  8. package/cjs/react-server-dom-webpack-client.edge.production.min.js.map +1 -1
  9. package/cjs/react-server-dom-webpack-client.node.development.js +96 -241
  10. package/cjs/react-server-dom-webpack-client.node.production.js +65 -84
  11. package/cjs/react-server-dom-webpack-client.node.production.min.js +29 -28
  12. package/cjs/react-server-dom-webpack-client.node.production.min.js.map +1 -1
  13. package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +96 -241
  14. package/cjs/react-server-dom-webpack-client.node.unbundled.production.js +65 -84
  15. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +30 -30
  16. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js.map +1 -1
  17. package/cjs/react-server-dom-webpack-node-register.js.map +1 -1
  18. package/cjs/react-server-dom-webpack-plugin.js.map +1 -1
  19. package/cjs/react-server-dom-webpack-server.browser.development.js +406 -550
  20. package/cjs/react-server-dom-webpack-server.browser.production.js +351 -373
  21. package/cjs/react-server-dom-webpack-server.browser.production.min.js +68 -65
  22. package/cjs/react-server-dom-webpack-server.browser.production.min.js.map +1 -1
  23. package/cjs/react-server-dom-webpack-server.edge.development.js +406 -553
  24. package/cjs/react-server-dom-webpack-server.edge.production.js +350 -375
  25. package/cjs/react-server-dom-webpack-server.edge.production.min.js +69 -66
  26. package/cjs/react-server-dom-webpack-server.edge.production.min.js.map +1 -1
  27. package/cjs/react-server-dom-webpack-server.node.development.js +406 -550
  28. package/cjs/react-server-dom-webpack-server.node.production.js +350 -372
  29. package/cjs/react-server-dom-webpack-server.node.production.min.js +72 -70
  30. package/cjs/react-server-dom-webpack-server.node.production.min.js.map +1 -1
  31. package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +406 -550
  32. package/cjs/react-server-dom-webpack-server.node.unbundled.production.js +350 -372
  33. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +69 -67
  34. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js.map +1 -1
  35. package/package.json +3 -3
  36. package/umd/react-server-dom-webpack-client.browser.development.js +91 -189
  37. package/umd/react-server-dom-webpack-client.browser.production.min.js +23 -22
  38. package/umd/react-server-dom-webpack-server.browser.development.js +406 -550
  39. package/umd/react-server-dom-webpack-server.browser.production.min.js +52 -52
@@ -149,10 +149,10 @@
149
149
  }
150
150
 
151
151
  // eslint-disable-next-line no-unused-vars
152
- var CLIENT_REFERENCE_TAG$1 = Symbol.for('react.client.reference');
152
+ var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
153
153
  var SERVER_REFERENCE_TAG = Symbol.for('react.server.reference');
154
154
  function isClientReference(reference) {
155
- return reference.$$typeof === CLIENT_REFERENCE_TAG$1;
155
+ return reference.$$typeof === CLIENT_REFERENCE_TAG;
156
156
  }
157
157
  function isServerReference(reference) {
158
158
  return reference.$$typeof === SERVER_REFERENCE_TAG;
@@ -164,7 +164,7 @@
164
164
  function registerClientReferenceImpl(proxyImplementation, id, async) {
165
165
  return Object.defineProperties(proxyImplementation, {
166
166
  $$typeof: {
167
- value: CLIENT_REFERENCE_TAG$1
167
+ value: CLIENT_REFERENCE_TAG
168
168
  },
169
169
  $$id: {
170
170
  value: id
@@ -185,14 +185,6 @@
185
185
  var newFn = FunctionBind.apply(this, arguments);
186
186
 
187
187
  if (this.$$typeof === SERVER_REFERENCE_TAG) {
188
- {
189
- var thisBind = arguments[0];
190
-
191
- if (thisBind != null) {
192
- error('Cannot bind "this" of a Server Action. Pass null or undefined as the first argument to .bind().');
193
- }
194
- }
195
-
196
188
  var args = ArraySlice.call(arguments, 1);
197
189
  return Object.defineProperties(newFn, {
198
190
  $$typeof: {
@@ -219,16 +211,13 @@
219
211
  value: SERVER_REFERENCE_TAG
220
212
  },
221
213
  $$id: {
222
- value: exportName === null ? id : id + '#' + exportName,
223
- configurable: true
214
+ value: exportName === null ? id : id + '#' + exportName
224
215
  },
225
216
  $$bound: {
226
- value: null,
227
- configurable: true
217
+ value: null
228
218
  },
229
219
  bind: {
230
- value: bind,
231
- configurable: true
220
+ value: bind
232
221
  }
233
222
  });
234
223
  }
@@ -267,10 +256,6 @@
267
256
  // $FlowFixMe[prop-missing]
268
257
  return Object.prototype[Symbol.toPrimitive];
269
258
 
270
- case Symbol.toStringTag:
271
- // $FlowFixMe[prop-missing]
272
- return Object.prototype[Symbol.toStringTag];
273
-
274
259
  case 'Provider':
275
260
  throw new Error("Cannot render a Client Context Provider on the Server. " + "Instead, you can export a Client Component wrapper " + "that itself renders a Client Context Provider.");
276
261
  } // eslint-disable-next-line react-internal/safe-string-coercion
@@ -312,10 +297,6 @@
312
297
  // $FlowFixMe[prop-missing]
313
298
  return Object.prototype[Symbol.toPrimitive];
314
299
 
315
- case Symbol.toStringTag:
316
- // $FlowFixMe[prop-missing]
317
- return Object.prototype[Symbol.toStringTag];
318
-
319
300
  case '__esModule':
320
301
  // Something is conditionally checking which export to use. We'll pretend to be
321
302
  // an ESM compat module but then we'll check again on the client.
@@ -356,10 +337,6 @@
356
337
 
357
338
  }
358
339
 
359
- if (typeof name === 'symbol') {
360
- throw new Error('Cannot read Symbol exports. Only named exports are supported on a client module ' + 'imported on the server.');
361
- }
362
-
363
340
  var cachedReference = target[name];
364
341
 
365
342
  if (!cachedReference) {
@@ -701,16 +678,13 @@
701
678
  return new Set();
702
679
  }
703
680
 
704
- var supportsRequestStorage = false;
705
- var requestStorage = null;
706
-
707
681
  // ATTENTION
708
682
  // When adding new symbols to this file,
709
683
  // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
710
684
  // The Symbol used to tag the ReactElement-like types.
711
685
  var REACT_ELEMENT_TYPE = Symbol.for('react.element');
712
686
  var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
713
- var REACT_CONTEXT_TYPE = Symbol.for('react.context');
687
+ var REACT_SERVER_CONTEXT_TYPE = Symbol.for('react.server_context');
714
688
  var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
715
689
  var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
716
690
  var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
@@ -734,6 +708,146 @@
734
708
  return null;
735
709
  }
736
710
 
711
+ // Forming a reverse tree.
712
+ // The structure of a context snapshot is an implementation of this file.
713
+ // Currently, it's implemented as tracking the current active node.
714
+
715
+
716
+ var rootContextSnapshot = null; // We assume that this runtime owns the "current" field on all ReactContext instances.
717
+ // This global (actually thread local) state represents what state all those "current",
718
+ // fields are currently in.
719
+
720
+ var currentActiveSnapshot = null;
721
+
722
+ function popNode(prev) {
723
+ {
724
+ prev.context._currentValue = prev.parentValue;
725
+ }
726
+ }
727
+
728
+ function pushNode(next) {
729
+ {
730
+ next.context._currentValue = next.value;
731
+ }
732
+ }
733
+
734
+ function popToNearestCommonAncestor(prev, next) {
735
+ if (prev === next) ; else {
736
+ popNode(prev);
737
+ var parentPrev = prev.parent;
738
+ var parentNext = next.parent;
739
+
740
+ if (parentPrev === null) {
741
+ if (parentNext !== null) {
742
+ throw new Error('The stacks must reach the root at the same time. This is a bug in React.');
743
+ }
744
+ } else {
745
+ if (parentNext === null) {
746
+ throw new Error('The stacks must reach the root at the same time. This is a bug in React.');
747
+ }
748
+
749
+ popToNearestCommonAncestor(parentPrev, parentNext); // On the way back, we push the new ones that weren't common.
750
+
751
+ pushNode(next);
752
+ }
753
+ }
754
+ }
755
+
756
+ function popAllPrevious(prev) {
757
+ popNode(prev);
758
+ var parentPrev = prev.parent;
759
+
760
+ if (parentPrev !== null) {
761
+ popAllPrevious(parentPrev);
762
+ }
763
+ }
764
+
765
+ function pushAllNext(next) {
766
+ var parentNext = next.parent;
767
+
768
+ if (parentNext !== null) {
769
+ pushAllNext(parentNext);
770
+ }
771
+
772
+ pushNode(next);
773
+ }
774
+
775
+ function popPreviousToCommonLevel(prev, next) {
776
+ popNode(prev);
777
+ var parentPrev = prev.parent;
778
+
779
+ if (parentPrev === null) {
780
+ throw new Error('The depth must equal at least at zero before reaching the root. This is a bug in React.');
781
+ }
782
+
783
+ if (parentPrev.depth === next.depth) {
784
+ // We found the same level. Now we just need to find a shared ancestor.
785
+ popToNearestCommonAncestor(parentPrev, next);
786
+ } else {
787
+ // We must still be deeper.
788
+ popPreviousToCommonLevel(parentPrev, next);
789
+ }
790
+ }
791
+
792
+ function popNextToCommonLevel(prev, next) {
793
+ var parentNext = next.parent;
794
+
795
+ if (parentNext === null) {
796
+ throw new Error('The depth must equal at least at zero before reaching the root. This is a bug in React.');
797
+ }
798
+
799
+ if (prev.depth === parentNext.depth) {
800
+ // We found the same level. Now we just need to find a shared ancestor.
801
+ popToNearestCommonAncestor(prev, parentNext);
802
+ } else {
803
+ // We must still be deeper.
804
+ popNextToCommonLevel(prev, parentNext);
805
+ }
806
+
807
+ pushNode(next);
808
+ } // Perform context switching to the new snapshot.
809
+ // To make it cheap to read many contexts, while not suspending, we make the switch eagerly by
810
+ // updating all the context's current values. That way reads, always just read the current value.
811
+ // At the cost of updating contexts even if they're never read by this subtree.
812
+
813
+
814
+ function switchContext(newSnapshot) {
815
+ // The basic algorithm we need to do is to pop back any contexts that are no longer on the stack.
816
+ // We also need to update any new contexts that are now on the stack with the deepest value.
817
+ // The easiest way to update new contexts is to just reapply them in reverse order from the
818
+ // perspective of the backpointers. To avoid allocating a lot when switching, we use the stack
819
+ // for that. Therefore this algorithm is recursive.
820
+ // 1) First we pop which ever snapshot tree was deepest. Popping old contexts as we go.
821
+ // 2) Then we find the nearest common ancestor from there. Popping old contexts as we go.
822
+ // 3) Then we reapply new contexts on the way back up the stack.
823
+ var prev = currentActiveSnapshot;
824
+ var next = newSnapshot;
825
+
826
+ if (prev !== next) {
827
+ if (prev === null) {
828
+ // $FlowFixMe[incompatible-call]: This has to be non-null since it's not equal to prev.
829
+ pushAllNext(next);
830
+ } else if (next === null) {
831
+ popAllPrevious(prev);
832
+ } else if (prev.depth === next.depth) {
833
+ popToNearestCommonAncestor(prev, next);
834
+ } else if (prev.depth > next.depth) {
835
+ popPreviousToCommonLevel(prev, next);
836
+ } else {
837
+ popNextToCommonLevel(prev, next);
838
+ }
839
+
840
+ currentActiveSnapshot = next;
841
+ }
842
+ }
843
+ function getActiveContext() {
844
+ return currentActiveSnapshot;
845
+ }
846
+ function readContext$1(context) {
847
+ var value = context._currentValue ;
848
+ return value;
849
+ }
850
+
737
851
  // Corresponds to ReactFiberWakeable and ReactFizzWakeable modules. Generally,
738
852
  // changes to one module should be reflected in the others.
739
853
  // TODO: Rename this module and the corresponding Fiber one to "Thenable"
@@ -862,13 +976,29 @@
862
976
  thenableState = prevThenableState;
863
977
  }
864
978
  function getThenableStateAfterSuspending() {
865
- // If you use() to Suspend this should always exist but if you throw a Promise instead,
866
- // which is not really supported anymore, it will be empty. We use the empty set as a
867
- // marker to know if this was a replay of the same component or first attempt.
868
- var state = thenableState || createThenableState();
979
+ var state = thenableState;
869
980
  thenableState = null;
870
981
  return state;
871
982
  }
983
+
984
+ function readContext(context) {
985
+ {
986
+ if (context.$$typeof !== REACT_SERVER_CONTEXT_TYPE) {
987
+ if (isClientReference(context)) {
988
+ error('Cannot read a Client Context from a Server Component.');
989
+ } else {
990
+ error('Only createServerContext is supported in Server Components.');
991
+ }
992
+ }
993
+
994
+ if (currentRequest$1 === null) {
995
+ error('Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
996
+ }
997
+ }
998
+
999
+ return readContext$1(context);
1000
+ }
1001
+
872
1002
  var HooksDispatcher = {
873
1003
  useMemo: function (nextCreate) {
874
1004
  return nextCreate();
@@ -879,8 +1009,8 @@
879
1009
  useDebugValue: function () {},
880
1010
  useDeferredValue: unsupportedHook,
881
1011
  useTransition: unsupportedHook,
882
- readContext: unsupportedContext,
883
- useContext: unsupportedContext,
1012
+ readContext: readContext,
1013
+ useContext: readContext,
884
1014
  useReducer: unsupportedHook,
885
1015
  useRef: unsupportedHook,
886
1016
  useState: unsupportedHook,
@@ -913,10 +1043,6 @@
913
1043
  throw new Error('Refreshing the cache is not supported in Server Components.');
914
1044
  }
915
1045
 
916
- function unsupportedContext() {
917
- throw new Error('Cannot read a Client Context from a Server Component.');
918
- }
919
-
920
1046
  function useId() {
921
1047
  if (currentRequest$1 === null) {
922
1048
  throw new Error('useId can only be used while React is rendering');
@@ -942,22 +1068,20 @@
942
1068
  }
943
1069
 
944
1070
  return trackUsedThenable(thenableState, thenable, index);
945
- } else if (usable.$$typeof === REACT_CONTEXT_TYPE) {
946
- unsupportedContext();
1071
+ } else if (usable.$$typeof === REACT_SERVER_CONTEXT_TYPE) {
1072
+ var context = usable;
1073
+ return readContext(context);
947
1074
  }
948
1075
  }
949
1076
 
950
- if (isClientReference(usable)) {
951
- if (usable.value != null && usable.value.$$typeof === REACT_CONTEXT_TYPE) {
952
- // Show a more specific message since it's a common mistake.
953
- throw new Error('Cannot read a Client Context from a Server Component.');
954
- } else {
955
- throw new Error('Cannot use() an already resolved Client Reference.');
1077
+ {
1078
+ if (isClientReference(usable)) {
1079
+ error('Cannot use() an already resolved Client Reference.');
956
1080
  }
957
- } else {
958
- throw new Error( // eslint-disable-next-line react-internal/safe-string-coercion
959
- 'An unsupported type was passed to use(): ' + String(usable));
960
- }
1081
+ } // eslint-disable-next-line react-internal/safe-string-coercion
1082
+
1083
+
1084
+ throw new Error('An unsupported type was passed to use(): ' + String(usable));
961
1085
  }
962
1086
 
963
1087
  function createSignal() {
@@ -1095,10 +1219,6 @@
1095
1219
  return '[...]';
1096
1220
  }
1097
1221
 
1098
- if (value !== null && value.$$typeof === CLIENT_REFERENCE_TAG) {
1099
- return describeClientReference();
1100
- }
1101
-
1102
1222
  var name = objectName(value);
1103
1223
 
1104
1224
  if (name === 'Object') {
@@ -1109,15 +1229,7 @@
1109
1229
  }
1110
1230
 
1111
1231
  case 'function':
1112
- {
1113
- if (value.$$typeof === CLIENT_REFERENCE_TAG) {
1114
- return describeClientReference();
1115
- }
1116
-
1117
- var _name = value.displayName || value.name;
1118
-
1119
- return _name ? 'function ' + _name : 'function';
1120
- }
1232
+ return 'function';
1121
1233
 
1122
1234
  default:
1123
1235
  // eslint-disable-next-line react-internal/safe-string-coercion
@@ -1163,12 +1275,6 @@
1163
1275
  return '';
1164
1276
  }
1165
1277
 
1166
- var CLIENT_REFERENCE_TAG = Symbol.for('react.client.reference');
1167
-
1168
- function describeClientReference(ref) {
1169
- return 'client';
1170
- }
1171
-
1172
1278
  function describeObjectForErrorMessage(objectOrArray, expandedName) {
1173
1279
  var objKind = objectName(objectOrArray);
1174
1280
 
@@ -1247,8 +1353,6 @@
1247
1353
  } else {
1248
1354
  if (objectOrArray.$$typeof === REACT_ELEMENT_TYPE) {
1249
1355
  str = '<' + describeElementType(objectOrArray.type) + '/>';
1250
- } else if (objectOrArray.$$typeof === CLIENT_REFERENCE_TAG) {
1251
- return describeClientReference();
1252
1356
  } else if (jsxPropsParents.has(objectOrArray)) {
1253
1357
  // Print JSX
1254
1358
  var _type = jsxPropsParents.get(objectOrArray);
@@ -1299,9 +1403,9 @@
1299
1403
  str += ', ';
1300
1404
  }
1301
1405
 
1302
- var _name2 = _names[_i3];
1303
- str += describeKeyForErrorMessage(_name2) + ': ';
1304
- var _value3 = _object[_name2];
1406
+ var _name = _names[_i3];
1407
+ str += describeKeyForErrorMessage(_name) + ': ';
1408
+ var _value3 = _object[_name];
1305
1409
 
1306
1410
  var _substr3 = void 0;
1307
1411
 
@@ -1311,7 +1415,7 @@
1311
1415
  _substr3 = describeValueForErrorMessage(_value3);
1312
1416
  }
1313
1417
 
1314
- if (_name2 === expandedName) {
1418
+ if (_name === expandedName) {
1315
1419
  start = str.length;
1316
1420
  length = _substr3.length;
1317
1421
  str += _substr3;
@@ -1366,7 +1470,7 @@
1366
1470
  var OPEN = 0;
1367
1471
  var CLOSING = 1;
1368
1472
  var CLOSED = 2;
1369
- function createRequest(model, bundlerConfig, onError, identifierPrefix, onPostpone, environmentName) {
1473
+ function createRequest(model, bundlerConfig, onError, context, identifierPrefix, onPostpone) {
1370
1474
  if (ReactCurrentCache.current !== null && ReactCurrentCache.current !== DefaultCacheDispatcher) {
1371
1475
  throw new Error('Currently React only supports one RSC renderer at a time.');
1372
1476
  }
@@ -1397,19 +1501,21 @@
1397
1501
  writtenSymbols: new Map(),
1398
1502
  writtenClientReferences: new Map(),
1399
1503
  writtenServerReferences: new Map(),
1504
+ writtenProviders: new Map(),
1400
1505
  writtenObjects: new WeakMap(),
1401
1506
  identifierPrefix: identifierPrefix || '',
1402
1507
  identifierCount: 1,
1403
1508
  taintCleanupQueue: cleanupQueue,
1404
1509
  onError: onError === undefined ? defaultErrorHandler : onError,
1405
- onPostpone: onPostpone === undefined ? defaultPostponeHandler : onPostpone
1510
+ onPostpone: onPostpone === undefined ? defaultPostponeHandler : onPostpone,
1511
+ // $FlowFixMe[missing-this-annot]
1512
+ toJSON: function (key, value) {
1513
+ return resolveModelToJSON(request, this, key, value);
1514
+ }
1406
1515
  };
1407
-
1408
- {
1409
- request.environmentName = environmentName === undefined ? 'Server' : environmentName;
1410
- }
1411
-
1412
- var rootTask = createTask(request, model, null, false, abortSet);
1516
+ request.pendingChunks++;
1517
+ var rootContext = createRootContext();
1518
+ var rootTask = createTask(request, model, rootContext, abortSet);
1413
1519
  pingedTasks.push(rootTask);
1414
1520
  return request;
1415
1521
  }
@@ -1420,18 +1526,13 @@
1420
1526
  return null;
1421
1527
  }
1422
1528
 
1423
- function serializeThenable(request, task, thenable) {
1424
- var newTask = createTask(request, null, task.keyPath, // the server component sequence continues through Promise-as-a-child.
1425
- task.implicitSlot, request.abortableTasks);
1426
-
1427
- {
1428
- // If this came from Flight, forward any debug info into this new row.
1429
- var debugInfo = thenable._debugInfo;
1529
+ function createRootContext(reqContext) {
1530
+ return importServerContexts();
1531
+ }
1430
1532
 
1431
- if (debugInfo) {
1432
- forwardDebugInfo(request, newTask.id, debugInfo);
1433
- }
1434
- }
1533
+ function serializeThenable(request, thenable) {
1534
+ request.pendingChunks++;
1535
+ var newTask = createTask(request, null, getActiveContext(), request.abortableTasks);
1435
1536
 
1436
1537
  switch (thenable.status) {
1437
1538
  case 'fulfilled':
@@ -1567,136 +1668,14 @@
1567
1668
  _payload: thenable,
1568
1669
  _init: readThenable
1569
1670
  };
1570
-
1571
- {
1572
- // If this came from React, transfer the debug info.
1573
- lazyType._debugInfo = thenable._debugInfo || [];
1574
- }
1575
-
1576
1671
  return lazyType;
1577
1672
  }
1578
1673
 
1579
- function renderFunctionComponent(request, task, key, Component, props) {
1580
- // Reset the task's thenable state before continuing, so that if a later
1581
- // component suspends we can reuse the same task object. If the same
1582
- // component suspends again, the thenable state will be restored.
1583
- var prevThenableState = task.thenableState;
1584
- task.thenableState = null;
1585
-
1586
- {
1587
- if (debugID === null) {
1588
- // We don't have a chunk to assign debug info. We need to outline this
1589
- // component to assign it an ID.
1590
- return outlineTask(request, task);
1591
- } else if (prevThenableState !== null) ; else {
1592
- // This is a new component in the same task so we can emit more debug info.
1593
- var componentName = Component.displayName || Component.name || '';
1594
- request.pendingChunks++;
1595
- emitDebugChunk(request, debugID, {
1596
- name: componentName,
1597
- env: request.environmentName
1598
- });
1599
- }
1600
- }
1601
-
1602
- prepareToUseHooksForComponent(prevThenableState); // The secondArg is always undefined in Server Components since refs error early.
1603
-
1604
- var secondArg = undefined;
1605
- var result = Component(props, secondArg);
1606
-
1607
- if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
1608
- // When the return value is in children position we can resolve it immediately,
1609
- // to its value without a wrapper if it's synchronously available.
1610
- var thenable = result;
1611
-
1612
- if (thenable.status === 'fulfilled') {
1613
- return thenable.value;
1614
- } // TODO: Once we accept Promises as children on the client, we can just return
1615
- // the thenable here.
1616
-
1617
-
1618
- result = createLazyWrapperAroundWakeable(result);
1619
- } // Track this element's key on the Server Component on the keyPath context..
1620
-
1621
-
1622
- var prevKeyPath = task.keyPath;
1623
- var prevImplicitSlot = task.implicitSlot;
1624
-
1625
- if (key !== null) {
1626
- // Append the key to the path. Technically a null key should really add the child
1627
- // index. We don't do that to hold the payload small and implementation simple.
1628
- task.keyPath = prevKeyPath === null ? key : prevKeyPath + ',' + key;
1629
- } else if (prevKeyPath === null) {
1630
- // This sequence of Server Components has no keys. This means that it was rendered
1631
- // in a slot that needs to assign an implicit key. Even if children below have
1632
- // explicit keys, they should not be used for the outer most key since it might
1633
- // collide with other slots in that set.
1634
- task.implicitSlot = true;
1635
- }
1636
-
1637
- var json = renderModelDestructive(request, task, emptyRoot, '', result);
1638
- task.keyPath = prevKeyPath;
1639
- task.implicitSlot = prevImplicitSlot;
1640
- return json;
1641
- }
1642
-
1643
- function renderFragment(request, task, children) {
1644
- {
1645
- var debugInfo = children._debugInfo;
1646
-
1647
- if (debugInfo) {
1648
- // If this came from Flight, forward any debug info into this new row.
1649
- if (debugID === null) {
1650
- // We don't have a chunk to assign debug info. We need to outline this
1651
- // component to assign it an ID.
1652
- return outlineTask(request, task);
1653
- } else {
1654
- // Forward any debug info we have the first time we see it.
1655
- // We do this after init so that we have received all the debug info
1656
- // from the server by the time we emit it.
1657
- forwardDebugInfo(request, debugID, debugInfo);
1658
- }
1659
- }
1660
- }
1661
-
1662
- {
1663
- return children;
1664
- }
1665
- }
1666
-
1667
- function renderClientElement(task, type, key, props) {
1668
- {
1669
- return [REACT_ELEMENT_TYPE, type, key, props];
1670
- } // We prepend the terminal client element that actually gets serialized with
1671
- } // The chunk ID we're currently rendering that we can assign debug data to.
1672
-
1673
-
1674
- var debugID = null;
1675
-
1676
- function outlineTask(request, task) {
1677
- var newTask = createTask(request, task.model, // the currently rendering element
1678
- task.keyPath, // unlike outlineModel this one carries along context
1679
- task.implicitSlot, request.abortableTasks);
1680
- retryTask(request, newTask);
1681
-
1682
- if (newTask.status === COMPLETED) {
1683
- // We completed synchronously so we can refer to this by reference. This
1684
- // makes it behaves the same as prod during deserialization.
1685
- return serializeByValueID(newTask.id);
1686
- } // This didn't complete synchronously so it wouldn't have even if we didn't
1687
- // outline it, so this would reduce to a lazy reference even in prod.
1688
-
1689
-
1690
- return serializeLazyID(newTask.id);
1691
- }
1692
-
1693
- function renderElement(request, task, type, key, ref, props) {
1674
+ function attemptResolveElement(request, type, key, ref, props, prevThenableState) {
1694
1675
  if (ref !== null && ref !== undefined) {
1695
1676
  // When the ref moves to the regular props object this will implicitly
1696
1677
  // throw for functions. We could probably relax it to a DEV warning for other
1697
1678
  // cases.
1698
- // TODO: `ref` is now just a prop when `enableRefAsProp` is on. Should we
1699
- // do what the above comment says?
1700
1679
  throw new Error('Refs cannot be used in Server Components, nor passed to Client Components.');
1701
1680
  }
1702
1681
 
@@ -1711,36 +1690,47 @@
1711
1690
  if (typeof type === 'function') {
1712
1691
  if (isClientReference(type)) {
1713
1692
  // This is a reference to a Client Component.
1714
- return renderClientElement(task, type, key, props);
1715
- } // This is a Server Component.
1693
+ return [REACT_ELEMENT_TYPE, type, key, props];
1694
+ } // This is a server-side component.
1695
+
1696
+
1697
+ prepareToUseHooksForComponent(prevThenableState);
1698
+ var result = type(props);
1716
1699
 
1700
+ if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
1701
+ // When the return value is in children position we can resolve it immediately,
1702
+ // to its value without a wrapper if it's synchronously available.
1703
+ var thenable = result;
1717
1704
 
1718
- return renderFunctionComponent(request, task, key, type, props);
1705
+ if (thenable.status === 'fulfilled') {
1706
+ return thenable.value;
1707
+ } // TODO: Once we accept Promises as children on the client, we can just return
1708
+ // the thenable here.
1709
+
1710
+
1711
+ return createLazyWrapperAroundWakeable(result);
1712
+ }
1713
+
1714
+ return result;
1719
1715
  } else if (typeof type === 'string') {
1720
1716
  // This is a host element. E.g. HTML.
1721
- return renderClientElement(task, type, key, props);
1717
+ return [REACT_ELEMENT_TYPE, type, key, props];
1722
1718
  } else if (typeof type === 'symbol') {
1723
- if (type === REACT_FRAGMENT_TYPE && key === null) {
1719
+ if (type === REACT_FRAGMENT_TYPE) {
1724
1720
  // For key-less fragments, we add a small optimization to avoid serializing
1725
1721
  // it as a wrapper.
1726
- var prevImplicitSlot = task.implicitSlot;
1727
-
1728
- if (task.keyPath === null) {
1729
- task.implicitSlot = true;
1730
- }
1731
-
1732
- var json = renderModelDestructive(request, task, emptyRoot, '', props.children);
1733
- task.implicitSlot = prevImplicitSlot;
1734
- return json;
1722
+ // TODO: If a key is specified, we should propagate its key to any children.
1723
+ // Same as if a Server Component has a key.
1724
+ return props.children;
1735
1725
  } // This might be a built-in React component. We'll let the client decide.
1736
1726
  // Any built-in works as long as its props are serializable.
1737
1727
 
1738
1728
 
1739
- return renderClientElement(task, type, key, props);
1729
+ return [REACT_ELEMENT_TYPE, type, key, props];
1740
1730
  } else if (type != null && typeof type === 'object') {
1741
1731
  if (isClientReference(type)) {
1742
1732
  // This is a reference to a Client Component.
1743
- return renderClientElement(task, type, key, props);
1733
+ return [REACT_ELEMENT_TYPE, type, key, props];
1744
1734
  }
1745
1735
 
1746
1736
  switch (type.$$typeof) {
@@ -1749,17 +1739,19 @@
1749
1739
  var payload = type._payload;
1750
1740
  var init = type._init;
1751
1741
  var wrappedType = init(payload);
1752
- return renderElement(request, task, wrappedType, key, ref, props);
1742
+ return attemptResolveElement(request, wrappedType, key, ref, props, prevThenableState);
1753
1743
  }
1754
1744
 
1755
1745
  case REACT_FORWARD_REF_TYPE:
1756
1746
  {
1757
- return renderFunctionComponent(request, task, key, type.render, props);
1747
+ var render = type.render;
1748
+ prepareToUseHooksForComponent(prevThenableState);
1749
+ return render(props, undefined);
1758
1750
  }
1759
1751
 
1760
1752
  case REACT_MEMO_TYPE:
1761
1753
  {
1762
- return renderElement(request, task, type.type, key, ref, props);
1754
+ return attemptResolveElement(request, type.type, key, ref, props, prevThenableState);
1763
1755
  }
1764
1756
  }
1765
1757
  }
@@ -1779,51 +1771,16 @@
1779
1771
  }
1780
1772
  }
1781
1773
 
1782
- function createTask(request, model, keyPath, implicitSlot, abortSet) {
1783
- request.pendingChunks++;
1774
+ function createTask(request, model, context, abortSet) {
1784
1775
  var id = request.nextChunkId++;
1785
-
1786
- if (typeof model === 'object' && model !== null) {
1787
- // If we're about to write this into a new task we can assign it an ID early so that
1788
- // any other references can refer to the value we're about to write.
1789
- {
1790
- request.writtenObjects.set(model, id);
1791
- }
1792
- }
1793
-
1794
1776
  var task = {
1795
1777
  id: id,
1796
1778
  status: PENDING$1,
1797
1779
  model: model,
1798
- keyPath: keyPath,
1799
- implicitSlot: implicitSlot,
1780
+ context: context,
1800
1781
  ping: function () {
1801
1782
  return pingTask(request, task);
1802
1783
  },
1803
- toJSON: function (parentPropertyName, value) {
1804
- var parent = this; // Make sure that `parent[parentPropertyName]` wasn't JSONified before `value` was passed to us
1805
-
1806
- {
1807
- // $FlowFixMe[incompatible-use]
1808
- var originalValue = parent[parentPropertyName];
1809
-
1810
- if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
1811
- if (objectName(originalValue) !== 'Object') {
1812
- var jsxParentType = jsxChildrenParents.get(parent);
1813
-
1814
- if (typeof jsxParentType === 'string') {
1815
- error('%s objects cannot be rendered as text children. Try formatting it using toString().%s', objectName(originalValue), describeObjectForErrorMessage(parent, parentPropertyName));
1816
- } else {
1817
- error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, parentPropertyName));
1818
- }
1819
- } else {
1820
- error('Only plain objects can be passed to Client Components from Server Components. ' + 'Objects with toJSON methods are not supported. Convert it manually ' + 'to a simple value before passing it to props.%s', describeObjectForErrorMessage(parent, parentPropertyName));
1821
- }
1822
- }
1823
- }
1824
-
1825
- return renderModel(request, task, parent, parentPropertyName, value);
1826
- },
1827
1784
  thenableState: null
1828
1785
  };
1829
1786
  abortSet.add(task);
@@ -1892,13 +1849,13 @@
1892
1849
  return stringToChunk(row);
1893
1850
  }
1894
1851
 
1895
- function serializeClientReference(request, parent, parentPropertyName, clientReference) {
1852
+ function serializeClientReference(request, parent, key, clientReference) {
1896
1853
  var clientReferenceKey = getClientReferenceKey(clientReference);
1897
1854
  var writtenClientReferences = request.writtenClientReferences;
1898
1855
  var existingId = writtenClientReferences.get(clientReferenceKey);
1899
1856
 
1900
1857
  if (existingId !== undefined) {
1901
- if (parent[0] === REACT_ELEMENT_TYPE && parentPropertyName === '1') {
1858
+ if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1902
1859
  // If we're encoding the "type" of an element, we can refer
1903
1860
  // to that by a lazy reference instead of directly since React
1904
1861
  // knows how to deal with lazy values. This lets us suspend
@@ -1917,7 +1874,7 @@
1917
1874
  emitImportChunk(request, importId, clientReferenceMetadata);
1918
1875
  writtenClientReferences.set(clientReferenceKey, importId);
1919
1876
 
1920
- if (parent[0] === REACT_ELEMENT_TYPE && parentPropertyName === '1') {
1877
+ if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
1921
1878
  // If we're encoding the "type" of an element, we can refer
1922
1879
  // to that by a lazy reference instead of directly since React
1923
1880
  // knows how to deal with lazy values. This lets us suspend
@@ -1937,14 +1894,13 @@
1937
1894
  }
1938
1895
 
1939
1896
  function outlineModel(request, value) {
1940
- var newTask = createTask(request, value, null, // The way we use outlining is for reusing an object.
1941
- false, // It makes no sense for that use case to be contextual.
1942
- request.abortableTasks);
1897
+ request.pendingChunks++;
1898
+ var newTask = createTask(request, value, getActiveContext(), request.abortableTasks);
1943
1899
  retryTask(request, newTask);
1944
1900
  return newTask.id;
1945
1901
  }
1946
1902
 
1947
- function serializeServerReference(request, serverReference) {
1903
+ function serializeServerReference(request, parent, key, serverReference) {
1948
1904
  var writtenServerReferences = request.writtenServerReferences;
1949
1905
  var existingId = writtenServerReferences.get(serverReference);
1950
1906
 
@@ -2024,77 +1980,110 @@
2024
1980
  return value;
2025
1981
  }
2026
1982
  }
2027
-
2028
1983
  var modelRoot = false;
2029
1984
 
2030
- function renderModel(request, task, parent, key, value) {
2031
- var prevKeyPath = task.keyPath;
2032
- var prevImplicitSlot = task.implicitSlot;
1985
+ function resolveModelToJSON(request, parent, key, value) {
1986
+ // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
1987
+ {
1988
+ // $FlowFixMe[incompatible-use]
1989
+ var originalValue = parent[key];
2033
1990
 
2034
- try {
2035
- return renderModelDestructive(request, task, parent, key, value);
2036
- } catch (thrownValue) {
2037
- var x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
2038
- // reasons, the rest of the Suspense implementation expects the thrown
2039
- // value to be a thenable, because before `use` existed that was the
2040
- // (unstable) API for suspending. This implementation detail can change
2041
- // later, once we deprecate the old API in favor of `use`.
2042
- getSuspendedThenable() : thrownValue; // If the suspended/errored value was an element or lazy it can be reduced
2043
- // to a lazy reference, so that it doesn't error the parent.
1991
+ if (typeof originalValue === 'object' && originalValue !== value && !(originalValue instanceof Date)) {
1992
+ if (objectName(originalValue) !== 'Object') {
1993
+ var jsxParentType = jsxChildrenParents.get(parent);
1994
+
1995
+ if (typeof jsxParentType === 'string') {
1996
+ error('%s objects cannot be rendered as text children. Try formatting it using toString().%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
1997
+ } else {
1998
+ error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(originalValue), describeObjectForErrorMessage(parent, key));
1999
+ }
2000
+ } else {
2001
+ error('Only plain objects can be passed to Client Components from Server Components. ' + 'Objects with toJSON methods are not supported. Convert it manually ' + 'to a simple value before passing it to props.%s', describeObjectForErrorMessage(parent, key));
2002
+ }
2003
+ }
2004
+ } // Special Symbols
2044
2005
 
2045
- var model = task.model;
2046
- var wasReactNode = typeof model === 'object' && model !== null && (model.$$typeof === REACT_ELEMENT_TYPE || model.$$typeof === REACT_LAZY_TYPE);
2047
2006
 
2048
- if (typeof x === 'object' && x !== null) {
2049
- // $FlowFixMe[method-unbinding]
2050
- if (typeof x.then === 'function') {
2051
- // Something suspended, we'll need to create a new task and resolve it later.
2052
- var newTask = createTask(request, task.model, task.keyPath, task.implicitSlot, request.abortableTasks);
2053
- var ping = newTask.ping;
2054
- x.then(ping, ping);
2055
- newTask.thenableState = getThenableStateAfterSuspending(); // Restore the context. We assume that this will be restored by the inner
2056
- // functions in case nothing throws so we don't use "finally" here.
2007
+ switch (value) {
2008
+ case REACT_ELEMENT_TYPE:
2009
+ return '$';
2010
+ }
2057
2011
 
2058
- task.keyPath = prevKeyPath;
2059
- task.implicitSlot = prevImplicitSlot;
2060
2012
 
2061
- if (wasReactNode) {
2062
- return serializeLazyID(newTask.id);
2063
- }
2013
+ while (typeof value === 'object' && value !== null && (value.$$typeof === REACT_ELEMENT_TYPE || value.$$typeof === REACT_LAZY_TYPE)) {
2014
+
2015
+ try {
2016
+ switch (value.$$typeof) {
2017
+ case REACT_ELEMENT_TYPE:
2018
+ {
2019
+ var writtenObjects = request.writtenObjects;
2020
+ var existingId = writtenObjects.get(value);
2021
+
2022
+ if (existingId !== undefined) {
2023
+ if (existingId === -1) {
2024
+ // Seen but not yet outlined.
2025
+ var newId = outlineModel(request, value);
2026
+ return serializeByValueID(newId);
2027
+ } else if (modelRoot === value) {
2028
+ // This is the ID we're currently emitting so we need to write it
2029
+ // once but if we discover it again, we refer to it by id.
2030
+ modelRoot = null;
2031
+ } else {
2032
+ // We've already emitted this as an outlined object, so we can
2033
+ // just refer to that by its existing ID.
2034
+ return serializeByValueID(existingId);
2035
+ }
2036
+ } else {
2037
+ // This is the first time we've seen this object. We may never see it again
2038
+ // so we'll inline it. Mark it as seen. If we see it again, we'll outline.
2039
+ writtenObjects.set(value, -1);
2040
+ } // TODO: Concatenate keys of parents onto children.
2064
2041
 
2065
- return serializeByValueID(newTask.id);
2066
- }
2067
- } // Restore the context. We assume that this will be restored by the inner
2068
- // functions in case nothing throws so we don't use "finally" here.
2069
2042
 
2043
+ var element = value; // Attempt to render the Server Component.
2070
2044
 
2071
- task.keyPath = prevKeyPath;
2072
- task.implicitSlot = prevImplicitSlot;
2045
+ value = attemptResolveElement(request, element.type, element.key, element.ref, element.props, null);
2046
+ break;
2047
+ }
2073
2048
 
2074
- if (wasReactNode) {
2075
- // Something errored. We'll still send everything we have up until this point.
2049
+ case REACT_LAZY_TYPE:
2050
+ {
2051
+ var payload = value._payload;
2052
+ var init = value._init;
2053
+ value = init(payload);
2054
+ break;
2055
+ }
2056
+ }
2057
+ } catch (thrownValue) {
2058
+ var x = thrownValue === SuspenseException ? // This is a special type of exception used for Suspense. For historical
2059
+ // reasons, the rest of the Suspense implementation expects the thrown
2060
+ // value to be a thenable, because before `use` existed that was the
2061
+ // (unstable) API for suspending. This implementation detail can change
2062
+ // later, once we deprecate the old API in favor of `use`.
2063
+ getSuspendedThenable() : thrownValue;
2064
+
2065
+ if (typeof x === 'object' && x !== null) {
2066
+ // $FlowFixMe[method-unbinding]
2067
+ if (typeof x.then === 'function') {
2068
+ // Something suspended, we'll need to create a new task and resolve it later.
2069
+ request.pendingChunks++;
2070
+ var newTask = createTask(request, value, getActiveContext(), request.abortableTasks);
2071
+ var ping = newTask.ping;
2072
+ x.then(ping, ping);
2073
+ newTask.thenableState = getThenableStateAfterSuspending();
2074
+ return serializeLazyID(newTask.id);
2075
+ }
2076
+ } // Something errored. We'll still send everything we have up until this point.
2076
2077
  // We'll replace this element with a lazy reference that throws on the client
2077
2078
  // once it gets rendered.
2079
+
2080
+
2078
2081
  request.pendingChunks++;
2079
2082
  var errorId = request.nextChunkId++;
2080
2083
  var digest = logRecoverableError(request, x);
2081
2084
  emitErrorChunk(request, errorId, digest, x);
2082
2085
  return serializeLazyID(errorId);
2083
- } // Something errored but it was not in a React Node. There's no need to serialize
2084
- // it by value because it'll just error the whole parent row anyway so we can
2085
- // just stop any siblings and error the whole parent row.
2086
-
2087
-
2088
- throw x;
2089
- }
2090
- }
2091
-
2092
- function renderModelDestructive(request, task, parent, parentPropertyName, value) {
2093
- // Set the currently rendering model
2094
- task.model = value; // Special Symbol, that's very common.
2095
-
2096
- if (value === REACT_ELEMENT_TYPE) {
2097
- return '$';
2086
+ }
2098
2087
  }
2099
2088
 
2100
2089
  if (value === null) {
@@ -2102,152 +2091,61 @@
2102
2091
  }
2103
2092
 
2104
2093
  if (typeof value === 'object') {
2105
- switch (value.$$typeof) {
2106
- case REACT_ELEMENT_TYPE:
2107
- {
2108
- var _writtenObjects = request.writtenObjects;
2109
-
2110
- var _existingId = _writtenObjects.get(value);
2111
-
2112
- if (_existingId !== undefined) {
2113
- if (modelRoot === value) {
2114
- // This is the ID we're currently emitting so we need to write it
2115
- // once but if we discover it again, we refer to it by id.
2116
- modelRoot = null;
2117
- } else if (_existingId === -1) {
2118
- // Seen but not yet outlined.
2119
- // TODO: If we throw here we can treat this as suspending which causes an outline
2120
- // but that is able to reuse the same task if we're already in one but then that
2121
- // will be a lazy future value rather than guaranteed to exist but maybe that's good.
2122
- var newId = outlineModel(request, value);
2123
- return serializeByValueID(newId);
2124
- } else {
2125
- // We've already emitted this as an outlined object, so we can refer to that by its
2126
- // existing ID. TODO: We should use a lazy reference since, unlike plain objects,
2127
- // elements might suspend so it might not have emitted yet even if we have the ID for
2128
- // it. However, this creates an extra wrapper when it's not needed. We should really
2129
- // detect whether this already was emitted and synchronously available. In that
2130
- // case we can refer to it synchronously and only make it lazy otherwise.
2131
- // We currently don't have a data structure that lets us see that though.
2132
- return serializeByValueID(_existingId);
2133
- }
2134
- } else {
2135
- // This is the first time we've seen this object. We may never see it again
2136
- // so we'll inline it. Mark it as seen. If we see it again, we'll outline.
2137
- _writtenObjects.set(value, -1);
2138
- }
2139
-
2140
- var element = value;
2141
-
2142
- {
2143
- var debugInfo = value._debugInfo;
2144
-
2145
- if (debugInfo) {
2146
- // If this came from Flight, forward any debug info into this new row.
2147
- if (debugID === null) {
2148
- // We don't have a chunk to assign debug info. We need to outline this
2149
- // component to assign it an ID.
2150
- return outlineTask(request, task);
2151
- } else {
2152
- // Forward any debug info we have the first time we see it.
2153
- forwardDebugInfo(request, debugID, debugInfo);
2154
- }
2155
- }
2156
- }
2157
-
2158
- var props = element.props;
2159
- var ref;
2160
-
2161
- {
2162
- ref = element.ref;
2163
- } // Attempt to render the Server Component.
2164
-
2165
-
2166
- return renderElement(request, task, element.type, // $FlowFixMe[incompatible-call] the key of an element is null | string
2167
- element.key, ref, props);
2168
- }
2169
-
2170
- case REACT_LAZY_TYPE:
2171
- {
2172
- // Reset the task's thenable state before continuing. If there was one, it was
2173
- // from suspending the lazy before.
2174
- task.thenableState = null;
2175
- var lazy = value;
2176
- var payload = lazy._payload;
2177
- var init = lazy._init;
2178
- var resolvedModel = init(payload);
2179
-
2180
- {
2181
- var _debugInfo = lazy._debugInfo;
2182
-
2183
- if (_debugInfo) {
2184
- // If this came from Flight, forward any debug info into this new row.
2185
- if (debugID === null) {
2186
- // We don't have a chunk to assign debug info. We need to outline this
2187
- // component to assign it an ID.
2188
- return outlineTask(request, task);
2189
- } else {
2190
- // Forward any debug info we have the first time we see it.
2191
- // We do this after init so that we have received all the debug info
2192
- // from the server by the time we emit it.
2193
- forwardDebugInfo(request, debugID, _debugInfo);
2194
- }
2195
- }
2196
- }
2197
-
2198
- return renderModelDestructive(request, task, emptyRoot, '', resolvedModel);
2199
- }
2200
- }
2201
2094
 
2202
2095
  if (isClientReference(value)) {
2203
- return serializeClientReference(request, parent, parentPropertyName, value);
2096
+ return serializeClientReference(request, parent, key, value);
2204
2097
  }
2205
2098
 
2206
- var writtenObjects = request.writtenObjects;
2207
- var existingId = writtenObjects.get(value); // $FlowFixMe[method-unbinding]
2099
+ var _writtenObjects = request.writtenObjects;
2100
+
2101
+ var _existingId = _writtenObjects.get(value); // $FlowFixMe[method-unbinding]
2102
+
2208
2103
 
2209
2104
  if (typeof value.then === 'function') {
2210
- if (existingId !== undefined) {
2105
+ if (_existingId !== undefined) {
2211
2106
  if (modelRoot === value) {
2212
2107
  // This is the ID we're currently emitting so we need to write it
2213
2108
  // once but if we discover it again, we refer to it by id.
2214
2109
  modelRoot = null;
2215
2110
  } else {
2216
2111
  // We've seen this promise before, so we can just refer to the same result.
2217
- return serializePromiseID(existingId);
2112
+ return serializePromiseID(_existingId);
2218
2113
  }
2219
2114
  } // We assume that any object with a .then property is a "Thenable" type,
2220
2115
  // or a Promise type. Either of which can be represented by a Promise.
2221
2116
 
2222
2117
 
2223
- var promiseId = serializeThenable(request, task, value);
2224
- writtenObjects.set(value, promiseId);
2118
+ var promiseId = serializeThenable(request, value);
2119
+
2120
+ _writtenObjects.set(value, promiseId);
2121
+
2225
2122
  return serializePromiseID(promiseId);
2226
2123
  }
2227
2124
 
2228
- if (existingId !== undefined) {
2229
- if (modelRoot === value) {
2230
- // This is the ID we're currently emitting so we need to write it
2231
- // once but if we discover it again, we refer to it by id.
2232
- modelRoot = null;
2233
- } else if (existingId === -1) {
2125
+ if (_existingId !== undefined) {
2126
+ if (_existingId === -1) {
2234
2127
  // Seen but not yet outlined.
2235
2128
  var _newId = outlineModel(request, value);
2236
2129
 
2237
2130
  return serializeByValueID(_newId);
2131
+ } else if (modelRoot === value) {
2132
+ // This is the ID we're currently emitting so we need to write it
2133
+ // once but if we discover it again, we refer to it by id.
2134
+ modelRoot = null;
2238
2135
  } else {
2239
2136
  // We've already emitted this as an outlined object, so we can
2240
2137
  // just refer to that by its existing ID.
2241
- return serializeByValueID(existingId);
2138
+ return serializeByValueID(_existingId);
2242
2139
  }
2243
2140
  } else {
2244
2141
  // This is the first time we've seen this object. We may never see it again
2245
2142
  // so we'll inline it. Mark it as seen. If we see it again, we'll outline.
2246
- writtenObjects.set(value, -1);
2143
+ _writtenObjects.set(value, -1);
2247
2144
  }
2248
2145
 
2249
2146
  if (isArray(value)) {
2250
- return renderFragment(request, task, value);
2147
+ // $FlowFixMe[incompatible-return]
2148
+ return value;
2251
2149
  }
2252
2150
 
2253
2151
  if (value instanceof Map) {
@@ -2261,7 +2159,7 @@
2261
2159
  var iteratorFn = getIteratorFn(value);
2262
2160
 
2263
2161
  if (iteratorFn) {
2264
- return renderFragment(request, task, Array.from(value));
2162
+ return Array.from(value);
2265
2163
  } // Verify that this is a simple plain object.
2266
2164
 
2267
2165
 
@@ -2273,14 +2171,14 @@
2273
2171
 
2274
2172
  {
2275
2173
  if (objectName(value) !== 'Object') {
2276
- error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, parentPropertyName));
2174
+ error('Only plain objects can be passed to Client Components from Server Components. ' + '%s objects are not supported.%s', objectName(value), describeObjectForErrorMessage(parent, key));
2277
2175
  } else if (!isSimpleObject(value)) {
2278
- error('Only plain objects can be passed to Client Components from Server Components. ' + 'Classes or other objects with methods are not supported.%s', describeObjectForErrorMessage(parent, parentPropertyName));
2176
+ error('Only plain objects can be passed to Client Components from Server Components. ' + 'Classes or other objects with methods are not supported.%s', describeObjectForErrorMessage(parent, key));
2279
2177
  } else if (Object.getOwnPropertySymbols) {
2280
2178
  var symbols = Object.getOwnPropertySymbols(value);
2281
2179
 
2282
2180
  if (symbols.length > 0) {
2283
- error('Only plain objects can be passed to Client Components from Server Components. ' + 'Objects with symbol properties like %s are not supported.%s', symbols[0].description, describeObjectForErrorMessage(parent, parentPropertyName));
2181
+ error('Only plain objects can be passed to Client Components from Server Components. ' + 'Objects with symbol properties like %s are not supported.%s', symbols[0].description, describeObjectForErrorMessage(parent, key));
2284
2182
  }
2285
2183
  }
2286
2184
  } // $FlowFixMe[incompatible-return]
@@ -2295,9 +2193,9 @@
2295
2193
  if (value[value.length - 1] === 'Z') {
2296
2194
  // Possibly a Date, whose toJSON automatically calls toISOString
2297
2195
  // $FlowFixMe[incompatible-use]
2298
- var originalValue = parent[parentPropertyName];
2196
+ var _originalValue = parent[key];
2299
2197
 
2300
- if (originalValue instanceof Date) {
2198
+ if (_originalValue instanceof Date) {
2301
2199
  return serializeDateFromDateJSON(value);
2302
2200
  }
2303
2201
  }
@@ -2325,21 +2223,19 @@
2325
2223
  }
2326
2224
 
2327
2225
  if (typeof value === 'function') {
2226
+
2328
2227
  if (isClientReference(value)) {
2329
- return serializeClientReference(request, parent, parentPropertyName, value);
2228
+ return serializeClientReference(request, parent, key, value);
2330
2229
  }
2331
2230
 
2332
2231
  if (isServerReference(value)) {
2333
- return serializeServerReference(request, value);
2232
+ return serializeServerReference(request, parent, key, value);
2334
2233
  }
2335
2234
 
2336
- if (/^on[A-Z]/.test(parentPropertyName)) {
2337
- throw new Error('Event handlers cannot be passed to Client Component props.' + describeObjectForErrorMessage(parent, parentPropertyName) + '\nIf you need interactivity, consider converting part of this to a Client Component.');
2338
- } else if ((jsxChildrenParents.has(parent) || jsxPropsParents.has(parent) && parentPropertyName === 'children')) {
2339
- var componentName = value.displayName || value.name || 'Component';
2340
- throw new Error('Functions are not valid as a child of Client Components. This may happen if ' + 'you return ' + componentName + ' instead of <' + componentName + ' /> from render. ' + 'Or maybe you meant to call this function rather than return it.' + describeObjectForErrorMessage(parent, parentPropertyName));
2235
+ if (/^on[A-Z]/.test(key)) {
2236
+ throw new Error('Event handlers cannot be passed to Client Component props.' + describeObjectForErrorMessage(parent, key) + '\nIf you need interactivity, consider converting part of this to a Client Component.');
2341
2237
  } else {
2342
- throw new Error('Functions cannot be passed directly to Client Components ' + 'unless you explicitly expose it by marking it with "use server". ' + 'Or maybe you meant to call this function rather than return it.' + describeObjectForErrorMessage(parent, parentPropertyName));
2238
+ throw new Error('Functions cannot be passed directly to Client Components ' + 'unless you explicitly expose it by marking it with "use server".' + describeObjectForErrorMessage(parent, key));
2343
2239
  }
2344
2240
  }
2345
2241
 
@@ -2357,7 +2253,7 @@
2357
2253
 
2358
2254
  if (Symbol.for(name) !== value) {
2359
2255
  throw new Error('Only global symbols received from Symbol.for(...) can be passed to Client Components. ' + ("The symbol Symbol.for(" + // $FlowFixMe[incompatible-type] `description` might be undefined
2360
- value.description + ") cannot be found among global symbols.") + describeObjectForErrorMessage(parent, parentPropertyName));
2256
+ value.description + ") cannot be found among global symbols.") + describeObjectForErrorMessage(parent, key));
2361
2257
  }
2362
2258
 
2363
2259
  request.pendingChunks++;
@@ -2372,38 +2268,17 @@
2372
2268
  return serializeBigInt(value);
2373
2269
  }
2374
2270
 
2375
- throw new Error("Type " + typeof value + " is not supported in Client Component props." + describeObjectForErrorMessage(parent, parentPropertyName));
2271
+ throw new Error("Type " + typeof value + " is not supported in Client Component props." + describeObjectForErrorMessage(parent, key));
2376
2272
  }
2377
2273
 
2378
2274
  function logPostpone(request, reason) {
2379
- var prevRequest = currentRequest;
2380
- currentRequest = null;
2381
-
2382
- try {
2383
- var onPostpone = request.onPostpone;
2384
-
2385
- if (supportsRequestStorage) ; else {
2386
- onPostpone(reason);
2387
- }
2388
- } finally {
2389
- currentRequest = prevRequest;
2390
- }
2275
+ var onPostpone = request.onPostpone;
2276
+ onPostpone(reason);
2391
2277
  }
2392
2278
 
2393
2279
  function logRecoverableError(request, error) {
2394
- var prevRequest = currentRequest;
2395
- currentRequest = null;
2396
- var errorDigest;
2397
-
2398
- try {
2399
- var onError = request.onError;
2400
-
2401
- if (supportsRequestStorage) ; else {
2402
- errorDigest = onError(error);
2403
- }
2404
- } finally {
2405
- currentRequest = prevRequest;
2406
- }
2280
+ var onError = request.onError;
2281
+ var errorDigest = onError(error);
2407
2282
 
2408
2283
  if (errorDigest != null && typeof errorDigest !== 'string') {
2409
2284
  // eslint-disable-next-line react-internal/prod-error-codes
@@ -2462,11 +2337,8 @@
2462
2337
  message = String(error.message); // eslint-disable-next-line react-internal/safe-string-coercion
2463
2338
 
2464
2339
  stack = String(error.stack);
2465
- } else if (typeof error === 'object' && error !== null) {
2466
- message = describeObjectForErrorMessage(error);
2467
2340
  } else {
2468
- // eslint-disable-next-line react-internal/safe-string-coercion
2469
- message = String(error);
2341
+ message = 'Error: ' + error;
2470
2342
  }
2471
2343
  } catch (x) {
2472
2344
  message = 'An error occurred but serializing the error message failed.';
@@ -2506,79 +2378,62 @@
2506
2378
  request.completedImportChunks.push(processedChunk);
2507
2379
  }
2508
2380
 
2509
- function emitModelChunk(request, id, json) {
2510
- var row = id.toString(16) + ':' + json + '\n';
2511
- var processedChunk = stringToChunk(row);
2512
- request.completedRegularChunks.push(processedChunk);
2513
- }
2514
-
2515
- function emitDebugChunk(request, id, debugInfo) {
2381
+ function emitModelChunk(request, id, model) {
2382
+ // Track the root so we know that we have to emit this object even though it
2383
+ // already has an ID. This is needed because we might see this object twice
2384
+ // in the same toJSON if it is cyclic.
2385
+ modelRoot = model; // $FlowFixMe[incompatible-type] stringify can return null
2516
2386
 
2517
-
2518
- var json = stringify(debugInfo);
2519
- var row = serializeRowHeader('D', id) + json + '\n';
2387
+ var json = stringify(model, request.toJSON);
2388
+ var row = id.toString(16) + ':' + json + '\n';
2520
2389
  var processedChunk = stringToChunk(row);
2521
2390
  request.completedRegularChunks.push(processedChunk);
2522
2391
  }
2523
2392
 
2524
- function forwardDebugInfo(request, id, debugInfo) {
2525
- for (var i = 0; i < debugInfo.length; i++) {
2526
- request.pendingChunks++;
2527
- emitDebugChunk(request, id, debugInfo[i]);
2528
- }
2529
- }
2530
-
2531
- var emptyRoot = {};
2532
-
2533
2393
  function retryTask(request, task) {
2534
2394
  if (task.status !== PENDING$1) {
2535
2395
  // We completed this by other means before we had a chance to retry it.
2536
2396
  return;
2537
2397
  }
2538
2398
 
2539
- var prevDebugID = debugID;
2399
+ switchContext(task.context);
2540
2400
 
2541
2401
  try {
2542
- // Track the root so we know that we have to emit this object even though it
2543
- // already has an ID. This is needed because we might see this object twice
2544
- // in the same toJSON if it is cyclic.
2545
- modelRoot = task.model;
2402
+ var value = task.model;
2546
2403
 
2547
- if (true) {
2548
- // Track the ID of the current task so we can assign debug info to this id.
2549
- debugID = task.id;
2550
- } // We call the destructive form that mutates this task. That way if something
2551
- // suspends again, we can reuse the same task instead of spawning a new one.
2404
+ if (typeof value === 'object' && value !== null && value.$$typeof === REACT_ELEMENT_TYPE) {
2405
+ request.writtenObjects.set(value, task.id); // TODO: Concatenate keys of parents onto children.
2552
2406
 
2407
+ var element = value; // When retrying a component, reuse the thenableState from the
2408
+ // previous attempt.
2553
2409
 
2554
- var resolvedModel = renderModelDestructive(request, task, emptyRoot, '', task.model);
2410
+ var prevThenableState = task.thenableState; // Attempt to render the Server Component.
2411
+ // Doing this here lets us reuse this same task if the next component
2412
+ // also suspends.
2555
2413
 
2556
- if (true) {
2557
- // We're now past rendering this task and future renders will spawn new tasks for their
2558
- // debug info.
2559
- debugID = null;
2560
- } // Track the root again for the resolved object.
2414
+ task.model = value;
2415
+ value = attemptResolveElement(request, element.type, element.key, element.ref, element.props, prevThenableState); // Successfully finished this component. We're going to keep rendering
2416
+ // using the same task, but we reset its thenable state before continuing.
2561
2417
 
2418
+ task.thenableState = null; // Keep rendering and reuse the same task. This inner loop is separate
2419
+ // from the render above because we don't need to reset the thenable state
2420
+ // until the next time something suspends and retries.
2562
2421
 
2563
- modelRoot = resolvedModel; // The keyPath resets at any terminal child node.
2422
+ while (typeof value === 'object' && value !== null && value.$$typeof === REACT_ELEMENT_TYPE) {
2423
+ request.writtenObjects.set(value, task.id); // TODO: Concatenate keys of parents onto children.
2564
2424
 
2565
- task.keyPath = null;
2566
- task.implicitSlot = false;
2567
- var json;
2425
+ var nextElement = value;
2426
+ task.model = value;
2427
+ value = attemptResolveElement(request, nextElement.type, nextElement.key, nextElement.ref, nextElement.props, null);
2428
+ }
2429
+ } // Track that this object is outlined and has an id.
2568
2430
 
2569
- if (typeof resolvedModel === 'object' && resolvedModel !== null) {
2570
- // Object might contain unresolved values like additional elements.
2571
- // This is simulating what the JSON loop would do if this was part of it.
2572
- // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
2573
- json = stringify(resolvedModel, task.toJSON);
2574
- } else {
2575
- // If the value is a string, it means it's a terminal value and we already escaped it
2576
- // We don't need to escape it again so it's not passed the toJSON replacer.
2577
- // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
2578
- json = stringify(resolvedModel);
2431
+
2432
+ if (typeof value === 'object' && value !== null) {
2433
+ request.writtenObjects.set(value, task.id);
2579
2434
  }
2580
2435
 
2581
- emitModelChunk(request, task.id, json);
2436
+ emitModelChunk(request, task.id, value);
2582
2437
  request.abortableTasks.delete(task);
2583
2438
  task.status = COMPLETED;
2584
2439
  } catch (thrownValue) {
@@ -2604,10 +2459,6 @@
2604
2459
  task.status = ERRORED$1;
2605
2460
  var digest = logRecoverableError(request, x);
2606
2461
  emitErrorChunk(request, task.id, digest, x);
2607
- } finally {
2608
- {
2609
- debugID = prevDebugID;
2610
- }
2611
2462
  }
2612
2463
  }
2613
2464
 
@@ -2820,6 +2671,11 @@
2820
2671
  }
2821
2672
  }
2822
2673
 
2674
+ function importServerContexts(contexts) {
2675
+
2676
+ return rootContextSnapshot;
2677
+ }
2678
+
2823
2679
  // This is the parsed shape of the wire format which is why it is
2824
2680
  // condensed to only the essentialy information
2825
2681
  var ID = 0;
@@ -3542,7 +3398,7 @@
3542
3398
  }
3543
3399
 
3544
3400
  function renderToReadableStream(model, webpackMap, options) {
3545
- var request = createRequest(model, webpackMap, options ? options.onError : undefined, options ? options.identifierPrefix : undefined, options ? options.onPostpone : undefined, options ? options.environmentName : undefined);
3401
+ var request = createRequest(model, webpackMap, options ? options.onError : undefined, options ? options.context : undefined, options ? options.identifierPrefix : undefined, options ? options.onPostpone : undefined);
3546
3402
 
3547
3403
  if (options && options.signal) {
3548
3404
  var signal = options.signal;