react-server-dom-webpack 19.0.0-rc.0 → 19.0.0

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 (28) hide show
  1. package/cjs/react-server-dom-webpack-client.browser.development.js +2483 -3269
  2. package/cjs/react-server-dom-webpack-client.browser.production.js +420 -215
  3. package/cjs/react-server-dom-webpack-client.edge.development.js +2656 -3546
  4. package/cjs/react-server-dom-webpack-client.edge.production.js +424 -218
  5. package/cjs/react-server-dom-webpack-client.node.development.js +2693 -3498
  6. package/cjs/react-server-dom-webpack-client.node.production.js +546 -263
  7. package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +2638 -3434
  8. package/cjs/react-server-dom-webpack-client.node.unbundled.production.js +526 -257
  9. package/cjs/react-server-dom-webpack-plugin.js +11 -11
  10. package/cjs/react-server-dom-webpack-server.browser.development.js +3700 -5229
  11. package/cjs/react-server-dom-webpack-server.browser.production.js +447 -276
  12. package/cjs/react-server-dom-webpack-server.edge.development.js +3730 -5241
  13. package/cjs/react-server-dom-webpack-server.edge.production.js +435 -283
  14. package/cjs/react-server-dom-webpack-server.node.development.js +3794 -5384
  15. package/cjs/react-server-dom-webpack-server.node.production.js +428 -289
  16. package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +3756 -5310
  17. package/cjs/react-server-dom-webpack-server.node.unbundled.production.js +421 -284
  18. package/esm/react-server-dom-webpack-node-loader.production.js +238 -44
  19. package/package.json +27 -4
  20. package/server.browser.js +12 -2
  21. package/server.edge.js +12 -2
  22. package/server.node.js +13 -2
  23. package/server.node.unbundled.js +13 -2
  24. package/static.browser.js +12 -0
  25. package/static.edge.js +12 -0
  26. package/static.js +6 -0
  27. package/static.node.js +12 -0
  28. package/static.node.unbundled.js +12 -0
@@ -15,15 +15,15 @@ var util = require("util"),
15
15
  function resolveClientReference(bundlerConfig, metadata) {
16
16
  if (bundlerConfig) {
17
17
  var moduleExports = bundlerConfig[metadata[0]];
18
- if ((bundlerConfig = moduleExports[metadata[2]]))
18
+ if ((bundlerConfig = moduleExports && moduleExports[metadata[2]]))
19
19
  moduleExports = bundlerConfig.name;
20
20
  else {
21
- bundlerConfig = moduleExports["*"];
21
+ bundlerConfig = moduleExports && moduleExports["*"];
22
22
  if (!bundlerConfig)
23
23
  throw Error(
24
24
  'Could not find the module "' +
25
25
  metadata[0] +
26
- '" in the React SSR Manifest. This is probably a bug in the React Server Components bundler.'
26
+ '" in the React Server Consumer Manifest. This is probably a bug in the React Server Components bundler.'
27
27
  );
28
28
  moduleExports = metadata[2];
29
29
  }
@@ -33,6 +33,26 @@ function resolveClientReference(bundlerConfig, metadata) {
33
33
  }
34
34
  return metadata;
35
35
  }
36
+ function resolveServerReference(bundlerConfig, id) {
37
+ var name = "",
38
+ resolvedModuleData = bundlerConfig[id];
39
+ if (resolvedModuleData) name = resolvedModuleData.name;
40
+ else {
41
+ var idx = id.lastIndexOf("#");
42
+ -1 !== idx &&
43
+ ((name = id.slice(idx + 1)),
44
+ (resolvedModuleData = bundlerConfig[id.slice(0, idx)]));
45
+ if (!resolvedModuleData)
46
+ throw Error(
47
+ 'Could not find the module "' +
48
+ id +
49
+ '" in the React Server Manifest. This is probably a bug in the React Server Components bundler.'
50
+ );
51
+ }
52
+ return resolvedModuleData.async
53
+ ? [resolvedModuleData.id, resolvedModuleData.chunks, name, 1]
54
+ : [resolvedModuleData.id, resolvedModuleData.chunks, name];
55
+ }
36
56
  var chunkCache = new Map();
37
57
  function requireAsyncModule(id) {
38
58
  var promise = __webpack_require__(id);
@@ -71,8 +91,22 @@ function preloadModule(metadata) {
71
91
  return requireAsyncModule(metadata[0]);
72
92
  })
73
93
  : 0 < promises.length
74
- ? Promise.all(promises)
75
- : null;
94
+ ? Promise.all(promises)
95
+ : null;
96
+ }
97
+ function requireModule(metadata) {
98
+ var moduleExports = __webpack_require__(metadata[0]);
99
+ if (4 === metadata.length && "function" === typeof moduleExports.then)
100
+ if ("fulfilled" === moduleExports.status)
101
+ moduleExports = moduleExports.value;
102
+ else throw moduleExports.reason;
103
+ return "*" === metadata[2]
104
+ ? moduleExports
105
+ : "" === metadata[2]
106
+ ? moduleExports.__esModule
107
+ ? moduleExports.default
108
+ : moduleExports
109
+ : moduleExports[metadata[2]];
76
110
  }
77
111
  function prepareDestinationWithChunks(moduleLoading, chunks, nonce$jscomp$0) {
78
112
  if (null !== moduleLoading)
@@ -118,10 +152,10 @@ function serializeNumber(number) {
118
152
  ? "$-0"
119
153
  : number
120
154
  : Infinity === number
121
- ? "$Infinity"
122
- : -Infinity === number
123
- ? "$-Infinity"
124
- : "$NaN";
155
+ ? "$Infinity"
156
+ : -Infinity === number
157
+ ? "$-Infinity"
158
+ : "$NaN";
125
159
  }
126
160
  function processReply(
127
161
  root,
@@ -470,12 +504,17 @@ function processReply(
470
504
  pendingParts = 0,
471
505
  formData = null,
472
506
  writtenObjects = new WeakMap(),
473
- modelRoot = root;
474
- root = serializeModel(root, 0);
507
+ modelRoot = root,
508
+ json = serializeModel(root, 0);
475
509
  null === formData
476
- ? resolve(root)
477
- : (formData.set(formFieldPrefix + "0", root),
510
+ ? resolve(json)
511
+ : (formData.set(formFieldPrefix + "0", json),
478
512
  0 === pendingParts && resolve(formData));
513
+ return function () {
514
+ 0 < pendingParts &&
515
+ ((pendingParts = 0),
516
+ null === formData ? resolve(json) : resolve(formData));
517
+ };
479
518
  }
480
519
  var boundCache = new WeakMap();
481
520
  function encodeFormData(reference) {
@@ -614,22 +653,38 @@ function bind() {
614
653
  }
615
654
  return newFn;
616
655
  }
656
+ function createBoundServerReference(metaData, callServer, encodeFormAction) {
657
+ function action() {
658
+ var args = Array.prototype.slice.call(arguments);
659
+ return bound
660
+ ? "fulfilled" === bound.status
661
+ ? callServer(id, bound.value.concat(args))
662
+ : Promise.resolve(bound).then(function (boundArgs) {
663
+ return callServer(id, boundArgs.concat(args));
664
+ })
665
+ : callServer(id, args);
666
+ }
667
+ var id = metaData.id,
668
+ bound = metaData.bound;
669
+ registerServerReference(action, { id: id, bound: bound }, encodeFormAction);
670
+ return action;
671
+ }
617
672
  function createServerReference$1(id, callServer, encodeFormAction) {
618
- function proxy() {
673
+ function action() {
619
674
  var args = Array.prototype.slice.call(arguments);
620
675
  return callServer(id, args);
621
676
  }
622
- registerServerReference(proxy, { id: id, bound: null }, encodeFormAction);
623
- return proxy;
677
+ registerServerReference(action, { id: id, bound: null }, encodeFormAction);
678
+ return action;
624
679
  }
625
- function Chunk(status, value, reason, response) {
680
+ function ReactPromise(status, value, reason, response) {
626
681
  this.status = status;
627
682
  this.value = value;
628
683
  this.reason = reason;
629
684
  this._response = response;
630
685
  }
631
- Chunk.prototype = Object.create(Promise.prototype);
632
- Chunk.prototype.then = function (resolve, reject) {
686
+ ReactPromise.prototype = Object.create(Promise.prototype);
687
+ ReactPromise.prototype.then = function (resolve, reject) {
633
688
  switch (this.status) {
634
689
  case "resolved_model":
635
690
  initializeModelChunk(this);
@@ -643,7 +698,6 @@ Chunk.prototype.then = function (resolve, reject) {
643
698
  break;
644
699
  case "pending":
645
700
  case "blocked":
646
- case "cyclic":
647
701
  resolve &&
648
702
  (null === this.value && (this.value = []), this.value.push(resolve));
649
703
  reject &&
@@ -666,14 +720,13 @@ function readChunk(chunk) {
666
720
  return chunk.value;
667
721
  case "pending":
668
722
  case "blocked":
669
- case "cyclic":
670
723
  throw chunk;
671
724
  default:
672
725
  throw chunk.reason;
673
726
  }
674
727
  }
675
728
  function createPendingChunk(response) {
676
- return new Chunk("pending", null, null, response);
729
+ return new ReactPromise("pending", null, null, response);
677
730
  }
678
731
  function wakeChunk(listeners, value) {
679
732
  for (var i = 0; i < listeners.length; i++) (0, listeners[i])(value);
@@ -685,7 +738,6 @@ function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
685
738
  break;
686
739
  case "pending":
687
740
  case "blocked":
688
- case "cyclic":
689
741
  if (chunk.value)
690
742
  for (var i = 0; i < resolveListeners.length; i++)
691
743
  chunk.value.push(resolveListeners[i]);
@@ -715,7 +767,7 @@ function triggerErrorOnChunk(chunk, error) {
715
767
  }
716
768
  }
717
769
  function createResolvedIteratorResultChunk(response, value, done) {
718
- return new Chunk(
770
+ return new ReactPromise(
719
771
  "resolved_model",
720
772
  (done ? '{"done":true,"value":' : '{"done":false,"value":') + value + "}",
721
773
  null,
@@ -751,55 +803,42 @@ function resolveModuleChunk(chunk, value) {
751
803
  wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners));
752
804
  }
753
805
  }
754
- var initializingChunk = null,
755
- initializingChunkBlockedModel = null;
806
+ var initializingHandler = null;
756
807
  function initializeModelChunk(chunk) {
757
- var prevChunk = initializingChunk,
758
- prevBlocked = initializingChunkBlockedModel;
759
- initializingChunk = chunk;
760
- initializingChunkBlockedModel = null;
808
+ var prevHandler = initializingHandler;
809
+ initializingHandler = null;
761
810
  var resolvedModel = chunk.value;
762
- chunk.status = "cyclic";
811
+ chunk.status = "blocked";
763
812
  chunk.value = null;
764
813
  chunk.reason = null;
765
814
  try {
766
- var value = JSON.parse(resolvedModel, chunk._response._fromJSON);
767
- if (
768
- null !== initializingChunkBlockedModel &&
769
- 0 < initializingChunkBlockedModel.deps
770
- )
771
- (initializingChunkBlockedModel.value = value), (chunk.status = "blocked");
772
- else {
773
- var resolveListeners = chunk.value;
774
- chunk.status = "fulfilled";
775
- chunk.value = value;
776
- null !== resolveListeners && wakeChunk(resolveListeners, value);
815
+ var value = JSON.parse(resolvedModel, chunk._response._fromJSON),
816
+ resolveListeners = chunk.value;
817
+ null !== resolveListeners &&
818
+ ((chunk.value = null),
819
+ (chunk.reason = null),
820
+ wakeChunk(resolveListeners, value));
821
+ if (null !== initializingHandler) {
822
+ if (initializingHandler.errored) throw initializingHandler.value;
823
+ if (0 < initializingHandler.deps) {
824
+ initializingHandler.value = value;
825
+ initializingHandler.chunk = chunk;
826
+ return;
827
+ }
777
828
  }
829
+ chunk.status = "fulfilled";
830
+ chunk.value = value;
778
831
  } catch (error) {
779
832
  (chunk.status = "rejected"), (chunk.reason = error);
780
833
  } finally {
781
- (initializingChunk = prevChunk),
782
- (initializingChunkBlockedModel = prevBlocked);
834
+ initializingHandler = prevHandler;
783
835
  }
784
836
  }
785
837
  function initializeModuleChunk(chunk) {
786
838
  try {
787
- var metadata = chunk.value,
788
- moduleExports = __webpack_require__(metadata[0]);
789
- if (4 === metadata.length && "function" === typeof moduleExports.then)
790
- if ("fulfilled" === moduleExports.status)
791
- moduleExports = moduleExports.value;
792
- else throw moduleExports.reason;
793
- var JSCompiler_inline_result =
794
- "*" === metadata[2]
795
- ? moduleExports
796
- : "" === metadata[2]
797
- ? moduleExports.__esModule
798
- ? moduleExports.default
799
- : moduleExports
800
- : moduleExports[metadata[2]];
839
+ var value = requireModule(chunk.value);
801
840
  chunk.status = "fulfilled";
802
- chunk.value = JSCompiler_inline_result;
841
+ chunk.value = value;
803
842
  } catch (error) {
804
843
  (chunk.status = "rejected"), (chunk.reason = error);
805
844
  }
@@ -809,62 +848,151 @@ function reportGlobalError(response, error) {
809
848
  "pending" === chunk.status && triggerErrorOnChunk(chunk, error);
810
849
  });
811
850
  }
851
+ function createLazyChunkWrapper(chunk) {
852
+ return { $$typeof: REACT_LAZY_TYPE, _payload: chunk, _init: readChunk };
853
+ }
812
854
  function getChunk(response, id) {
813
855
  var chunks = response._chunks,
814
856
  chunk = chunks.get(id);
815
857
  chunk || ((chunk = createPendingChunk(response)), chunks.set(id, chunk));
816
858
  return chunk;
817
859
  }
818
- function createModelResolver(
819
- chunk,
860
+ function waitForReference(
861
+ referencedChunk,
820
862
  parentObject,
821
863
  key,
822
- cyclic,
823
864
  response,
824
865
  map,
825
866
  path
826
867
  ) {
827
- if (initializingChunkBlockedModel) {
828
- var blocked = initializingChunkBlockedModel;
829
- cyclic || blocked.deps++;
868
+ function fulfill(value) {
869
+ for (var i = 1; i < path.length; i++) {
870
+ for (; value.$$typeof === REACT_LAZY_TYPE; )
871
+ if (((value = value._payload), value === handler.chunk))
872
+ value = handler.value;
873
+ else if ("fulfilled" === value.status) value = value.value;
874
+ else {
875
+ path.splice(0, i - 1);
876
+ value.then(fulfill, reject);
877
+ return;
878
+ }
879
+ value = value[path[i]];
880
+ }
881
+ i = map(response, value, parentObject, key);
882
+ parentObject[key] = i;
883
+ "" === key && null === handler.value && (handler.value = i);
884
+ if (
885
+ parentObject[0] === REACT_ELEMENT_TYPE &&
886
+ "object" === typeof handler.value &&
887
+ null !== handler.value &&
888
+ handler.value.$$typeof === REACT_ELEMENT_TYPE
889
+ )
890
+ switch (((value = handler.value), key)) {
891
+ case "3":
892
+ value.props = i;
893
+ }
894
+ handler.deps--;
895
+ 0 === handler.deps &&
896
+ ((i = handler.chunk),
897
+ null !== i &&
898
+ "blocked" === i.status &&
899
+ ((value = i.value),
900
+ (i.status = "fulfilled"),
901
+ (i.value = handler.value),
902
+ null !== value && wakeChunk(value, handler.value)));
903
+ }
904
+ function reject(error) {
905
+ if (!handler.errored) {
906
+ handler.errored = !0;
907
+ handler.value = error;
908
+ var chunk = handler.chunk;
909
+ null !== chunk &&
910
+ "blocked" === chunk.status &&
911
+ triggerErrorOnChunk(chunk, error);
912
+ }
913
+ }
914
+ if (initializingHandler) {
915
+ var handler = initializingHandler;
916
+ handler.deps++;
830
917
  } else
831
- blocked = initializingChunkBlockedModel = {
832
- deps: cyclic ? 0 : 1,
833
- value: null
918
+ handler = initializingHandler = {
919
+ parent: null,
920
+ chunk: null,
921
+ value: null,
922
+ deps: 1,
923
+ errored: !1
834
924
  };
835
- return function (value) {
836
- for (var i = 1; i < path.length; i++) value = value[path[i]];
837
- parentObject[key] = map(response, value);
838
- "" === key && null === blocked.value && (blocked.value = parentObject[key]);
839
- blocked.deps--;
840
- 0 === blocked.deps &&
841
- "blocked" === chunk.status &&
842
- ((value = chunk.value),
843
- (chunk.status = "fulfilled"),
844
- (chunk.value = blocked.value),
845
- null !== value && wakeChunk(value, blocked.value));
846
- };
847
- }
848
- function createModelReject(chunk) {
849
- return function (error) {
850
- return triggerErrorOnChunk(chunk, error);
851
- };
925
+ referencedChunk.then(fulfill, reject);
926
+ return null;
852
927
  }
853
- function createServerReferenceProxy(response, metaData) {
854
- function proxy() {
855
- var args = Array.prototype.slice.call(arguments),
856
- p = metaData.bound;
857
- return p
858
- ? "fulfilled" === p.status
859
- ? callServer(metaData.id, p.value.concat(args))
860
- : Promise.resolve(p).then(function (bound) {
861
- return callServer(metaData.id, bound.concat(args));
862
- })
863
- : callServer(metaData.id, args);
864
- }
865
- var callServer = response._callServer;
866
- registerServerReference(proxy, metaData, response._encodeFormAction);
867
- return proxy;
928
+ function loadServerReference(response, metaData, parentObject, key) {
929
+ if (!response._serverReferenceConfig)
930
+ return createBoundServerReference(
931
+ metaData,
932
+ response._callServer,
933
+ response._encodeFormAction
934
+ );
935
+ var serverReference = resolveServerReference(
936
+ response._serverReferenceConfig,
937
+ metaData.id
938
+ );
939
+ if ((response = preloadModule(serverReference)))
940
+ metaData.bound && (response = Promise.all([response, metaData.bound]));
941
+ else if (metaData.bound) response = Promise.resolve(metaData.bound);
942
+ else return requireModule(serverReference);
943
+ if (initializingHandler) {
944
+ var handler = initializingHandler;
945
+ handler.deps++;
946
+ } else
947
+ handler = initializingHandler = {
948
+ parent: null,
949
+ chunk: null,
950
+ value: null,
951
+ deps: 1,
952
+ errored: !1
953
+ };
954
+ response.then(
955
+ function () {
956
+ var resolvedValue = requireModule(serverReference);
957
+ if (metaData.bound) {
958
+ var boundArgs = metaData.bound.value.slice(0);
959
+ boundArgs.unshift(null);
960
+ resolvedValue = resolvedValue.bind.apply(resolvedValue, boundArgs);
961
+ }
962
+ parentObject[key] = resolvedValue;
963
+ "" === key && null === handler.value && (handler.value = resolvedValue);
964
+ if (
965
+ parentObject[0] === REACT_ELEMENT_TYPE &&
966
+ "object" === typeof handler.value &&
967
+ null !== handler.value &&
968
+ handler.value.$$typeof === REACT_ELEMENT_TYPE
969
+ )
970
+ switch (((boundArgs = handler.value), key)) {
971
+ case "3":
972
+ boundArgs.props = resolvedValue;
973
+ }
974
+ handler.deps--;
975
+ 0 === handler.deps &&
976
+ ((resolvedValue = handler.chunk),
977
+ null !== resolvedValue &&
978
+ "blocked" === resolvedValue.status &&
979
+ ((boundArgs = resolvedValue.value),
980
+ (resolvedValue.status = "fulfilled"),
981
+ (resolvedValue.value = handler.value),
982
+ null !== boundArgs && wakeChunk(boundArgs, handler.value)));
983
+ },
984
+ function (error) {
985
+ if (!handler.errored) {
986
+ handler.errored = !0;
987
+ handler.value = error;
988
+ var chunk = handler.chunk;
989
+ null !== chunk &&
990
+ "blocked" === chunk.status &&
991
+ triggerErrorOnChunk(chunk, error);
992
+ }
993
+ }
994
+ );
995
+ return null;
868
996
  }
869
997
  function getOutlinedModel(response, reference, parentObject, key, map) {
870
998
  reference = reference.split(":");
@@ -879,29 +1007,40 @@ function getOutlinedModel(response, reference, parentObject, key, map) {
879
1007
  }
880
1008
  switch (id.status) {
881
1009
  case "fulfilled":
882
- parentObject = id.value;
883
- for (key = 1; key < reference.length; key++)
884
- parentObject = parentObject[reference[key]];
885
- return map(response, parentObject);
1010
+ var value = id.value;
1011
+ for (id = 1; id < reference.length; id++) {
1012
+ for (; value.$$typeof === REACT_LAZY_TYPE; )
1013
+ if (((value = value._payload), "fulfilled" === value.status))
1014
+ value = value.value;
1015
+ else
1016
+ return waitForReference(
1017
+ value,
1018
+ parentObject,
1019
+ key,
1020
+ response,
1021
+ map,
1022
+ reference.slice(id - 1)
1023
+ );
1024
+ value = value[reference[id]];
1025
+ }
1026
+ return map(response, value, parentObject, key);
886
1027
  case "pending":
887
1028
  case "blocked":
888
- case "cyclic":
889
- var parentChunk = initializingChunk;
890
- id.then(
891
- createModelResolver(
892
- parentChunk,
893
- parentObject,
894
- key,
895
- "cyclic" === id.status,
896
- response,
897
- map,
898
- reference
899
- ),
900
- createModelReject(parentChunk)
901
- );
902
- return null;
1029
+ return waitForReference(id, parentObject, key, response, map, reference);
903
1030
  default:
904
- throw id.reason;
1031
+ return (
1032
+ initializingHandler
1033
+ ? ((initializingHandler.errored = !0),
1034
+ (initializingHandler.value = id.reason))
1035
+ : (initializingHandler = {
1036
+ parent: null,
1037
+ chunk: null,
1038
+ value: id.reason,
1039
+ deps: 0,
1040
+ errored: !0
1041
+ }),
1042
+ null
1043
+ );
905
1044
  }
906
1045
  }
907
1046
  function createMap(response, model) {
@@ -927,7 +1066,19 @@ function createModel(response, model) {
927
1066
  }
928
1067
  function parseModelString(response, parentObject, key, value) {
929
1068
  if ("$" === value[0]) {
930
- if ("$" === value) return REACT_ELEMENT_TYPE;
1069
+ if ("$" === value)
1070
+ return (
1071
+ null !== initializingHandler &&
1072
+ "0" === key &&
1073
+ (initializingHandler = {
1074
+ parent: initializingHandler,
1075
+ chunk: null,
1076
+ value: null,
1077
+ deps: 0,
1078
+ errored: !1
1079
+ }),
1080
+ REACT_ELEMENT_TYPE
1081
+ );
931
1082
  switch (value[1]) {
932
1083
  case "$":
933
1084
  return value.slice(1);
@@ -935,7 +1086,7 @@ function parseModelString(response, parentObject, key, value) {
935
1086
  return (
936
1087
  (parentObject = parseInt(value.slice(2), 16)),
937
1088
  (response = getChunk(response, parentObject)),
938
- { $$typeof: REACT_LAZY_TYPE, _payload: response, _init: readChunk }
1089
+ createLazyChunkWrapper(response)
939
1090
  );
940
1091
  case "@":
941
1092
  if (2 === value.length) return new Promise(function () {});
@@ -951,7 +1102,7 @@ function parseModelString(response, parentObject, key, value) {
951
1102
  value,
952
1103
  parentObject,
953
1104
  key,
954
- createServerReferenceProxy
1105
+ loadServerReference
955
1106
  )
956
1107
  );
957
1108
  case "T":
@@ -982,6 +1133,8 @@ function parseModelString(response, parentObject, key, value) {
982
1133
  (value = value.slice(2)),
983
1134
  getOutlinedModel(response, value, parentObject, key, createFormData)
984
1135
  );
1136
+ case "Z":
1137
+ return resolveErrorProd();
985
1138
  case "i":
986
1139
  return (
987
1140
  (value = value.slice(2)),
@@ -1013,8 +1166,9 @@ function missingCall() {
1013
1166
  'Trying to call a function from "use server" but the callServer option was not implemented in your router runtime.'
1014
1167
  );
1015
1168
  }
1016
- function createResponse(
1169
+ function ResponseInstance(
1017
1170
  bundlerConfig,
1171
+ serverReferenceConfig,
1018
1172
  moduleLoading,
1019
1173
  callServer,
1020
1174
  encodeFormAction,
@@ -1022,31 +1176,26 @@ function createResponse(
1022
1176
  temporaryReferences
1023
1177
  ) {
1024
1178
  var chunks = new Map();
1025
- bundlerConfig = {
1026
- _bundlerConfig: bundlerConfig,
1027
- _moduleLoading: moduleLoading,
1028
- _callServer: void 0 !== callServer ? callServer : missingCall,
1029
- _encodeFormAction: encodeFormAction,
1030
- _nonce: nonce,
1031
- _chunks: chunks,
1032
- _stringDecoder: new util.TextDecoder(),
1033
- _fromJSON: null,
1034
- _rowState: 0,
1035
- _rowID: 0,
1036
- _rowTag: 0,
1037
- _rowLength: 0,
1038
- _buffer: [],
1039
- _tempRefs: temporaryReferences
1040
- };
1041
- bundlerConfig._fromJSON = createFromJSONCallback(bundlerConfig);
1042
- return bundlerConfig;
1179
+ this._bundlerConfig = bundlerConfig;
1180
+ this._serverReferenceConfig = serverReferenceConfig;
1181
+ this._moduleLoading = moduleLoading;
1182
+ this._callServer = void 0 !== callServer ? callServer : missingCall;
1183
+ this._encodeFormAction = encodeFormAction;
1184
+ this._nonce = nonce;
1185
+ this._chunks = chunks;
1186
+ this._stringDecoder = new util.TextDecoder();
1187
+ this._fromJSON = null;
1188
+ this._rowLength = this._rowTag = this._rowID = this._rowState = 0;
1189
+ this._buffer = [];
1190
+ this._tempRefs = temporaryReferences;
1191
+ this._fromJSON = createFromJSONCallback(this);
1043
1192
  }
1044
1193
  function resolveBuffer(response, id, buffer) {
1045
1194
  var chunks = response._chunks,
1046
1195
  chunk = chunks.get(id);
1047
1196
  chunk && "pending" !== chunk.status
1048
1197
  ? chunk.reason.enqueueValue(buffer)
1049
- : chunks.set(id, new Chunk("fulfilled", buffer, null, response));
1198
+ : chunks.set(id, new ReactPromise("fulfilled", buffer, null, response));
1050
1199
  }
1051
1200
  function resolveModule(response, id, model) {
1052
1201
  var chunks = response._chunks,
@@ -1063,7 +1212,7 @@ function resolveModule(response, id, model) {
1063
1212
  var blockedChunk = chunk;
1064
1213
  blockedChunk.status = "blocked";
1065
1214
  } else
1066
- (blockedChunk = new Chunk("blocked", null, null, response)),
1215
+ (blockedChunk = new ReactPromise("blocked", null, null, response)),
1067
1216
  chunks.set(id, blockedChunk);
1068
1217
  model.then(
1069
1218
  function () {
@@ -1078,7 +1227,7 @@ function resolveModule(response, id, model) {
1078
1227
  ? resolveModuleChunk(chunk, clientReference)
1079
1228
  : chunks.set(
1080
1229
  id,
1081
- new Chunk("resolved_module", clientReference, null, response)
1230
+ new ReactPromise("resolved_module", clientReference, null, response)
1082
1231
  );
1083
1232
  }
1084
1233
  function resolveStream(response, id, stream, controller) {
@@ -1091,7 +1240,10 @@ function resolveStream(response, id, stream, controller) {
1091
1240
  (chunk.value = stream),
1092
1241
  (chunk.reason = controller),
1093
1242
  null !== response && wakeChunk(response, chunk.value))
1094
- : chunks.set(id, new Chunk("fulfilled", stream, controller, response));
1243
+ : chunks.set(
1244
+ id,
1245
+ new ReactPromise("fulfilled", stream, controller, response)
1246
+ );
1095
1247
  }
1096
1248
  function startReadableStream(response, id, type) {
1097
1249
  var controller = null;
@@ -1112,7 +1264,7 @@ function startReadableStream(response, id, type) {
1112
1264
  },
1113
1265
  enqueueModel: function (json) {
1114
1266
  if (null === previousBlockedChunk) {
1115
- var chunk = new Chunk("resolved_model", json, null, response);
1267
+ var chunk = new ReactPromise("resolved_model", json, null, response);
1116
1268
  initializeModelChunk(chunk);
1117
1269
  "fulfilled" === chunk.status
1118
1270
  ? controller.enqueue(chunk.value)
@@ -1127,8 +1279,8 @@ function startReadableStream(response, id, type) {
1127
1279
  (previousBlockedChunk = chunk));
1128
1280
  } else {
1129
1281
  chunk = previousBlockedChunk;
1130
- var chunk$51 = createPendingChunk(response);
1131
- chunk$51.then(
1282
+ var chunk$52 = createPendingChunk(response);
1283
+ chunk$52.then(
1132
1284
  function (v) {
1133
1285
  return controller.enqueue(v);
1134
1286
  },
@@ -1136,10 +1288,10 @@ function startReadableStream(response, id, type) {
1136
1288
  return controller.error(e);
1137
1289
  }
1138
1290
  );
1139
- previousBlockedChunk = chunk$51;
1291
+ previousBlockedChunk = chunk$52;
1140
1292
  chunk.then(function () {
1141
- previousBlockedChunk === chunk$51 && (previousBlockedChunk = null);
1142
- resolveModelChunk(chunk$51, json);
1293
+ previousBlockedChunk === chunk$52 && (previousBlockedChunk = null);
1294
+ resolveModelChunk(chunk$52, json);
1143
1295
  });
1144
1296
  }
1145
1297
  },
@@ -1188,7 +1340,7 @@ function startAsyncIterable(response, id, iterator) {
1188
1340
  );
1189
1341
  if (nextReadIndex === buffer.length) {
1190
1342
  if (closed)
1191
- return new Chunk(
1343
+ return new ReactPromise(
1192
1344
  "fulfilled",
1193
1345
  { done: !0, value: void 0 },
1194
1346
  null,
@@ -1207,7 +1359,7 @@ function startAsyncIterable(response, id, iterator) {
1207
1359
  {
1208
1360
  enqueueValue: function (value) {
1209
1361
  if (nextWriteIndex === buffer.length)
1210
- buffer[nextWriteIndex] = new Chunk(
1362
+ buffer[nextWriteIndex] = new ReactPromise(
1211
1363
  "fulfilled",
1212
1364
  { done: !1, value: value },
1213
1365
  null,
@@ -1263,12 +1415,19 @@ function startAsyncIterable(response, id, iterator) {
1263
1415
  }
1264
1416
  );
1265
1417
  }
1418
+ function resolveErrorProd() {
1419
+ var error = Error(
1420
+ "An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error."
1421
+ );
1422
+ error.stack = "Error: " + error.message;
1423
+ return error;
1424
+ }
1266
1425
  function mergeBuffer(buffer, lastChunk) {
1267
1426
  for (var l = buffer.length, byteLength = lastChunk.length, i = 0; i < l; i++)
1268
1427
  byteLength += buffer[i].byteLength;
1269
1428
  byteLength = new Uint8Array(byteLength);
1270
- for (var i$52 = (i = 0); i$52 < l; i$52++) {
1271
- var chunk = buffer[i$52];
1429
+ for (var i$53 = (i = 0); i$53 < l; i$53++) {
1430
+ var chunk = buffer[i$53];
1272
1431
  byteLength.set(chunk, i);
1273
1432
  i += chunk.byteLength;
1274
1433
  }
@@ -1294,7 +1453,7 @@ function resolveTypedArray(
1294
1453
  );
1295
1454
  resolveBuffer(response, id, constructor);
1296
1455
  }
1297
- function processFullRow(response, id, tag, buffer, chunk) {
1456
+ function processFullBinaryRow(response, id, tag, buffer, chunk) {
1298
1457
  switch (tag) {
1299
1458
  case 65:
1300
1459
  resolveBuffer(response, id, mergeBuffer(buffer, chunk).buffer);
@@ -1347,6 +1506,9 @@ function processFullRow(response, id, tag, buffer, chunk) {
1347
1506
  )
1348
1507
  row += stringDecoder.decode(buffer[i], decoderOptions);
1349
1508
  row += stringDecoder.decode(chunk);
1509
+ processFullStringRow(response, id, tag, row);
1510
+ }
1511
+ function processFullStringRow(response, id, tag, row) {
1350
1512
  switch (tag) {
1351
1513
  case 73:
1352
1514
  resolveModule(response, id, row);
@@ -1396,22 +1558,20 @@ function processFullRow(response, id, tag, buffer, chunk) {
1396
1558
  }
1397
1559
  break;
1398
1560
  case 69:
1399
- tag = JSON.parse(row).digest;
1400
- row = Error(
1401
- "An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error."
1402
- );
1403
- row.stack = "Error: " + row.message;
1404
- row.digest = tag;
1561
+ tag = JSON.parse(row);
1562
+ row = resolveErrorProd();
1563
+ row.digest = tag.digest;
1405
1564
  tag = response._chunks;
1406
- (buffer = tag.get(id))
1407
- ? triggerErrorOnChunk(buffer, row)
1408
- : tag.set(id, new Chunk("rejected", null, row, response));
1565
+ var chunk = tag.get(id);
1566
+ chunk
1567
+ ? triggerErrorOnChunk(chunk, row)
1568
+ : tag.set(id, new ReactPromise("rejected", null, row, response));
1409
1569
  break;
1410
1570
  case 84:
1411
1571
  tag = response._chunks;
1412
- (buffer = tag.get(id)) && "pending" !== buffer.status
1413
- ? buffer.reason.enqueueValue(row)
1414
- : tag.set(id, new Chunk("fulfilled", row, null, response));
1572
+ (chunk = tag.get(id)) && "pending" !== chunk.status
1573
+ ? chunk.reason.enqueueValue(row)
1574
+ : tag.set(id, new ReactPromise("fulfilled", row, null, response));
1415
1575
  break;
1416
1576
  case 68:
1417
1577
  case 87:
@@ -1437,28 +1597,52 @@ function processFullRow(response, id, tag, buffer, chunk) {
1437
1597
  break;
1438
1598
  default:
1439
1599
  (tag = response._chunks),
1440
- (buffer = tag.get(id))
1441
- ? resolveModelChunk(buffer, row)
1442
- : tag.set(id, new Chunk("resolved_model", row, null, response));
1600
+ (chunk = tag.get(id))
1601
+ ? resolveModelChunk(chunk, row)
1602
+ : tag.set(
1603
+ id,
1604
+ new ReactPromise("resolved_model", row, null, response)
1605
+ );
1443
1606
  }
1444
1607
  }
1445
1608
  function createFromJSONCallback(response) {
1446
1609
  return function (key, value) {
1447
- return "string" === typeof value
1448
- ? parseModelString(response, this, key, value)
1449
- : "object" === typeof value && null !== value
1450
- ? ((key =
1451
- value[0] === REACT_ELEMENT_TYPE
1452
- ? {
1453
- $$typeof: REACT_ELEMENT_TYPE,
1454
- type: value[1],
1455
- key: value[2],
1456
- ref: null,
1457
- props: value[3]
1458
- }
1459
- : value),
1460
- key)
1461
- : value;
1610
+ if ("string" === typeof value)
1611
+ return parseModelString(response, this, key, value);
1612
+ if ("object" === typeof value && null !== value) {
1613
+ if (value[0] === REACT_ELEMENT_TYPE) {
1614
+ if (
1615
+ ((key = {
1616
+ $$typeof: REACT_ELEMENT_TYPE,
1617
+ type: value[1],
1618
+ key: value[2],
1619
+ ref: null,
1620
+ props: value[3]
1621
+ }),
1622
+ null !== initializingHandler)
1623
+ )
1624
+ if (
1625
+ ((value = initializingHandler),
1626
+ (initializingHandler = value.parent),
1627
+ value.errored)
1628
+ )
1629
+ (key = new ReactPromise("rejected", null, value.value, response)),
1630
+ (key = createLazyChunkWrapper(key));
1631
+ else if (0 < value.deps) {
1632
+ var blockedChunk = new ReactPromise(
1633
+ "blocked",
1634
+ null,
1635
+ null,
1636
+ response
1637
+ );
1638
+ value.value = key;
1639
+ value.chunk = blockedChunk;
1640
+ key = createLazyChunkWrapper(blockedChunk);
1641
+ }
1642
+ } else key = value;
1643
+ return key;
1644
+ }
1645
+ return value;
1462
1646
  };
1463
1647
  }
1464
1648
  function noServerCall() {
@@ -1466,92 +1650,191 @@ function noServerCall() {
1466
1650
  "Server Functions cannot be called during initial render. This would create a fetch waterfall. Try to use a Server Component to pass data to Client Components instead."
1467
1651
  );
1468
1652
  }
1469
- exports.createFromNodeStream = function (stream, ssrManifest, options) {
1470
- var response = createResponse(
1471
- ssrManifest.moduleMap,
1472
- ssrManifest.moduleLoading,
1653
+ exports.createFromNodeStream = function (
1654
+ stream,
1655
+ serverConsumerManifest,
1656
+ options
1657
+ ) {
1658
+ var response = new ResponseInstance(
1659
+ serverConsumerManifest.moduleMap,
1660
+ serverConsumerManifest.serverModuleMap,
1661
+ serverConsumerManifest.moduleLoading,
1473
1662
  noServerCall,
1474
1663
  options ? options.encodeFormAction : void 0,
1475
1664
  options && "string" === typeof options.nonce ? options.nonce : void 0,
1476
1665
  void 0
1477
1666
  );
1478
1667
  stream.on("data", function (chunk) {
1479
- for (
1480
- var i = 0,
1481
- rowState = response._rowState,
1482
- rowID = response._rowID,
1483
- rowTag = response._rowTag,
1484
- rowLength = response._rowLength,
1485
- buffer = response._buffer,
1486
- chunkLength = chunk.length;
1487
- i < chunkLength;
1668
+ if ("string" === typeof chunk) {
1669
+ for (
1670
+ var i = 0,
1671
+ rowState = response._rowState,
1672
+ rowID = response._rowID,
1673
+ rowTag = response._rowTag,
1674
+ rowLength = response._rowLength,
1675
+ buffer = response._buffer,
1676
+ chunkLength = chunk.length;
1677
+ i < chunkLength;
1488
1678
 
1489
- ) {
1490
- var lastIdx = -1;
1491
- switch (rowState) {
1492
- case 0:
1493
- lastIdx = chunk[i++];
1494
- 58 === lastIdx
1495
- ? (rowState = 1)
1496
- : (rowID =
1497
- (rowID << 4) | (96 < lastIdx ? lastIdx - 87 : lastIdx - 48));
1498
- continue;
1499
- case 1:
1500
- rowState = chunk[i];
1501
- 84 === rowState ||
1502
- 65 === rowState ||
1503
- 79 === rowState ||
1504
- 111 === rowState ||
1505
- 85 === rowState ||
1506
- 83 === rowState ||
1507
- 115 === rowState ||
1508
- 76 === rowState ||
1509
- 108 === rowState ||
1510
- 71 === rowState ||
1511
- 103 === rowState ||
1512
- 77 === rowState ||
1513
- 109 === rowState ||
1514
- 86 === rowState
1515
- ? ((rowTag = rowState), (rowState = 2), i++)
1516
- : (64 < rowState && 91 > rowState) ||
1517
- 114 === rowState ||
1518
- 120 === rowState
1519
- ? ((rowTag = rowState), (rowState = 3), i++)
1520
- : ((rowTag = 0), (rowState = 3));
1521
- continue;
1522
- case 2:
1523
- lastIdx = chunk[i++];
1524
- 44 === lastIdx
1525
- ? (rowState = 4)
1526
- : (rowLength =
1527
- (rowLength << 4) |
1528
- (96 < lastIdx ? lastIdx - 87 : lastIdx - 48));
1529
- continue;
1530
- case 3:
1531
- lastIdx = chunk.indexOf(10, i);
1532
- break;
1533
- case 4:
1534
- (lastIdx = i + rowLength), lastIdx > chunk.length && (lastIdx = -1);
1679
+ ) {
1680
+ var lastIdx = -1;
1681
+ switch (rowState) {
1682
+ case 0:
1683
+ lastIdx = chunk.charCodeAt(i++);
1684
+ 58 === lastIdx
1685
+ ? (rowState = 1)
1686
+ : (rowID =
1687
+ (rowID << 4) | (96 < lastIdx ? lastIdx - 87 : lastIdx - 48));
1688
+ continue;
1689
+ case 1:
1690
+ rowState = chunk.charCodeAt(i);
1691
+ 84 === rowState ||
1692
+ 65 === rowState ||
1693
+ 79 === rowState ||
1694
+ 111 === rowState ||
1695
+ 85 === rowState ||
1696
+ 83 === rowState ||
1697
+ 115 === rowState ||
1698
+ 76 === rowState ||
1699
+ 108 === rowState ||
1700
+ 71 === rowState ||
1701
+ 103 === rowState ||
1702
+ 77 === rowState ||
1703
+ 109 === rowState ||
1704
+ 86 === rowState
1705
+ ? ((rowTag = rowState), (rowState = 2), i++)
1706
+ : (64 < rowState && 91 > rowState) ||
1707
+ 114 === rowState ||
1708
+ 120 === rowState
1709
+ ? ((rowTag = rowState), (rowState = 3), i++)
1710
+ : ((rowTag = 0), (rowState = 3));
1711
+ continue;
1712
+ case 2:
1713
+ lastIdx = chunk.charCodeAt(i++);
1714
+ 44 === lastIdx
1715
+ ? (rowState = 4)
1716
+ : (rowLength =
1717
+ (rowLength << 4) |
1718
+ (96 < lastIdx ? lastIdx - 87 : lastIdx - 48));
1719
+ continue;
1720
+ case 3:
1721
+ lastIdx = chunk.indexOf("\n", i);
1722
+ break;
1723
+ case 4:
1724
+ if (84 !== rowTag)
1725
+ throw Error(
1726
+ "Binary RSC chunks cannot be encoded as strings. This is a bug in the wiring of the React streams."
1727
+ );
1728
+ if (rowLength < chunk.length || chunk.length > 3 * rowLength)
1729
+ throw Error(
1730
+ "String chunks need to be passed in their original shape. Not split into smaller string chunks. This is a bug in the wiring of the React streams."
1731
+ );
1732
+ lastIdx = chunk.length;
1733
+ }
1734
+ if (-1 < lastIdx) {
1735
+ if (0 < buffer.length)
1736
+ throw Error(
1737
+ "String chunks need to be passed in their original shape. Not split into smaller string chunks. This is a bug in the wiring of the React streams."
1738
+ );
1739
+ i = chunk.slice(i, lastIdx);
1740
+ processFullStringRow(response, rowID, rowTag, i);
1741
+ i = lastIdx;
1742
+ 3 === rowState && i++;
1743
+ rowLength = rowID = rowTag = rowState = 0;
1744
+ buffer.length = 0;
1745
+ } else if (chunk.length !== i)
1746
+ throw Error(
1747
+ "String chunks need to be passed in their original shape. Not split into smaller string chunks. This is a bug in the wiring of the React streams."
1748
+ );
1535
1749
  }
1536
- var offset = chunk.byteOffset + i;
1537
- if (-1 < lastIdx)
1538
- (rowLength = new Uint8Array(chunk.buffer, offset, lastIdx - i)),
1539
- processFullRow(response, rowID, rowTag, buffer, rowLength),
1540
- (i = lastIdx),
1541
- 3 === rowState && i++,
1542
- (rowLength = rowID = rowTag = rowState = 0),
1543
- (buffer.length = 0);
1544
- else {
1545
- chunk = new Uint8Array(chunk.buffer, offset, chunk.byteLength - i);
1546
- buffer.push(chunk);
1547
- rowLength -= chunk.byteLength;
1548
- break;
1750
+ response._rowState = rowState;
1751
+ response._rowID = rowID;
1752
+ response._rowTag = rowTag;
1753
+ response._rowLength = rowLength;
1754
+ } else {
1755
+ rowLength = 0;
1756
+ chunkLength = response._rowState;
1757
+ rowID = response._rowID;
1758
+ i = response._rowTag;
1759
+ rowState = response._rowLength;
1760
+ buffer = response._buffer;
1761
+ for (rowTag = chunk.length; rowLength < rowTag; ) {
1762
+ lastIdx = -1;
1763
+ switch (chunkLength) {
1764
+ case 0:
1765
+ lastIdx = chunk[rowLength++];
1766
+ 58 === lastIdx
1767
+ ? (chunkLength = 1)
1768
+ : (rowID =
1769
+ (rowID << 4) | (96 < lastIdx ? lastIdx - 87 : lastIdx - 48));
1770
+ continue;
1771
+ case 1:
1772
+ chunkLength = chunk[rowLength];
1773
+ 84 === chunkLength ||
1774
+ 65 === chunkLength ||
1775
+ 79 === chunkLength ||
1776
+ 111 === chunkLength ||
1777
+ 85 === chunkLength ||
1778
+ 83 === chunkLength ||
1779
+ 115 === chunkLength ||
1780
+ 76 === chunkLength ||
1781
+ 108 === chunkLength ||
1782
+ 71 === chunkLength ||
1783
+ 103 === chunkLength ||
1784
+ 77 === chunkLength ||
1785
+ 109 === chunkLength ||
1786
+ 86 === chunkLength
1787
+ ? ((i = chunkLength), (chunkLength = 2), rowLength++)
1788
+ : (64 < chunkLength && 91 > chunkLength) ||
1789
+ 35 === chunkLength ||
1790
+ 114 === chunkLength ||
1791
+ 120 === chunkLength
1792
+ ? ((i = chunkLength), (chunkLength = 3), rowLength++)
1793
+ : ((i = 0), (chunkLength = 3));
1794
+ continue;
1795
+ case 2:
1796
+ lastIdx = chunk[rowLength++];
1797
+ 44 === lastIdx
1798
+ ? (chunkLength = 4)
1799
+ : (rowState =
1800
+ (rowState << 4) |
1801
+ (96 < lastIdx ? lastIdx - 87 : lastIdx - 48));
1802
+ continue;
1803
+ case 3:
1804
+ lastIdx = chunk.indexOf(10, rowLength);
1805
+ break;
1806
+ case 4:
1807
+ (lastIdx = rowLength + rowState),
1808
+ lastIdx > chunk.length && (lastIdx = -1);
1809
+ }
1810
+ var offset = chunk.byteOffset + rowLength;
1811
+ if (-1 < lastIdx)
1812
+ (rowState = new Uint8Array(
1813
+ chunk.buffer,
1814
+ offset,
1815
+ lastIdx - rowLength
1816
+ )),
1817
+ processFullBinaryRow(response, rowID, i, buffer, rowState),
1818
+ (rowLength = lastIdx),
1819
+ 3 === chunkLength && rowLength++,
1820
+ (rowState = rowID = i = chunkLength = 0),
1821
+ (buffer.length = 0);
1822
+ else {
1823
+ chunk = new Uint8Array(
1824
+ chunk.buffer,
1825
+ offset,
1826
+ chunk.byteLength - rowLength
1827
+ );
1828
+ buffer.push(chunk);
1829
+ rowState -= chunk.byteLength;
1830
+ break;
1831
+ }
1549
1832
  }
1833
+ response._rowState = chunkLength;
1834
+ response._rowID = rowID;
1835
+ response._rowTag = i;
1836
+ response._rowLength = rowState;
1550
1837
  }
1551
- response._rowState = rowState;
1552
- response._rowID = rowID;
1553
- response._rowTag = rowTag;
1554
- response._rowLength = rowLength;
1555
1838
  });
1556
1839
  stream.on("error", function (error) {
1557
1840
  reportGlobalError(response, error);