react-server-dom-turbopack 19.2.7 → 19.2.9

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.
@@ -43,31 +43,39 @@
43
43
  });
44
44
  }
45
45
  function writeChunkAndReturn(destination, chunk) {
46
- if (0 !== chunk.byteLength)
47
- if (2048 < chunk.byteLength)
48
- 0 < writtenBytes &&
49
- (destination.enqueue(
50
- new Uint8Array(currentView.buffer, 0, writtenBytes)
46
+ if (0 === chunk.byteLength)
47
+ if (supportsArrayBufferDetached) {
48
+ if (chunk.buffer.detached)
49
+ throw Error(
50
+ "Cannot transport a detached buffer. This usually happens when trying to transport multiple buffer-spanning views on the same underyling buffer. Either reuse the exact same view by identity or copy the underlying buffer manually via `view.slice()`."
51
+ );
52
+ } else
53
+ didWarnAboutMissingArrayBufferDetached ||
54
+ (console.error(
55
+ "React encountered an empty buffer when writing in an environment that does not support ArrayBuffer.prototype.detached. This could be a security issue if the buffer was not actually empty. Please use a modern browser that supports ArrayBuffer.prototype.detached."
51
56
  ),
52
- (currentView = new Uint8Array(2048)),
53
- (writtenBytes = 0)),
54
- destination.enqueue(chunk);
55
- else {
56
- var allowableBytes = currentView.length - writtenBytes;
57
- allowableBytes < chunk.byteLength &&
58
- (0 === allowableBytes
59
- ? destination.enqueue(currentView)
60
- : (currentView.set(
61
- chunk.subarray(0, allowableBytes),
62
- writtenBytes
63
- ),
64
- destination.enqueue(currentView),
65
- (chunk = chunk.subarray(allowableBytes))),
66
- (currentView = new Uint8Array(2048)),
67
- (writtenBytes = 0));
68
- currentView.set(chunk, writtenBytes);
69
- writtenBytes += chunk.byteLength;
70
- }
57
+ (didWarnAboutMissingArrayBufferDetached = !0));
58
+ else if (2048 < chunk.byteLength)
59
+ 0 < writtenBytes &&
60
+ (destination.enqueue(
61
+ new Uint8Array(currentView.buffer, 0, writtenBytes)
62
+ ),
63
+ (currentView = new Uint8Array(2048)),
64
+ (writtenBytes = 0)),
65
+ destination.enqueue(chunk);
66
+ else {
67
+ var allowableBytes = currentView.length - writtenBytes;
68
+ allowableBytes < chunk.byteLength &&
69
+ (0 === allowableBytes
70
+ ? destination.enqueue(currentView)
71
+ : (currentView.set(chunk.subarray(0, allowableBytes), writtenBytes),
72
+ destination.enqueue(currentView),
73
+ (chunk = chunk.subarray(allowableBytes))),
74
+ (currentView = new Uint8Array(2048)),
75
+ (writtenBytes = 0));
76
+ currentView.set(chunk, writtenBytes);
77
+ writtenBytes += chunk.byteLength;
78
+ }
71
79
  return !0;
72
80
  }
73
81
  function completeWriting(destination) {
@@ -1395,7 +1403,7 @@
1395
1403
  erroredTask(request, streamTask, reason),
1396
1404
  enqueueFlush(request),
1397
1405
  "function" === typeof iterator.throw &&
1398
- iterator.throw(reason).then(error, error));
1406
+ iterator.throw(reason).then(noop, noop));
1399
1407
  }
1400
1408
  function abortIterable() {
1401
1409
  if (0 === streamTask.status) {
@@ -1409,7 +1417,7 @@
1409
1417
  : (erroredTask(request, streamTask, signal.reason),
1410
1418
  enqueueFlush(request));
1411
1419
  "function" === typeof iterator.throw &&
1412
- iterator.throw(reason).then(error, error);
1420
+ iterator.throw(reason).then(noop, noop);
1413
1421
  }
1414
1422
  }
1415
1423
  var isIterator = iterable === iterator,
@@ -2804,14 +2812,35 @@
2804
2812
  }
2805
2813
  function emitTypedArrayChunk(request, id, tag, typedArray, debug) {
2806
2814
  debug ? request.pendingDebugChunks++ : request.pendingChunks++;
2807
- var buffer = new Uint8Array(
2808
- typedArray.buffer,
2809
- typedArray.byteOffset,
2810
- typedArray.byteLength
2811
- );
2812
- typedArray = 2048 < typedArray.byteLength ? buffer.slice() : buffer;
2813
- buffer = typedArray.byteLength;
2814
- id = id.toString(16) + ":" + tag + buffer.toString(16) + ",";
2815
+ a: {
2816
+ var view = new Uint8Array(
2817
+ typedArray.buffer,
2818
+ typedArray.byteOffset,
2819
+ typedArray.byteLength
2820
+ );
2821
+ if (2048 < typedArray.byteLength) {
2822
+ if (
2823
+ 0 !== typedArray.byteOffset ||
2824
+ typedArray.byteLength !== typedArray.buffer.byteLength ||
2825
+ typedArray.buffer.resizable
2826
+ ) {
2827
+ typedArray = view.slice();
2828
+ break a;
2829
+ }
2830
+ if (!supportsArrayBufferDetached) {
2831
+ didWarnAboutMissingArrayBufferDetached ||
2832
+ (console.error(
2833
+ "React copied a partial view into a fresh buffer as a safety precaution because the environment does not implement ArrayBuffer.prototype.detached. This negatively impacts performance. Please use a modern browser that supports ArrayBuffer.prototype.detached."
2834
+ ),
2835
+ (didWarnAboutMissingArrayBufferDetached = !0));
2836
+ typedArray = view.slice();
2837
+ break a;
2838
+ }
2839
+ }
2840
+ typedArray = view;
2841
+ }
2842
+ view = typedArray.byteLength;
2843
+ id = id.toString(16) + ":" + tag + view.toString(16) + ",";
2815
2844
  id = stringToChunk(id);
2816
2845
  debug
2817
2846
  ? request.completedDebugChunks.push(id, typedArray)
@@ -3872,6 +3901,39 @@
3872
3901
  if (hasOwnProperty.call(moduleExports, metadata[2]))
3873
3902
  return moduleExports[metadata[2]];
3874
3903
  }
3904
+ function appendBackingEntry(backingStore, value, key) {
3905
+ var prefix = backingStore.prefix;
3906
+ if (key.startsWith(prefix)) {
3907
+ switch (key[prefix.length]) {
3908
+ case "_":
3909
+ prefix = backingStore.referencedEntries;
3910
+ null === prefix && (prefix = backingStore.referencedEntries = []);
3911
+ prefix.push([key, value]);
3912
+ return;
3913
+ case "S":
3914
+ "string" === typeof value &&
3915
+ ((prefix = backingStore.streamChunks),
3916
+ null === prefix &&
3917
+ (prefix = backingStore.streamChunks = new Map()),
3918
+ (backingStore = prefix.get(key)),
3919
+ void 0 === backingStore
3920
+ ? prefix.set(key, [value])
3921
+ : backingStore.push(value));
3922
+ return;
3923
+ }
3924
+ "string" === typeof value
3925
+ ? ((prefix = backingStore.stringChunks),
3926
+ null === prefix && (prefix = backingStore.stringChunks = new Map()),
3927
+ prefix.set(key, value))
3928
+ : ((prefix = backingStore.blobs),
3929
+ null === prefix && (prefix = backingStore.blobs = new Map()),
3930
+ prefix.set(key, value));
3931
+ }
3932
+ }
3933
+ function getBackingBlob(backingStore, key) {
3934
+ backingStore = backingStore.blobs;
3935
+ return null === backingStore ? void 0 : backingStore.get(key);
3936
+ }
3875
3937
  function ReactPromise(status, value, reason) {
3876
3938
  this.status = status;
3877
3939
  this.value = value;
@@ -4183,9 +4245,11 @@
4183
4245
  function getChunk(response, id) {
4184
4246
  var chunks = response._chunks,
4185
4247
  chunk = chunks.get(id);
4186
- chunk ||
4187
- ((chunk = response._formData.data.get(response._prefix + id)),
4188
- (chunk =
4248
+ if (!chunk) {
4249
+ chunk = response._prefix;
4250
+ var stringChunks = response._formData.stringChunks;
4251
+ chunk = null === stringChunks ? void 0 : stringChunks.get(chunk + id);
4252
+ chunk =
4189
4253
  "string" === typeof chunk
4190
4254
  ? new ReactPromise(
4191
4255
  "resolved_model",
@@ -4194,8 +4258,9 @@
4194
4258
  )
4195
4259
  : response._closed
4196
4260
  ? new ReactPromise("rejected", null, response._closedReason)
4197
- : new ReactPromise("pending", null, null)),
4198
- chunks.set(id, chunk));
4261
+ : new ReactPromise("pending", null, null);
4262
+ chunks.set(id, chunk);
4263
+ }
4199
4264
  return chunk;
4200
4265
  }
4201
4266
  function fulfillReference(response, reference, value, arrayRoot) {
@@ -4442,7 +4507,7 @@
4442
4507
  Error("Already initialized typed array.")
4443
4508
  )
4444
4509
  );
4445
- reference = response._formData.data.get(key).arrayBuffer();
4510
+ reference = getBackingBlob(response._formData, key).arrayBuffer();
4446
4511
  if (initializingHandler) {
4447
4512
  var handler = initializingHandler;
4448
4513
  handler.deps++;
@@ -4486,15 +4551,17 @@
4486
4551
  var chunks = response._chunks;
4487
4552
  stream = new ReactPromise("fulfilled", stream, controller);
4488
4553
  chunks.set(id, stream);
4489
- response = response._formData.data.getAll(response._prefix + id);
4490
- for (id = 0; id < response.length; id++)
4491
- (chunks = response[id]),
4492
- "string" === typeof chunks &&
4493
- ("C" === chunks[0]
4554
+ chunks = response._prefix;
4555
+ response = response._formData.streamChunks;
4556
+ id = null === response ? void 0 : response.get(chunks + "S" + id);
4557
+ if (void 0 !== id)
4558
+ for (response = 0; response < id.length; response++)
4559
+ (chunks = id[response]),
4560
+ "C" === chunks[0]
4494
4561
  ? controller.close(
4495
4562
  "C" === chunks ? '"$undefined"' : chunks.slice(1)
4496
4563
  )
4497
- : controller.enqueueModel(chunks));
4564
+ : controller.enqueueModel(chunks);
4498
4565
  }
4499
4566
  function parseReadableStream(response, reference, type) {
4500
4567
  function enqueue(value) {
@@ -4658,7 +4725,14 @@
4658
4725
  });
4659
4726
  return iterator;
4660
4727
  }
4661
- function parseModelString(response, obj, key, value, reference, arrayRoot) {
4728
+ function parseModelString(
4729
+ response,
4730
+ obj,
4731
+ key$jscomp$0,
4732
+ value,
4733
+ reference,
4734
+ arrayRoot
4735
+ ) {
4662
4736
  if ("$" === value[0]) {
4663
4737
  switch (value[1]) {
4664
4738
  case "$":
@@ -4678,7 +4752,7 @@
4678
4752
  response,
4679
4753
  arrayRoot,
4680
4754
  obj,
4681
- key,
4755
+ key$jscomp$0,
4682
4756
  null,
4683
4757
  loadServerReference$1
4684
4758
  )
@@ -4698,41 +4772,44 @@
4698
4772
  case "Q":
4699
4773
  return (
4700
4774
  (arrayRoot = value.slice(2)),
4701
- getOutlinedModel(response, arrayRoot, obj, key, null, createMap)
4775
+ getOutlinedModel(
4776
+ response,
4777
+ arrayRoot,
4778
+ obj,
4779
+ key$jscomp$0,
4780
+ null,
4781
+ createMap
4782
+ )
4702
4783
  );
4703
4784
  case "W":
4704
4785
  return (
4705
4786
  (arrayRoot = value.slice(2)),
4706
- getOutlinedModel(response, arrayRoot, obj, key, null, createSet)
4787
+ getOutlinedModel(
4788
+ response,
4789
+ arrayRoot,
4790
+ obj,
4791
+ key$jscomp$0,
4792
+ null,
4793
+ createSet
4794
+ )
4707
4795
  );
4708
4796
  case "K":
4709
- key = value.slice(2);
4710
- obj = response._prefix + "_";
4711
- key = obj + key + "_";
4712
- arrayRoot = new FormData();
4713
- for (response = response._formData; ; ) {
4714
- value = response;
4715
- reference = value.keys;
4716
- null === reference &&
4717
- ((reference = value.keys = Array.from(value.data.keys())),
4718
- (value.keyPointer = 0));
4719
- value = reference[value.keyPointer];
4720
- if (void 0 === value) break;
4721
- if (value.startsWith(key)) {
4722
- reference = response.data.getAll(value);
4723
- for (
4724
- var referencedFormDataKey = value.slice(key.length), i = 0;
4725
- i < reference.length;
4726
- i++
4727
- )
4728
- arrayRoot.append(referencedFormDataKey, reference[i]);
4729
- reference = response;
4730
- reference.data.delete(value);
4731
- reference.keyPointer++;
4732
- } else if (value.startsWith(obj)) break;
4733
- else response.keyPointer++;
4797
+ key$jscomp$0 = value.slice(2);
4798
+ obj = response._formData;
4799
+ response = response._prefix + "_" + key$jscomp$0 + "_";
4800
+ key$jscomp$0 = new FormData();
4801
+ arrayRoot = obj.referencedEntries;
4802
+ if (null !== arrayRoot) {
4803
+ for (value = obj.keyPointer; value < arrayRoot.length; ) {
4804
+ reference = arrayRoot[value];
4805
+ var key = reference[0];
4806
+ if (!key.startsWith(response)) break;
4807
+ key$jscomp$0.append(key.slice(response.length), reference[1]);
4808
+ value++;
4809
+ }
4810
+ obj.keyPointer = value;
4734
4811
  }
4735
- return arrayRoot;
4812
+ return key$jscomp$0;
4736
4813
  case "i":
4737
4814
  return (
4738
4815
  (arrayRoot = value.slice(2)),
@@ -4740,7 +4817,7 @@
4740
4817
  response,
4741
4818
  arrayRoot,
4742
4819
  obj,
4743
- key,
4820
+ key$jscomp$0,
4744
4821
  null,
4745
4822
  extractIterator
4746
4823
  )
@@ -4775,7 +4852,7 @@
4775
4852
  ArrayBuffer,
4776
4853
  1,
4777
4854
  obj,
4778
- key,
4855
+ key$jscomp$0,
4779
4856
  arrayRoot
4780
4857
  );
4781
4858
  case "O":
@@ -4785,7 +4862,7 @@
4785
4862
  Int8Array,
4786
4863
  1,
4787
4864
  obj,
4788
- key,
4865
+ key$jscomp$0,
4789
4866
  arrayRoot
4790
4867
  );
4791
4868
  case "o":
@@ -4795,7 +4872,7 @@
4795
4872
  Uint8Array,
4796
4873
  1,
4797
4874
  obj,
4798
- key,
4875
+ key$jscomp$0,
4799
4876
  arrayRoot
4800
4877
  );
4801
4878
  case "U":
@@ -4805,7 +4882,7 @@
4805
4882
  Uint8ClampedArray,
4806
4883
  1,
4807
4884
  obj,
4808
- key,
4885
+ key$jscomp$0,
4809
4886
  arrayRoot
4810
4887
  );
4811
4888
  case "S":
@@ -4815,7 +4892,7 @@
4815
4892
  Int16Array,
4816
4893
  2,
4817
4894
  obj,
4818
- key,
4895
+ key$jscomp$0,
4819
4896
  arrayRoot
4820
4897
  );
4821
4898
  case "s":
@@ -4825,7 +4902,7 @@
4825
4902
  Uint16Array,
4826
4903
  2,
4827
4904
  obj,
4828
- key,
4905
+ key$jscomp$0,
4829
4906
  arrayRoot
4830
4907
  );
4831
4908
  case "L":
@@ -4835,7 +4912,7 @@
4835
4912
  Int32Array,
4836
4913
  4,
4837
4914
  obj,
4838
- key,
4915
+ key$jscomp$0,
4839
4916
  arrayRoot
4840
4917
  );
4841
4918
  case "l":
@@ -4845,7 +4922,7 @@
4845
4922
  Uint32Array,
4846
4923
  4,
4847
4924
  obj,
4848
- key,
4925
+ key$jscomp$0,
4849
4926
  arrayRoot
4850
4927
  );
4851
4928
  case "G":
@@ -4855,7 +4932,7 @@
4855
4932
  Float32Array,
4856
4933
  4,
4857
4934
  obj,
4858
- key,
4935
+ key$jscomp$0,
4859
4936
  arrayRoot
4860
4937
  );
4861
4938
  case "g":
@@ -4865,7 +4942,7 @@
4865
4942
  Float64Array,
4866
4943
  8,
4867
4944
  obj,
4868
- key,
4945
+ key$jscomp$0,
4869
4946
  arrayRoot
4870
4947
  );
4871
4948
  case "M":
@@ -4875,7 +4952,7 @@
4875
4952
  BigInt64Array,
4876
4953
  8,
4877
4954
  obj,
4878
- key,
4955
+ key$jscomp$0,
4879
4956
  arrayRoot
4880
4957
  );
4881
4958
  case "m":
@@ -4885,7 +4962,7 @@
4885
4962
  BigUint64Array,
4886
4963
  8,
4887
4964
  obj,
4888
- key,
4965
+ key$jscomp$0,
4889
4966
  arrayRoot
4890
4967
  );
4891
4968
  case "V":
@@ -4895,13 +4972,13 @@
4895
4972
  DataView,
4896
4973
  1,
4897
4974
  obj,
4898
- key,
4975
+ key$jscomp$0,
4899
4976
  arrayRoot
4900
4977
  );
4901
4978
  case "B":
4902
4979
  return (
4903
4980
  (obj = parseInt(value.slice(2), 16)),
4904
- response._formData.data.get(response._prefix + obj)
4981
+ getBackingBlob(response._formData, response._prefix + obj)
4905
4982
  );
4906
4983
  case "R":
4907
4984
  return parseReadableStream(response, value, void 0);
@@ -4917,7 +4994,7 @@
4917
4994
  response,
4918
4995
  value,
4919
4996
  obj,
4920
- key,
4997
+ key$jscomp$0,
4921
4998
  arrayRoot,
4922
4999
  createModel
4923
5000
  );
@@ -4936,11 +5013,20 @@
4936
5013
  : new FormData(),
4937
5014
  arraySizeLimit =
4938
5015
  4 < arguments.length && void 0 !== arguments[4] ? arguments[4] : 1e6,
4939
- chunks = new Map();
5016
+ chunks = new Map(),
5017
+ backingStore = {
5018
+ prefix: formFieldPrefix,
5019
+ referencedEntries: null,
5020
+ keyPointer: 0,
5021
+ stringChunks: null,
5022
+ streamChunks: null,
5023
+ blobs: null
5024
+ };
5025
+ backingFormData.forEach(appendBackingEntry.bind(null, backingStore));
4940
5026
  return {
4941
5027
  _bundlerConfig: bundlerConfig,
4942
5028
  _prefix: formFieldPrefix,
4943
- _formData: { data: backingFormData, keyPointer: -1, keys: null },
5029
+ _formData: backingStore,
4944
5030
  _chunks: chunks,
4945
5031
  _closed: !1,
4946
5032
  _closedReason: null,
@@ -5087,13 +5173,19 @@
5087
5173
  }
5088
5174
  var ReactDOM = require("react-dom"),
5089
5175
  React = require("react"),
5176
+ hasOwnProperty = Object.prototype.hasOwnProperty,
5090
5177
  channel = new MessageChannel(),
5091
5178
  taskQueue = [];
5092
5179
  channel.port1.onmessage = function () {
5093
5180
  var task = taskQueue.shift();
5094
5181
  task && task();
5095
5182
  };
5096
- var LocalPromise = Promise,
5183
+ var supportsArrayBufferDetached = hasOwnProperty.call(
5184
+ ArrayBuffer.prototype,
5185
+ "detached"
5186
+ ),
5187
+ didWarnAboutMissingArrayBufferDetached = !1,
5188
+ LocalPromise = Promise,
5097
5189
  scheduleMicrotask =
5098
5190
  "function" === typeof queueMicrotask
5099
5191
  ? queueMicrotask
@@ -5483,7 +5575,6 @@
5483
5575
  jsxPropsParents = new WeakMap(),
5484
5576
  jsxChildrenParents = new WeakMap(),
5485
5577
  CLIENT_REFERENCE_TAG = Symbol.for("react.client.reference"),
5486
- hasOwnProperty = Object.prototype.hasOwnProperty,
5487
5578
  doNotLimit = new WeakSet();
5488
5579
  "object" === typeof console &&
5489
5580
  null !== console &&
@@ -5583,44 +5674,44 @@
5583
5674
  };
5584
5675
  exports.decodeAction = function (body, serverManifest) {
5585
5676
  var formData = new FormData(),
5586
- action = null,
5587
- seenActions = new Set();
5677
+ maybeActionKey = null;
5588
5678
  body.forEach(function (value, key) {
5589
5679
  key.startsWith("$ACTION_")
5590
5680
  ? key.startsWith("$ACTION_REF_")
5591
- ? seenActions.has(key) ||
5592
- (seenActions.add(key),
5593
- (value = "$ACTION_" + key.slice(12) + ":"),
5594
- (value = decodeBoundActionMetaData(body, serverManifest, value)),
5595
- (action = loadServerReference(serverManifest, value)))
5596
- : key.startsWith("$ACTION_ID_") &&
5597
- !seenActions.has(key) &&
5598
- (seenActions.add(key),
5599
- (value = key.slice(11)),
5600
- (action = loadServerReference(serverManifest, {
5601
- id: value,
5602
- bound: null
5603
- })))
5681
+ ? (maybeActionKey = key)
5682
+ : key.startsWith("$ACTION_ID_") && (maybeActionKey = key)
5604
5683
  : formData.append(key, value);
5605
5684
  });
5606
- return null === action
5607
- ? null
5608
- : action.then(function (fn) {
5609
- return fn.bind(null, formData);
5610
- });
5685
+ if (null === maybeActionKey) return null;
5686
+ var actionKey = maybeActionKey,
5687
+ action = null;
5688
+ if (actionKey.startsWith("$ACTION_REF_"))
5689
+ (actionKey = "$ACTION_" + actionKey.slice(12) + ":"),
5690
+ (body = decodeBoundActionMetaData(body, serverManifest, actionKey)),
5691
+ (action = loadServerReference(serverManifest, body));
5692
+ else if (actionKey.startsWith("$ACTION_ID_"))
5693
+ (body = actionKey.slice(11)),
5694
+ (action = loadServerReference(serverManifest, {
5695
+ id: body,
5696
+ bound: null
5697
+ }));
5698
+ else throw Error("Cannot handle action key. This is a bug in React.");
5699
+ return action.then(function (fn) {
5700
+ return fn.bind(null, formData);
5701
+ });
5611
5702
  };
5612
5703
  exports.decodeFormState = function (actionResult, body, serverManifest) {
5613
5704
  var keyPath = body.get("$ACTION_KEY");
5614
5705
  if ("string" !== typeof keyPath) return Promise.resolve(null);
5615
- var metaData = null;
5706
+ var actionKey = null;
5616
5707
  body.forEach(function (value, key) {
5617
- key.startsWith("$ACTION_REF_") &&
5618
- ((value = "$ACTION_" + key.slice(12) + ":"),
5619
- (metaData = decodeBoundActionMetaData(body, serverManifest, value)));
5708
+ key.startsWith("$ACTION_REF_") && (actionKey = key);
5620
5709
  });
5621
- if (null === metaData) return Promise.resolve(null);
5622
- var referenceId = metaData.id;
5623
- return Promise.resolve(metaData.bound).then(function (bound) {
5710
+ if (null === actionKey) return Promise.resolve(null);
5711
+ var formFieldPrefix = "$ACTION_" + actionKey.slice(12) + ":";
5712
+ body = decodeBoundActionMetaData(body, serverManifest, formFieldPrefix);
5713
+ var referenceId = body.id;
5714
+ return Promise.resolve(body.bound).then(function (bound) {
5624
5715
  return null === bound
5625
5716
  ? null
5626
5717
  : [actionResult, keyPath, referenceId, bound.length - 1];