react-server-dom-turbopack 19.3.0 → 19.3.1

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.
@@ -32,7 +32,12 @@ function getIteratorFn(maybeIterable) {
32
32
  return "function" === typeof maybeIterable ? maybeIterable : null;
33
33
  }
34
34
  var ASYNC_ITERATOR = Symbol.asyncIterator,
35
- REACT_OPTIMISTIC_KEY = Symbol.for("react.optimistic_key");
35
+ REACT_OPTIMISTIC_KEY = Symbol.for("react.optimistic_key"),
36
+ hasOwnProperty = Object.prototype.hasOwnProperty,
37
+ supportsArrayBufferDetached = hasOwnProperty.call(
38
+ ArrayBuffer.prototype,
39
+ "detached"
40
+ );
36
41
  function handleErrorInNextTick(error) {
37
42
  setTimeout(function () {
38
43
  throw error;
@@ -50,28 +55,30 @@ var LocalPromise = Promise,
50
55
  currentView = null,
51
56
  writtenBytes = 0;
52
57
  function writeChunk(destination, chunk) {
53
- if (0 !== chunk.byteLength)
54
- if (4096 < chunk.byteLength)
55
- 0 < writtenBytes &&
56
- (destination.enqueue(
57
- new Uint8Array(currentView.buffer, 0, writtenBytes)
58
- ),
59
- (currentView = new Uint8Array(4096)),
60
- (writtenBytes = 0)),
61
- destination.enqueue(chunk);
62
- else {
63
- var allowableBytes = currentView.length - writtenBytes;
64
- allowableBytes < chunk.byteLength &&
65
- (0 === allowableBytes
66
- ? destination.enqueue(currentView)
67
- : (currentView.set(chunk.subarray(0, allowableBytes), writtenBytes),
68
- destination.enqueue(currentView),
69
- (chunk = chunk.subarray(allowableBytes))),
70
- (currentView = new Uint8Array(4096)),
71
- (writtenBytes = 0));
72
- currentView.set(chunk, writtenBytes);
73
- writtenBytes += chunk.byteLength;
74
- }
58
+ if (0 === chunk.byteLength) {
59
+ if (supportsArrayBufferDetached && chunk.buffer.detached)
60
+ throw Error(
61
+ "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()`."
62
+ );
63
+ } else if (4096 < chunk.byteLength)
64
+ 0 < writtenBytes &&
65
+ (destination.enqueue(new Uint8Array(currentView.buffer, 0, writtenBytes)),
66
+ (currentView = new Uint8Array(4096)),
67
+ (writtenBytes = 0)),
68
+ destination.enqueue(chunk);
69
+ else {
70
+ var allowableBytes = currentView.length - writtenBytes;
71
+ allowableBytes < chunk.byteLength &&
72
+ (0 === allowableBytes
73
+ ? destination.enqueue(currentView)
74
+ : (currentView.set(chunk.subarray(0, allowableBytes), writtenBytes),
75
+ destination.enqueue(currentView),
76
+ (chunk = chunk.subarray(allowableBytes))),
77
+ (currentView = new Uint8Array(4096)),
78
+ (writtenBytes = 0));
79
+ currentView.set(chunk, writtenBytes);
80
+ writtenBytes += chunk.byteLength;
81
+ }
75
82
  }
76
83
  function writeChunkAndReturn(destination, chunk) {
77
84
  writeChunk(destination, chunk);
@@ -821,8 +828,7 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
821
828
  "\n " + str + "\n " + objectOrArray)
822
829
  : "\n " + str;
823
830
  }
824
- var hasOwnProperty = Object.prototype.hasOwnProperty,
825
- ObjectPrototype$1 = Object.prototype,
831
+ var ObjectPrototype$1 = Object.prototype,
826
832
  stringify = JSON.stringify,
827
833
  NEXT_TWO_CHUNKS_ARE_ATOMIC = Symbol();
828
834
  function defaultErrorHandler(error) {
@@ -2058,11 +2064,28 @@ function emitModelChunk(request, id, json) {
2058
2064
  }
2059
2065
  function emitTypedArrayChunk(request, id, tag, typedArray, debug) {
2060
2066
  debug ? request.pendingDebugChunks++ : request.pendingChunks++;
2061
- typedArray = new Uint8Array(
2062
- typedArray.buffer,
2063
- typedArray.byteOffset,
2064
- typedArray.byteLength
2065
- );
2067
+ a: {
2068
+ debug = new Uint8Array(
2069
+ typedArray.buffer,
2070
+ typedArray.byteOffset,
2071
+ typedArray.byteLength
2072
+ );
2073
+ if (4096 < typedArray.byteLength) {
2074
+ if (
2075
+ 0 !== typedArray.byteOffset ||
2076
+ typedArray.byteLength !== typedArray.buffer.byteLength ||
2077
+ typedArray.buffer.resizable
2078
+ ) {
2079
+ typedArray = debug.slice();
2080
+ break a;
2081
+ }
2082
+ if (!supportsArrayBufferDetached) {
2083
+ typedArray = debug.slice();
2084
+ break a;
2085
+ }
2086
+ }
2087
+ typedArray = debug;
2088
+ }
2066
2089
  debug = typedArray.byteLength;
2067
2090
  id = id.toString(16) + ":" + tag + debug.toString(16) + ",";
2068
2091
  id = stringToChunk(id);
@@ -2498,13 +2521,37 @@ function requireModule(metadata) {
2498
2521
  if (hasOwnProperty.call(moduleExports, metadata[2]))
2499
2522
  return moduleExports[metadata[2]];
2500
2523
  }
2501
- function appendBackingEntry(backingStore, key, value) {
2502
- backingStore.data.append(key, value);
2503
- value = backingStore.keys;
2504
- null === value
2505
- ? ((backingStore.keys = Array.from(backingStore.data.keys())),
2506
- (backingStore.keyPointer = 0))
2507
- : value.push(key);
2524
+ function appendBackingEntry(backingStore, value, key) {
2525
+ var prefix = backingStore.prefix;
2526
+ if (key.startsWith(prefix)) {
2527
+ switch (key[prefix.length]) {
2528
+ case "_":
2529
+ prefix = backingStore.referencedEntries;
2530
+ null === prefix && (prefix = backingStore.referencedEntries = []);
2531
+ prefix.push([key, value]);
2532
+ return;
2533
+ case "S":
2534
+ "string" === typeof value &&
2535
+ ((prefix = backingStore.streamChunks),
2536
+ null === prefix && (prefix = backingStore.streamChunks = new Map()),
2537
+ (backingStore = prefix.get(key)),
2538
+ void 0 === backingStore
2539
+ ? prefix.set(key, [value])
2540
+ : backingStore.push(value));
2541
+ return;
2542
+ }
2543
+ "string" === typeof value
2544
+ ? ((prefix = backingStore.stringChunks),
2545
+ null === prefix && (prefix = backingStore.stringChunks = new Map()),
2546
+ prefix.set(key, value))
2547
+ : ((prefix = backingStore.blobs),
2548
+ null === prefix && (prefix = backingStore.blobs = new Map()),
2549
+ prefix.set(key, value));
2550
+ }
2551
+ }
2552
+ function getBackingBlob(backingStore, key) {
2553
+ backingStore = backingStore.blobs;
2554
+ return null === backingStore ? void 0 : backingStore.get(key);
2508
2555
  }
2509
2556
  var RESPONSE_SYMBOL = Symbol();
2510
2557
  function ReactPromise(status, value, reason) {
@@ -2885,15 +2932,18 @@ function reportGlobalError(response, error) {
2885
2932
  function getChunk(response, id) {
2886
2933
  var chunks = response._chunks,
2887
2934
  chunk = chunks.get(id);
2888
- chunk ||
2889
- ((chunk = response._formData.data.get(response._prefix + id)),
2890
- (chunk =
2935
+ if (!chunk) {
2936
+ chunk = response._prefix;
2937
+ var stringChunks = response._formData.stringChunks;
2938
+ chunk = null === stringChunks ? void 0 : stringChunks.get(chunk + id);
2939
+ chunk =
2891
2940
  "string" === typeof chunk
2892
2941
  ? createResolvedModelChunk(response, chunk, id)
2893
2942
  : response._closed
2894
2943
  ? new ReactPromise("rejected", null, response._closedReason)
2895
- : new ReactPromise("pending", null, null)),
2896
- chunks.set(id, chunk));
2944
+ : new ReactPromise("pending", null, null);
2945
+ chunks.set(id, chunk);
2946
+ }
2897
2947
  return chunk;
2898
2948
  }
2899
2949
  function fulfillReference(response, reference, value, arrayRoot) {
@@ -3124,7 +3174,7 @@ function parseTypedArray(
3124
3174
  Error("Already initialized typed array.")
3125
3175
  )
3126
3176
  );
3127
- reference = response._formData.data.get(key).arrayBuffer();
3177
+ reference = getBackingBlob(response._formData, key).arrayBuffer();
3128
3178
  if (initializingHandler) {
3129
3179
  var handler = initializingHandler;
3130
3180
  handler.deps++;
@@ -3168,13 +3218,15 @@ function resolveStream(response, id, stream, controller) {
3168
3218
  var chunks = response._chunks;
3169
3219
  stream = new ReactPromise("fulfilled", stream, controller);
3170
3220
  chunks.set(id, stream);
3171
- response = response._formData.data.getAll(response._prefix + id);
3172
- for (id = 0; id < response.length; id++)
3173
- (chunks = response[id]),
3174
- "string" === typeof chunks &&
3175
- ("C" === chunks[0]
3221
+ chunks = response._prefix;
3222
+ response = response._formData.streamChunks;
3223
+ id = null === response ? void 0 : response.get(chunks + "S" + id);
3224
+ if (void 0 !== id)
3225
+ for (response = 0; response < id.length; response++)
3226
+ (chunks = id[response]),
3227
+ "C" === chunks[0]
3176
3228
  ? controller.close("C" === chunks ? '"$undefined"' : chunks.slice(1))
3177
- : controller.enqueueModel(chunks));
3229
+ : controller.enqueueModel(chunks);
3178
3230
  }
3179
3231
  function parseReadableStream(response, reference, type) {
3180
3232
  function enqueue(value) {
@@ -3340,7 +3392,14 @@ function parseAsyncIterable(response, reference, iterator) {
3340
3392
  });
3341
3393
  return iterator;
3342
3394
  }
3343
- function parseModelString(response, obj, key, value, reference, arrayRoot) {
3395
+ function parseModelString(
3396
+ response,
3397
+ obj,
3398
+ key$jscomp$0,
3399
+ value,
3400
+ reference,
3401
+ arrayRoot
3402
+ ) {
3344
3403
  if ("$" === value[0]) {
3345
3404
  switch (value[1]) {
3346
3405
  case "$":
@@ -3358,7 +3417,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3358
3417
  response,
3359
3418
  arrayRoot,
3360
3419
  obj,
3361
- key,
3420
+ key$jscomp$0,
3362
3421
  null,
3363
3422
  loadServerReference$1
3364
3423
  )
@@ -3375,43 +3434,55 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3375
3434
  case "Q":
3376
3435
  return (
3377
3436
  (arrayRoot = value.slice(2)),
3378
- getOutlinedModel(response, arrayRoot, obj, key, null, createMap)
3437
+ getOutlinedModel(
3438
+ response,
3439
+ arrayRoot,
3440
+ obj,
3441
+ key$jscomp$0,
3442
+ null,
3443
+ createMap
3444
+ )
3379
3445
  );
3380
3446
  case "W":
3381
3447
  return (
3382
3448
  (arrayRoot = value.slice(2)),
3383
- getOutlinedModel(response, arrayRoot, obj, key, null, createSet)
3449
+ getOutlinedModel(
3450
+ response,
3451
+ arrayRoot,
3452
+ obj,
3453
+ key$jscomp$0,
3454
+ null,
3455
+ createSet
3456
+ )
3384
3457
  );
3385
3458
  case "K":
3386
- key = value.slice(2);
3387
- obj = response._prefix + "_";
3388
- key = obj + key + "_";
3389
- arrayRoot = new FormData();
3390
- for (response = response._formData; ; ) {
3391
- value = response.keys;
3392
- null === value &&
3393
- ((value = response.keys = Array.from(response.data.keys())),
3394
- (response.keyPointer = 0));
3395
- value = value[response.keyPointer];
3396
- if (void 0 === value) break;
3397
- if (value.startsWith(key)) {
3398
- reference = response.data.getAll(value);
3399
- for (
3400
- var referencedFormDataKey = value.slice(key.length), i = 0;
3401
- i < reference.length;
3402
- i++
3403
- )
3404
- arrayRoot.append(referencedFormDataKey, reference[i]);
3405
- response.data.delete(value);
3406
- response.keyPointer++;
3407
- } else if (value.startsWith(obj)) break;
3408
- else response.keyPointer++;
3459
+ obj = value.slice(2);
3460
+ obj = response._prefix + "_" + obj + "_";
3461
+ response = response._formData;
3462
+ key$jscomp$0 = new FormData();
3463
+ arrayRoot = response.referencedEntries;
3464
+ if (null !== arrayRoot) {
3465
+ for (value = response.keyPointer; value < arrayRoot.length; ) {
3466
+ reference = arrayRoot[value];
3467
+ var key = reference[0];
3468
+ if (!key.startsWith(obj)) break;
3469
+ key$jscomp$0.append(key.slice(obj.length), reference[1]);
3470
+ value++;
3471
+ }
3472
+ response.keyPointer = value;
3409
3473
  }
3410
- return arrayRoot;
3474
+ return key$jscomp$0;
3411
3475
  case "i":
3412
3476
  return (
3413
3477
  (arrayRoot = value.slice(2)),
3414
- getOutlinedModel(response, arrayRoot, obj, key, null, extractIterator)
3478
+ getOutlinedModel(
3479
+ response,
3480
+ arrayRoot,
3481
+ obj,
3482
+ key$jscomp$0,
3483
+ null,
3484
+ extractIterator
3485
+ )
3415
3486
  );
3416
3487
  case "I":
3417
3488
  return Infinity;
@@ -3440,7 +3511,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3440
3511
  ArrayBuffer,
3441
3512
  1,
3442
3513
  obj,
3443
- key,
3514
+ key$jscomp$0,
3444
3515
  arrayRoot
3445
3516
  );
3446
3517
  case "O":
@@ -3450,7 +3521,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3450
3521
  Int8Array,
3451
3522
  1,
3452
3523
  obj,
3453
- key,
3524
+ key$jscomp$0,
3454
3525
  arrayRoot
3455
3526
  );
3456
3527
  case "o":
@@ -3460,7 +3531,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3460
3531
  Uint8Array,
3461
3532
  1,
3462
3533
  obj,
3463
- key,
3534
+ key$jscomp$0,
3464
3535
  arrayRoot
3465
3536
  );
3466
3537
  case "U":
@@ -3470,7 +3541,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3470
3541
  Uint8ClampedArray,
3471
3542
  1,
3472
3543
  obj,
3473
- key,
3544
+ key$jscomp$0,
3474
3545
  arrayRoot
3475
3546
  );
3476
3547
  case "S":
@@ -3480,7 +3551,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3480
3551
  Int16Array,
3481
3552
  2,
3482
3553
  obj,
3483
- key,
3554
+ key$jscomp$0,
3484
3555
  arrayRoot
3485
3556
  );
3486
3557
  case "s":
@@ -3490,7 +3561,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3490
3561
  Uint16Array,
3491
3562
  2,
3492
3563
  obj,
3493
- key,
3564
+ key$jscomp$0,
3494
3565
  arrayRoot
3495
3566
  );
3496
3567
  case "L":
@@ -3500,7 +3571,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3500
3571
  Int32Array,
3501
3572
  4,
3502
3573
  obj,
3503
- key,
3574
+ key$jscomp$0,
3504
3575
  arrayRoot
3505
3576
  );
3506
3577
  case "l":
@@ -3510,7 +3581,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3510
3581
  Uint32Array,
3511
3582
  4,
3512
3583
  obj,
3513
- key,
3584
+ key$jscomp$0,
3514
3585
  arrayRoot
3515
3586
  );
3516
3587
  case "G":
@@ -3520,7 +3591,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3520
3591
  Float32Array,
3521
3592
  4,
3522
3593
  obj,
3523
- key,
3594
+ key$jscomp$0,
3524
3595
  arrayRoot
3525
3596
  );
3526
3597
  case "g":
@@ -3530,7 +3601,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3530
3601
  Float64Array,
3531
3602
  8,
3532
3603
  obj,
3533
- key,
3604
+ key$jscomp$0,
3534
3605
  arrayRoot
3535
3606
  );
3536
3607
  case "M":
@@ -3540,7 +3611,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3540
3611
  BigInt64Array,
3541
3612
  8,
3542
3613
  obj,
3543
- key,
3614
+ key$jscomp$0,
3544
3615
  arrayRoot
3545
3616
  );
3546
3617
  case "m":
@@ -3550,7 +3621,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3550
3621
  BigUint64Array,
3551
3622
  8,
3552
3623
  obj,
3553
- key,
3624
+ key$jscomp$0,
3554
3625
  arrayRoot
3555
3626
  );
3556
3627
  case "V":
@@ -3560,12 +3631,12 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3560
3631
  DataView,
3561
3632
  1,
3562
3633
  obj,
3563
- key,
3634
+ key$jscomp$0,
3564
3635
  arrayRoot
3565
3636
  );
3566
3637
  case "B":
3567
3638
  obj = parseInt(value.slice(2), 16);
3568
- response = response._formData.data.get(response._prefix + obj);
3639
+ response = getBackingBlob(response._formData, response._prefix + obj);
3569
3640
  if (!(response instanceof Blob))
3570
3641
  throw Error("Referenced Blob is not a Blob.");
3571
3642
  return response;
@@ -3579,7 +3650,14 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3579
3650
  return parseAsyncIterable(response, value, !0);
3580
3651
  }
3581
3652
  value = value.slice(1);
3582
- return getOutlinedModel(response, value, obj, key, arrayRoot, createModel);
3653
+ return getOutlinedModel(
3654
+ response,
3655
+ value,
3656
+ obj,
3657
+ key$jscomp$0,
3658
+ arrayRoot,
3659
+ createModel
3660
+ );
3583
3661
  }
3584
3662
  null !== arrayRoot && bumpArrayCount(arrayRoot, value.length, response);
3585
3663
  return value;
@@ -3591,11 +3669,20 @@ function createResponse(bundlerConfig, formFieldPrefix, temporaryReferences) {
3591
3669
  : new FormData(),
3592
3670
  arraySizeLimit =
3593
3671
  4 < arguments.length && void 0 !== arguments[4] ? arguments[4] : 1e6,
3594
- chunks = new Map();
3672
+ chunks = new Map(),
3673
+ backingStore = {
3674
+ prefix: formFieldPrefix,
3675
+ referencedEntries: null,
3676
+ keyPointer: 0,
3677
+ stringChunks: null,
3678
+ streamChunks: null,
3679
+ blobs: null
3680
+ };
3681
+ backingFormData.forEach(appendBackingEntry.bind(null, backingStore));
3595
3682
  return {
3596
3683
  _bundlerConfig: bundlerConfig,
3597
3684
  _prefix: formFieldPrefix,
3598
- _formData: { data: backingFormData, keyPointer: -1, keys: null },
3685
+ _formData: backingStore,
3599
3686
  _chunks: chunks,
3600
3687
  _closed: !1,
3601
3688
  _closedReason: null,
@@ -3724,19 +3811,34 @@ exports.decodeReplyFromAsyncIterable = function (
3724
3811
  function progress(entry) {
3725
3812
  if (entry.done) close(response);
3726
3813
  else {
3727
- entry = entry.value;
3728
- var name = entry[0];
3729
- entry = entry[1];
3730
- if ("string" === typeof entry) {
3731
- appendBackingEntry(response._formData, name, entry);
3732
- var prefix = response._prefix;
3733
- if (name.startsWith(prefix)) {
3734
- var chunks = response._chunks;
3735
- name = +name.slice(prefix.length);
3736
- (chunks = chunks.get(name)) &&
3737
- resolveModelChunk(response, chunks, entry, name);
3814
+ var _entry$value = entry.value;
3815
+ entry = _entry$value[0];
3816
+ _entry$value = _entry$value[1];
3817
+ if ("string" === typeof _entry$value)
3818
+ a: {
3819
+ var prefix = response._prefix;
3820
+ if (entry.startsWith(prefix)) {
3821
+ var chunks = response._chunks;
3822
+ if ("S" === entry[prefix.length]) {
3823
+ if (
3824
+ entry.length > prefix.length + 1 &&
3825
+ ((prefix = +entry.slice(prefix.length + 1)),
3826
+ (chunks = chunks.get(prefix)))
3827
+ ) {
3828
+ resolveModelChunk(response, chunks, _entry$value, prefix);
3829
+ break a;
3830
+ }
3831
+ } else if (
3832
+ ((prefix = +entry.slice(prefix.length)),
3833
+ (chunks = chunks.get(prefix)))
3834
+ ) {
3835
+ resolveModelChunk(response, chunks, _entry$value, prefix);
3836
+ break a;
3837
+ }
3838
+ }
3839
+ appendBackingEntry(response._formData, _entry$value, entry);
3738
3840
  }
3739
- } else appendBackingEntry(response._formData, name, entry);
3841
+ else appendBackingEntry(response._formData, _entry$value, entry);
3740
3842
  iterator.next().then(progress, error);
3741
3843
  }
3742
3844
  }