react-server-dom-turbopack 19.0.7 → 19.0.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.
@@ -29,31 +29,39 @@
29
29
  });
30
30
  }
31
31
  function writeChunkAndReturn(destination, chunk) {
32
- if (0 !== chunk.byteLength)
33
- if (2048 < chunk.byteLength)
34
- 0 < writtenBytes &&
35
- (destination.enqueue(
36
- new Uint8Array(currentView.buffer, 0, writtenBytes)
32
+ if (0 === chunk.byteLength)
33
+ if (supportsArrayBufferDetached) {
34
+ if (chunk.buffer.detached)
35
+ throw Error(
36
+ "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()`."
37
+ );
38
+ } else
39
+ didWarnAboutMissingArrayBufferDetached ||
40
+ (console.error(
41
+ "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 Edge runtime that supports ArrayBuffer.prototype.detached."
37
42
  ),
38
- (currentView = new Uint8Array(2048)),
39
- (writtenBytes = 0)),
40
- destination.enqueue(chunk);
41
- else {
42
- var allowableBytes = currentView.length - writtenBytes;
43
- allowableBytes < chunk.byteLength &&
44
- (0 === allowableBytes
45
- ? destination.enqueue(currentView)
46
- : (currentView.set(
47
- chunk.subarray(0, allowableBytes),
48
- writtenBytes
49
- ),
50
- destination.enqueue(currentView),
51
- (chunk = chunk.subarray(allowableBytes))),
52
- (currentView = new Uint8Array(2048)),
53
- (writtenBytes = 0));
54
- currentView.set(chunk, writtenBytes);
55
- writtenBytes += chunk.byteLength;
56
- }
43
+ (didWarnAboutMissingArrayBufferDetached = !0));
44
+ else if (2048 < chunk.byteLength)
45
+ 0 < writtenBytes &&
46
+ (destination.enqueue(
47
+ new Uint8Array(currentView.buffer, 0, writtenBytes)
48
+ ),
49
+ (currentView = new Uint8Array(2048)),
50
+ (writtenBytes = 0)),
51
+ destination.enqueue(chunk);
52
+ else {
53
+ var allowableBytes = currentView.length - writtenBytes;
54
+ allowableBytes < chunk.byteLength &&
55
+ (0 === allowableBytes
56
+ ? destination.enqueue(currentView)
57
+ : (currentView.set(chunk.subarray(0, allowableBytes), writtenBytes),
58
+ destination.enqueue(currentView),
59
+ (chunk = chunk.subarray(allowableBytes))),
60
+ (currentView = new Uint8Array(2048)),
61
+ (writtenBytes = 0));
62
+ currentView.set(chunk, writtenBytes);
63
+ writtenBytes += chunk.byteLength;
64
+ }
57
65
  return !0;
58
66
  }
59
67
  function stringToChunk(content) {
@@ -833,7 +841,7 @@
833
841
  emitErrorChunk(request, streamTask.id, digest, reason);
834
842
  enqueueFlush(request);
835
843
  "function" === typeof iterator.throw &&
836
- iterator.throw(reason).then(error, error);
844
+ iterator.throw(reason).then(noop, noop);
837
845
  }
838
846
  }
839
847
  function abortIterable(reason) {
@@ -844,7 +852,7 @@
844
852
  emitErrorChunk(request, streamTask.id, digest, reason);
845
853
  enqueueFlush(request);
846
854
  "function" === typeof iterator.throw &&
847
- iterator.throw(reason).then(error, error);
855
+ iterator.throw(reason).then(noop, noop);
848
856
  }
849
857
  }
850
858
  var isIterator = iterable === iterator,
@@ -1914,14 +1922,35 @@
1914
1922
  }
1915
1923
  function emitTypedArrayChunk(request, id, tag, typedArray) {
1916
1924
  request.pendingChunks++;
1917
- var buffer = new Uint8Array(
1918
- typedArray.buffer,
1919
- typedArray.byteOffset,
1920
- typedArray.byteLength
1921
- );
1922
- typedArray = 2048 < typedArray.byteLength ? buffer.slice() : buffer;
1923
- buffer = typedArray.byteLength;
1924
- id = id.toString(16) + ":" + tag + buffer.toString(16) + ",";
1925
+ a: {
1926
+ var view = new Uint8Array(
1927
+ typedArray.buffer,
1928
+ typedArray.byteOffset,
1929
+ typedArray.byteLength
1930
+ );
1931
+ if (2048 < typedArray.byteLength) {
1932
+ if (
1933
+ 0 !== typedArray.byteOffset ||
1934
+ typedArray.byteLength !== typedArray.buffer.byteLength ||
1935
+ typedArray.buffer.resizable
1936
+ ) {
1937
+ typedArray = view.slice();
1938
+ break a;
1939
+ }
1940
+ if (!supportsArrayBufferDetached) {
1941
+ didWarnAboutMissingArrayBufferDetached ||
1942
+ (console.error(
1943
+ "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 upgrade to a modern Edge runtime."
1944
+ ),
1945
+ (didWarnAboutMissingArrayBufferDetached = !0));
1946
+ typedArray = view.slice();
1947
+ break a;
1948
+ }
1949
+ }
1950
+ typedArray = view;
1951
+ }
1952
+ view = typedArray.byteLength;
1953
+ id = id.toString(16) + ":" + tag + view.toString(16) + ",";
1925
1954
  id = stringToChunk(id);
1926
1955
  request.completedRegularChunks.push(id, typedArray);
1927
1956
  }
@@ -2548,6 +2577,39 @@
2548
2577
  if (hasOwnProperty.call(moduleExports, metadata[2]))
2549
2578
  return moduleExports[metadata[2]];
2550
2579
  }
2580
+ function appendBackingEntry(backingStore, value, key) {
2581
+ var prefix = backingStore.prefix;
2582
+ if (key.startsWith(prefix)) {
2583
+ switch (key[prefix.length]) {
2584
+ case "_":
2585
+ prefix = backingStore.referencedEntries;
2586
+ null === prefix && (prefix = backingStore.referencedEntries = []);
2587
+ prefix.push([key, value]);
2588
+ return;
2589
+ case "S":
2590
+ "string" === typeof value &&
2591
+ ((prefix = backingStore.streamChunks),
2592
+ null === prefix &&
2593
+ (prefix = backingStore.streamChunks = new Map()),
2594
+ (backingStore = prefix.get(key)),
2595
+ void 0 === backingStore
2596
+ ? prefix.set(key, [value])
2597
+ : backingStore.push(value));
2598
+ return;
2599
+ }
2600
+ "string" === typeof value
2601
+ ? ((prefix = backingStore.stringChunks),
2602
+ null === prefix && (prefix = backingStore.stringChunks = new Map()),
2603
+ prefix.set(key, value))
2604
+ : ((prefix = backingStore.blobs),
2605
+ null === prefix && (prefix = backingStore.blobs = new Map()),
2606
+ prefix.set(key, value));
2607
+ }
2608
+ }
2609
+ function getBackingBlob(backingStore, key) {
2610
+ backingStore = backingStore.blobs;
2611
+ return null === backingStore ? void 0 : backingStore.get(key);
2612
+ }
2551
2613
  function ReactPromise(status, value, reason) {
2552
2614
  this.status = status;
2553
2615
  this.value = value;
@@ -2857,17 +2919,20 @@
2857
2919
  function getChunk(response, id) {
2858
2920
  var chunks = response._chunks,
2859
2921
  chunk = chunks.get(id);
2860
- chunk ||
2861
- ((chunk = response._formData.data.get(response._prefix + id)),
2862
- (chunk =
2922
+ if (!chunk) {
2923
+ chunk = response._prefix;
2924
+ var stringChunks = response._formData.stringChunks;
2925
+ chunk = null === stringChunks ? void 0 : stringChunks.get(chunk + id);
2926
+ chunk =
2863
2927
  "string" === typeof chunk
2864
2928
  ? new ReactPromise(
2865
2929
  "resolved_model",
2866
2930
  chunk,
2867
2931
  _defineProperty({ id: id }, RESPONSE_SYMBOL, response)
2868
2932
  )
2869
- : new ReactPromise("pending", null, null)),
2870
- chunks.set(id, chunk));
2933
+ : new ReactPromise("pending", null, null);
2934
+ chunks.set(id, chunk);
2935
+ }
2871
2936
  return chunk;
2872
2937
  }
2873
2938
  function fulfillReference(response, reference, value, arrayRoot) {
@@ -3114,7 +3179,7 @@
3114
3179
  Error("Already initialized typed array.")
3115
3180
  )
3116
3181
  );
3117
- reference = response._formData.data.get(key).arrayBuffer();
3182
+ reference = getBackingBlob(response._formData, key).arrayBuffer();
3118
3183
  if (initializingHandler) {
3119
3184
  var handler = initializingHandler;
3120
3185
  handler.deps++;
@@ -3158,15 +3223,17 @@
3158
3223
  var chunks = response._chunks;
3159
3224
  stream = new ReactPromise("fulfilled", stream, controller);
3160
3225
  chunks.set(id, stream);
3161
- response = response._formData.data.getAll(response._prefix + id);
3162
- for (id = 0; id < response.length; id++)
3163
- (chunks = response[id]),
3164
- "string" === typeof chunks &&
3165
- ("C" === chunks[0]
3226
+ chunks = response._prefix;
3227
+ response = response._formData.streamChunks;
3228
+ id = null === response ? void 0 : response.get(chunks + "S" + id);
3229
+ if (void 0 !== id)
3230
+ for (response = 0; response < id.length; response++)
3231
+ (chunks = id[response]),
3232
+ "C" === chunks[0]
3166
3233
  ? controller.close(
3167
3234
  "C" === chunks ? '"$undefined"' : chunks.slice(1)
3168
3235
  )
3169
- : controller.enqueueModel(chunks));
3236
+ : controller.enqueueModel(chunks);
3170
3237
  }
3171
3238
  function parseReadableStream(response, reference, type) {
3172
3239
  function enqueue(value) {
@@ -3330,7 +3397,14 @@
3330
3397
  });
3331
3398
  return iterator;
3332
3399
  }
3333
- function parseModelString(response, obj, key, value, reference, arrayRoot) {
3400
+ function parseModelString(
3401
+ response,
3402
+ obj,
3403
+ key$jscomp$0,
3404
+ value,
3405
+ reference,
3406
+ arrayRoot
3407
+ ) {
3334
3408
  if ("$" === value[0]) {
3335
3409
  switch (value[1]) {
3336
3410
  case "$":
@@ -3350,7 +3424,7 @@
3350
3424
  response,
3351
3425
  arrayRoot,
3352
3426
  obj,
3353
- key,
3427
+ key$jscomp$0,
3354
3428
  null,
3355
3429
  loadServerReference$1
3356
3430
  )
@@ -3370,41 +3444,44 @@
3370
3444
  case "Q":
3371
3445
  return (
3372
3446
  (arrayRoot = value.slice(2)),
3373
- getOutlinedModel(response, arrayRoot, obj, key, null, createMap)
3447
+ getOutlinedModel(
3448
+ response,
3449
+ arrayRoot,
3450
+ obj,
3451
+ key$jscomp$0,
3452
+ null,
3453
+ createMap
3454
+ )
3374
3455
  );
3375
3456
  case "W":
3376
3457
  return (
3377
3458
  (arrayRoot = value.slice(2)),
3378
- getOutlinedModel(response, arrayRoot, obj, key, null, createSet)
3459
+ getOutlinedModel(
3460
+ response,
3461
+ arrayRoot,
3462
+ obj,
3463
+ key$jscomp$0,
3464
+ null,
3465
+ createSet
3466
+ )
3379
3467
  );
3380
3468
  case "K":
3381
- key = value.slice(2);
3382
- obj = response._prefix + "_";
3383
- key = obj + key + "_";
3384
- arrayRoot = new FormData();
3385
- for (response = response._formData; ; ) {
3386
- value = response;
3387
- reference = value.keys;
3388
- null === reference &&
3389
- ((reference = value.keys = Array.from(value.data.keys())),
3390
- (value.keyPointer = 0));
3391
- value = reference[value.keyPointer];
3392
- if (void 0 === value) break;
3393
- if (value.startsWith(key)) {
3394
- reference = response.data.getAll(value);
3395
- for (
3396
- var referencedFormDataKey = value.slice(key.length), i = 0;
3397
- i < reference.length;
3398
- i++
3399
- )
3400
- arrayRoot.append(referencedFormDataKey, reference[i]);
3401
- reference = response;
3402
- reference.data.delete(value);
3403
- reference.keyPointer++;
3404
- } else if (value.startsWith(obj)) break;
3405
- else response.keyPointer++;
3469
+ key$jscomp$0 = value.slice(2);
3470
+ obj = response._formData;
3471
+ response = response._prefix + "_" + key$jscomp$0 + "_";
3472
+ key$jscomp$0 = new FormData();
3473
+ arrayRoot = obj.referencedEntries;
3474
+ if (null !== arrayRoot) {
3475
+ for (value = obj.keyPointer; value < arrayRoot.length; ) {
3476
+ reference = arrayRoot[value];
3477
+ var key = reference[0];
3478
+ if (!key.startsWith(response)) break;
3479
+ key$jscomp$0.append(key.slice(response.length), reference[1]);
3480
+ value++;
3481
+ }
3482
+ obj.keyPointer = value;
3406
3483
  }
3407
- return arrayRoot;
3484
+ return key$jscomp$0;
3408
3485
  case "i":
3409
3486
  return (
3410
3487
  (arrayRoot = value.slice(2)),
@@ -3412,7 +3489,7 @@
3412
3489
  response,
3413
3490
  arrayRoot,
3414
3491
  obj,
3415
- key,
3492
+ key$jscomp$0,
3416
3493
  null,
3417
3494
  extractIterator
3418
3495
  )
@@ -3449,7 +3526,7 @@
3449
3526
  ArrayBuffer,
3450
3527
  1,
3451
3528
  obj,
3452
- key,
3529
+ key$jscomp$0,
3453
3530
  arrayRoot
3454
3531
  );
3455
3532
  case "O":
@@ -3459,7 +3536,7 @@
3459
3536
  Int8Array,
3460
3537
  1,
3461
3538
  obj,
3462
- key,
3539
+ key$jscomp$0,
3463
3540
  arrayRoot
3464
3541
  );
3465
3542
  case "o":
@@ -3469,7 +3546,7 @@
3469
3546
  Uint8Array,
3470
3547
  1,
3471
3548
  obj,
3472
- key,
3549
+ key$jscomp$0,
3473
3550
  arrayRoot
3474
3551
  );
3475
3552
  case "U":
@@ -3479,7 +3556,7 @@
3479
3556
  Uint8ClampedArray,
3480
3557
  1,
3481
3558
  obj,
3482
- key,
3559
+ key$jscomp$0,
3483
3560
  arrayRoot
3484
3561
  );
3485
3562
  case "S":
@@ -3489,7 +3566,7 @@
3489
3566
  Int16Array,
3490
3567
  2,
3491
3568
  obj,
3492
- key,
3569
+ key$jscomp$0,
3493
3570
  arrayRoot
3494
3571
  );
3495
3572
  case "s":
@@ -3499,7 +3576,7 @@
3499
3576
  Uint16Array,
3500
3577
  2,
3501
3578
  obj,
3502
- key,
3579
+ key$jscomp$0,
3503
3580
  arrayRoot
3504
3581
  );
3505
3582
  case "L":
@@ -3509,7 +3586,7 @@
3509
3586
  Int32Array,
3510
3587
  4,
3511
3588
  obj,
3512
- key,
3589
+ key$jscomp$0,
3513
3590
  arrayRoot
3514
3591
  );
3515
3592
  case "l":
@@ -3519,7 +3596,7 @@
3519
3596
  Uint32Array,
3520
3597
  4,
3521
3598
  obj,
3522
- key,
3599
+ key$jscomp$0,
3523
3600
  arrayRoot
3524
3601
  );
3525
3602
  case "G":
@@ -3529,7 +3606,7 @@
3529
3606
  Float32Array,
3530
3607
  4,
3531
3608
  obj,
3532
- key,
3609
+ key$jscomp$0,
3533
3610
  arrayRoot
3534
3611
  );
3535
3612
  case "g":
@@ -3539,7 +3616,7 @@
3539
3616
  Float64Array,
3540
3617
  8,
3541
3618
  obj,
3542
- key,
3619
+ key$jscomp$0,
3543
3620
  arrayRoot
3544
3621
  );
3545
3622
  case "M":
@@ -3549,7 +3626,7 @@
3549
3626
  BigInt64Array,
3550
3627
  8,
3551
3628
  obj,
3552
- key,
3629
+ key$jscomp$0,
3553
3630
  arrayRoot
3554
3631
  );
3555
3632
  case "m":
@@ -3559,7 +3636,7 @@
3559
3636
  BigUint64Array,
3560
3637
  8,
3561
3638
  obj,
3562
- key,
3639
+ key$jscomp$0,
3563
3640
  arrayRoot
3564
3641
  );
3565
3642
  case "V":
@@ -3569,13 +3646,13 @@
3569
3646
  DataView,
3570
3647
  1,
3571
3648
  obj,
3572
- key,
3649
+ key$jscomp$0,
3573
3650
  arrayRoot
3574
3651
  );
3575
3652
  case "B":
3576
3653
  return (
3577
3654
  (obj = parseInt(value.slice(2), 16)),
3578
- response._formData.data.get(response._prefix + obj)
3655
+ getBackingBlob(response._formData, response._prefix + obj)
3579
3656
  );
3580
3657
  }
3581
3658
  switch (value[1]) {
@@ -3593,7 +3670,7 @@
3593
3670
  response,
3594
3671
  value,
3595
3672
  obj,
3596
- key,
3673
+ key$jscomp$0,
3597
3674
  arrayRoot,
3598
3675
  createModel
3599
3676
  );
@@ -3612,11 +3689,20 @@
3612
3689
  : new FormData(),
3613
3690
  arraySizeLimit =
3614
3691
  4 < arguments.length && void 0 !== arguments[4] ? arguments[4] : 1e6,
3615
- chunks = new Map();
3692
+ chunks = new Map(),
3693
+ backingStore = {
3694
+ prefix: formFieldPrefix,
3695
+ referencedEntries: null,
3696
+ keyPointer: 0,
3697
+ stringChunks: null,
3698
+ streamChunks: null,
3699
+ blobs: null
3700
+ };
3701
+ backingFormData.forEach(appendBackingEntry.bind(null, backingStore));
3616
3702
  return {
3617
3703
  _bundlerConfig: bundlerConfig,
3618
3704
  _prefix: formFieldPrefix,
3619
- _formData: { data: backingFormData, keyPointer: -1, keys: null },
3705
+ _formData: backingStore,
3620
3706
  _chunks: chunks,
3621
3707
  _temporaryReferences: temporaryReferences,
3622
3708
  _rootArrayContexts: new WeakMap(),
@@ -3673,6 +3759,12 @@
3673
3759
  }
3674
3760
  var ReactDOM = require("react-dom"),
3675
3761
  React = require("react"),
3762
+ hasOwnProperty = Object.prototype.hasOwnProperty,
3763
+ supportsArrayBufferDetached = hasOwnProperty.call(
3764
+ ArrayBuffer.prototype,
3765
+ "detached"
3766
+ ),
3767
+ didWarnAboutMissingArrayBufferDetached = !1,
3676
3768
  LocalPromise = Promise,
3677
3769
  scheduleMicrotask =
3678
3770
  "function" === typeof queueMicrotask
@@ -4111,7 +4203,6 @@
4111
4203
  debugID = null,
4112
4204
  modelRoot = !1,
4113
4205
  emptyRoot = {},
4114
- hasOwnProperty = Object.prototype.hasOwnProperty,
4115
4206
  chunkCache = new Map(),
4116
4207
  RESPONSE_SYMBOL = Symbol();
4117
4208
  ReactPromise.prototype = Object.create(Promise.prototype);
@@ -4179,44 +4270,44 @@
4179
4270
  };
4180
4271
  exports.decodeAction = function (body, serverManifest) {
4181
4272
  var formData = new FormData(),
4182
- action = null,
4183
- seenActions = new Set();
4273
+ maybeActionKey = null;
4184
4274
  body.forEach(function (value, key) {
4185
4275
  key.startsWith("$ACTION_")
4186
4276
  ? key.startsWith("$ACTION_REF_")
4187
- ? seenActions.has(key) ||
4188
- (seenActions.add(key),
4189
- (value = "$ACTION_" + key.slice(12) + ":"),
4190
- (value = decodeBoundActionMetaData(body, serverManifest, value)),
4191
- (action = loadServerReference(serverManifest, value)))
4192
- : key.startsWith("$ACTION_ID_") &&
4193
- !seenActions.has(key) &&
4194
- (seenActions.add(key),
4195
- (value = key.slice(11)),
4196
- (action = loadServerReference(serverManifest, {
4197
- id: value,
4198
- bound: null
4199
- })))
4277
+ ? (maybeActionKey = key)
4278
+ : key.startsWith("$ACTION_ID_") && (maybeActionKey = key)
4200
4279
  : formData.append(key, value);
4201
4280
  });
4202
- return null === action
4203
- ? null
4204
- : action.then(function (fn) {
4205
- return fn.bind(null, formData);
4206
- });
4281
+ if (null === maybeActionKey) return null;
4282
+ var actionKey = maybeActionKey,
4283
+ action = null;
4284
+ if (actionKey.startsWith("$ACTION_REF_"))
4285
+ (actionKey = "$ACTION_" + actionKey.slice(12) + ":"),
4286
+ (body = decodeBoundActionMetaData(body, serverManifest, actionKey)),
4287
+ (action = loadServerReference(serverManifest, body));
4288
+ else if (actionKey.startsWith("$ACTION_ID_"))
4289
+ (body = actionKey.slice(11)),
4290
+ (action = loadServerReference(serverManifest, {
4291
+ id: body,
4292
+ bound: null
4293
+ }));
4294
+ else throw Error("Cannot handle action key. This is a bug in React.");
4295
+ return action.then(function (fn) {
4296
+ return fn.bind(null, formData);
4297
+ });
4207
4298
  };
4208
4299
  exports.decodeFormState = function (actionResult, body, serverManifest) {
4209
4300
  var keyPath = body.get("$ACTION_KEY");
4210
4301
  if ("string" !== typeof keyPath) return Promise.resolve(null);
4211
- var metaData = null;
4302
+ var actionKey = null;
4212
4303
  body.forEach(function (value, key) {
4213
- key.startsWith("$ACTION_REF_") &&
4214
- ((value = "$ACTION_" + key.slice(12) + ":"),
4215
- (metaData = decodeBoundActionMetaData(body, serverManifest, value)));
4304
+ key.startsWith("$ACTION_REF_") && (actionKey = key);
4216
4305
  });
4217
- if (null === metaData) return Promise.resolve(null);
4218
- var referenceId = metaData.id;
4219
- return Promise.resolve(metaData.bound).then(function (bound) {
4306
+ if (null === actionKey) return Promise.resolve(null);
4307
+ var formFieldPrefix = "$ACTION_" + actionKey.slice(12) + ":";
4308
+ body = decodeBoundActionMetaData(body, serverManifest, formFieldPrefix);
4309
+ var referenceId = body.id;
4310
+ return Promise.resolve(body.bound).then(function (bound) {
4220
4311
  return null === bound
4221
4312
  ? null
4222
4313
  : [actionResult, keyPath, referenceId, bound.length - 1];