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.
@@ -10,7 +10,12 @@
10
10
 
11
11
  "use strict";
12
12
  var ReactDOM = require("react-dom"),
13
- React = require("react");
13
+ React = require("react"),
14
+ hasOwnProperty = Object.prototype.hasOwnProperty,
15
+ supportsArrayBufferDetached = hasOwnProperty.call(
16
+ ArrayBuffer.prototype,
17
+ "detached"
18
+ );
14
19
  function handleErrorInNextTick(error) {
15
20
  setTimeout(function () {
16
21
  throw error;
@@ -28,28 +33,30 @@ var LocalPromise = Promise,
28
33
  currentView = null,
29
34
  writtenBytes = 0;
30
35
  function writeChunkAndReturn(destination, chunk) {
31
- if (0 !== chunk.byteLength)
32
- if (2048 < chunk.byteLength)
33
- 0 < writtenBytes &&
34
- (destination.enqueue(
35
- new Uint8Array(currentView.buffer, 0, writtenBytes)
36
- ),
37
- (currentView = new Uint8Array(2048)),
38
- (writtenBytes = 0)),
39
- destination.enqueue(chunk);
40
- else {
41
- var allowableBytes = currentView.length - writtenBytes;
42
- allowableBytes < chunk.byteLength &&
43
- (0 === allowableBytes
44
- ? destination.enqueue(currentView)
45
- : (currentView.set(chunk.subarray(0, allowableBytes), writtenBytes),
46
- destination.enqueue(currentView),
47
- (chunk = chunk.subarray(allowableBytes))),
48
- (currentView = new Uint8Array(2048)),
49
- (writtenBytes = 0));
50
- currentView.set(chunk, writtenBytes);
51
- writtenBytes += chunk.byteLength;
52
- }
36
+ if (0 === chunk.byteLength) {
37
+ if (supportsArrayBufferDetached && chunk.buffer.detached)
38
+ throw Error(
39
+ "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()`."
40
+ );
41
+ } else if (2048 < chunk.byteLength)
42
+ 0 < writtenBytes &&
43
+ (destination.enqueue(new Uint8Array(currentView.buffer, 0, writtenBytes)),
44
+ (currentView = new Uint8Array(2048)),
45
+ (writtenBytes = 0)),
46
+ destination.enqueue(chunk);
47
+ else {
48
+ var allowableBytes = currentView.length - writtenBytes;
49
+ allowableBytes < chunk.byteLength &&
50
+ (0 === allowableBytes
51
+ ? destination.enqueue(currentView)
52
+ : (currentView.set(chunk.subarray(0, allowableBytes), writtenBytes),
53
+ destination.enqueue(currentView),
54
+ (chunk = chunk.subarray(allowableBytes))),
55
+ (currentView = new Uint8Array(2048)),
56
+ (writtenBytes = 0));
57
+ currentView.set(chunk, writtenBytes);
58
+ writtenBytes += chunk.byteLength;
59
+ }
53
60
  return !0;
54
61
  }
55
62
  var textEncoder = new TextEncoder();
@@ -940,7 +947,7 @@ function serializeAsyncIterable(request, task, iterable, iterator) {
940
947
  emitErrorChunk(request, streamTask.id, digest);
941
948
  enqueueFlush(request);
942
949
  "function" === typeof iterator.throw &&
943
- iterator.throw(reason).then(error, error);
950
+ iterator.throw(reason).then(noop, noop);
944
951
  }
945
952
  }
946
953
  function abortIterable(reason) {
@@ -951,7 +958,7 @@ function serializeAsyncIterable(request, task, iterable, iterator) {
951
958
  emitErrorChunk(request, streamTask.id, digest);
952
959
  enqueueFlush(request);
953
960
  "function" === typeof iterator.throw &&
954
- iterator.throw(reason).then(error, error);
961
+ iterator.throw(reason).then(noop, noop);
955
962
  }
956
963
  }
957
964
  iterable = iterable === iterator;
@@ -1688,14 +1695,30 @@ function emitModelChunk(request, id, json) {
1688
1695
  }
1689
1696
  function emitTypedArrayChunk(request, id, tag, typedArray) {
1690
1697
  request.pendingChunks++;
1691
- var buffer = new Uint8Array(
1692
- typedArray.buffer,
1693
- typedArray.byteOffset,
1694
- typedArray.byteLength
1695
- );
1696
- typedArray = 2048 < typedArray.byteLength ? buffer.slice() : buffer;
1697
- buffer = typedArray.byteLength;
1698
- id = id.toString(16) + ":" + tag + buffer.toString(16) + ",";
1698
+ a: {
1699
+ var view = new Uint8Array(
1700
+ typedArray.buffer,
1701
+ typedArray.byteOffset,
1702
+ typedArray.byteLength
1703
+ );
1704
+ if (2048 < typedArray.byteLength) {
1705
+ if (
1706
+ 0 !== typedArray.byteOffset ||
1707
+ typedArray.byteLength !== typedArray.buffer.byteLength ||
1708
+ typedArray.buffer.resizable
1709
+ ) {
1710
+ typedArray = view.slice();
1711
+ break a;
1712
+ }
1713
+ if (!supportsArrayBufferDetached) {
1714
+ typedArray = view.slice();
1715
+ break a;
1716
+ }
1717
+ }
1718
+ typedArray = view;
1719
+ }
1720
+ view = typedArray.byteLength;
1721
+ id = id.toString(16) + ":" + tag + view.toString(16) + ",";
1699
1722
  id = stringToChunk(id);
1700
1723
  request.completedRegularChunks.push(id, typedArray);
1701
1724
  }
@@ -1938,7 +1961,6 @@ function abort(request, reason) {
1938
1961
  logRecoverableError(request, error$27, null), fatalError(request, error$27);
1939
1962
  }
1940
1963
  }
1941
- var hasOwnProperty = Object.prototype.hasOwnProperty;
1942
1964
  function resolveServerReference(bundlerConfig, id) {
1943
1965
  var name = "",
1944
1966
  resolvedModuleData = bundlerConfig[id];
@@ -2009,6 +2031,38 @@ function requireModule(metadata) {
2009
2031
  if (hasOwnProperty.call(moduleExports, metadata[2]))
2010
2032
  return moduleExports[metadata[2]];
2011
2033
  }
2034
+ function appendBackingEntry(backingStore, value, key) {
2035
+ var prefix = backingStore.prefix;
2036
+ if (key.startsWith(prefix)) {
2037
+ switch (key[prefix.length]) {
2038
+ case "_":
2039
+ prefix = backingStore.referencedEntries;
2040
+ null === prefix && (prefix = backingStore.referencedEntries = []);
2041
+ prefix.push([key, value]);
2042
+ return;
2043
+ case "S":
2044
+ "string" === typeof value &&
2045
+ ((prefix = backingStore.streamChunks),
2046
+ null === prefix && (prefix = backingStore.streamChunks = new Map()),
2047
+ (backingStore = prefix.get(key)),
2048
+ void 0 === backingStore
2049
+ ? prefix.set(key, [value])
2050
+ : backingStore.push(value));
2051
+ return;
2052
+ }
2053
+ "string" === typeof value
2054
+ ? ((prefix = backingStore.stringChunks),
2055
+ null === prefix && (prefix = backingStore.stringChunks = new Map()),
2056
+ prefix.set(key, value))
2057
+ : ((prefix = backingStore.blobs),
2058
+ null === prefix && (prefix = backingStore.blobs = new Map()),
2059
+ prefix.set(key, value));
2060
+ }
2061
+ }
2062
+ function getBackingBlob(backingStore, key) {
2063
+ backingStore = backingStore.blobs;
2064
+ return null === backingStore ? void 0 : backingStore.get(key);
2065
+ }
2012
2066
  var RESPONSE_SYMBOL = Symbol();
2013
2067
  function ReactPromise(status, value, reason) {
2014
2068
  this.status = status;
@@ -2378,13 +2432,16 @@ function reportGlobalError(response, error) {
2378
2432
  function getChunk(response, id) {
2379
2433
  var chunks = response._chunks,
2380
2434
  chunk = chunks.get(id);
2381
- chunk ||
2382
- ((chunk = response._formData.data.get(response._prefix + id)),
2383
- (chunk =
2435
+ if (!chunk) {
2436
+ chunk = response._prefix;
2437
+ var stringChunks = response._formData.stringChunks;
2438
+ chunk = null === stringChunks ? void 0 : stringChunks.get(chunk + id);
2439
+ chunk =
2384
2440
  "string" === typeof chunk
2385
2441
  ? createResolvedModelChunk(response, chunk, id)
2386
- : new ReactPromise("pending", null, null)),
2387
- chunks.set(id, chunk));
2442
+ : new ReactPromise("pending", null, null);
2443
+ chunks.set(id, chunk);
2444
+ }
2388
2445
  return chunk;
2389
2446
  }
2390
2447
  function fulfillReference(response, reference, value, arrayRoot) {
@@ -2615,7 +2672,7 @@ function parseTypedArray(
2615
2672
  Error("Already initialized typed array.")
2616
2673
  )
2617
2674
  );
2618
- reference = response._formData.data.get(key).arrayBuffer();
2675
+ reference = getBackingBlob(response._formData, key).arrayBuffer();
2619
2676
  if (initializingHandler) {
2620
2677
  var handler = initializingHandler;
2621
2678
  handler.deps++;
@@ -2659,13 +2716,15 @@ function resolveStream(response, id, stream, controller) {
2659
2716
  var chunks = response._chunks;
2660
2717
  stream = new ReactPromise("fulfilled", stream, controller);
2661
2718
  chunks.set(id, stream);
2662
- response = response._formData.data.getAll(response._prefix + id);
2663
- for (id = 0; id < response.length; id++)
2664
- (chunks = response[id]),
2665
- "string" === typeof chunks &&
2666
- ("C" === chunks[0]
2719
+ chunks = response._prefix;
2720
+ response = response._formData.streamChunks;
2721
+ id = null === response ? void 0 : response.get(chunks + "S" + id);
2722
+ if (void 0 !== id)
2723
+ for (response = 0; response < id.length; response++)
2724
+ (chunks = id[response]),
2725
+ "C" === chunks[0]
2667
2726
  ? controller.close("C" === chunks ? '"$undefined"' : chunks.slice(1))
2668
- : controller.enqueueModel(chunks));
2727
+ : controller.enqueueModel(chunks);
2669
2728
  }
2670
2729
  function parseReadableStream(response, reference, type) {
2671
2730
  function enqueue(value) {
@@ -2831,7 +2890,14 @@ function parseAsyncIterable(response, reference, iterator) {
2831
2890
  });
2832
2891
  return iterator;
2833
2892
  }
2834
- function parseModelString(response, obj, key, value, reference, arrayRoot) {
2893
+ function parseModelString(
2894
+ response,
2895
+ obj,
2896
+ key$jscomp$0,
2897
+ value,
2898
+ reference,
2899
+ arrayRoot
2900
+ ) {
2835
2901
  if ("$" === value[0]) {
2836
2902
  switch (value[1]) {
2837
2903
  case "$":
@@ -2849,7 +2915,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2849
2915
  response,
2850
2916
  arrayRoot,
2851
2917
  obj,
2852
- key,
2918
+ key$jscomp$0,
2853
2919
  null,
2854
2920
  loadServerReference$1
2855
2921
  )
@@ -2866,43 +2932,55 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2866
2932
  case "Q":
2867
2933
  return (
2868
2934
  (arrayRoot = value.slice(2)),
2869
- getOutlinedModel(response, arrayRoot, obj, key, null, createMap)
2935
+ getOutlinedModel(
2936
+ response,
2937
+ arrayRoot,
2938
+ obj,
2939
+ key$jscomp$0,
2940
+ null,
2941
+ createMap
2942
+ )
2870
2943
  );
2871
2944
  case "W":
2872
2945
  return (
2873
2946
  (arrayRoot = value.slice(2)),
2874
- getOutlinedModel(response, arrayRoot, obj, key, null, createSet)
2947
+ getOutlinedModel(
2948
+ response,
2949
+ arrayRoot,
2950
+ obj,
2951
+ key$jscomp$0,
2952
+ null,
2953
+ createSet
2954
+ )
2875
2955
  );
2876
2956
  case "K":
2877
- key = value.slice(2);
2878
- obj = response._prefix + "_";
2879
- key = obj + key + "_";
2880
- arrayRoot = new FormData();
2881
- for (response = response._formData; ; ) {
2882
- value = response.keys;
2883
- null === value &&
2884
- ((value = response.keys = Array.from(response.data.keys())),
2885
- (response.keyPointer = 0));
2886
- value = value[response.keyPointer];
2887
- if (void 0 === value) break;
2888
- if (value.startsWith(key)) {
2889
- reference = response.data.getAll(value);
2890
- for (
2891
- var referencedFormDataKey = value.slice(key.length), i = 0;
2892
- i < reference.length;
2893
- i++
2894
- )
2895
- arrayRoot.append(referencedFormDataKey, reference[i]);
2896
- response.data.delete(value);
2897
- response.keyPointer++;
2898
- } else if (value.startsWith(obj)) break;
2899
- else response.keyPointer++;
2957
+ obj = value.slice(2);
2958
+ obj = response._prefix + "_" + obj + "_";
2959
+ response = response._formData;
2960
+ key$jscomp$0 = new FormData();
2961
+ arrayRoot = response.referencedEntries;
2962
+ if (null !== arrayRoot) {
2963
+ for (value = response.keyPointer; value < arrayRoot.length; ) {
2964
+ reference = arrayRoot[value];
2965
+ var key = reference[0];
2966
+ if (!key.startsWith(obj)) break;
2967
+ key$jscomp$0.append(key.slice(obj.length), reference[1]);
2968
+ value++;
2969
+ }
2970
+ response.keyPointer = value;
2900
2971
  }
2901
- return arrayRoot;
2972
+ return key$jscomp$0;
2902
2973
  case "i":
2903
2974
  return (
2904
2975
  (arrayRoot = value.slice(2)),
2905
- getOutlinedModel(response, arrayRoot, obj, key, null, extractIterator)
2976
+ getOutlinedModel(
2977
+ response,
2978
+ arrayRoot,
2979
+ obj,
2980
+ key$jscomp$0,
2981
+ null,
2982
+ extractIterator
2983
+ )
2906
2984
  );
2907
2985
  case "I":
2908
2986
  return Infinity;
@@ -2933,7 +3011,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2933
3011
  ArrayBuffer,
2934
3012
  1,
2935
3013
  obj,
2936
- key,
3014
+ key$jscomp$0,
2937
3015
  arrayRoot
2938
3016
  );
2939
3017
  case "O":
@@ -2943,7 +3021,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2943
3021
  Int8Array,
2944
3022
  1,
2945
3023
  obj,
2946
- key,
3024
+ key$jscomp$0,
2947
3025
  arrayRoot
2948
3026
  );
2949
3027
  case "o":
@@ -2953,7 +3031,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2953
3031
  Uint8Array,
2954
3032
  1,
2955
3033
  obj,
2956
- key,
3034
+ key$jscomp$0,
2957
3035
  arrayRoot
2958
3036
  );
2959
3037
  case "U":
@@ -2963,7 +3041,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2963
3041
  Uint8ClampedArray,
2964
3042
  1,
2965
3043
  obj,
2966
- key,
3044
+ key$jscomp$0,
2967
3045
  arrayRoot
2968
3046
  );
2969
3047
  case "S":
@@ -2973,7 +3051,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2973
3051
  Int16Array,
2974
3052
  2,
2975
3053
  obj,
2976
- key,
3054
+ key$jscomp$0,
2977
3055
  arrayRoot
2978
3056
  );
2979
3057
  case "s":
@@ -2983,7 +3061,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2983
3061
  Uint16Array,
2984
3062
  2,
2985
3063
  obj,
2986
- key,
3064
+ key$jscomp$0,
2987
3065
  arrayRoot
2988
3066
  );
2989
3067
  case "L":
@@ -2993,7 +3071,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2993
3071
  Int32Array,
2994
3072
  4,
2995
3073
  obj,
2996
- key,
3074
+ key$jscomp$0,
2997
3075
  arrayRoot
2998
3076
  );
2999
3077
  case "l":
@@ -3003,7 +3081,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3003
3081
  Uint32Array,
3004
3082
  4,
3005
3083
  obj,
3006
- key,
3084
+ key$jscomp$0,
3007
3085
  arrayRoot
3008
3086
  );
3009
3087
  case "G":
@@ -3013,7 +3091,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3013
3091
  Float32Array,
3014
3092
  4,
3015
3093
  obj,
3016
- key,
3094
+ key$jscomp$0,
3017
3095
  arrayRoot
3018
3096
  );
3019
3097
  case "g":
@@ -3023,7 +3101,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3023
3101
  Float64Array,
3024
3102
  8,
3025
3103
  obj,
3026
- key,
3104
+ key$jscomp$0,
3027
3105
  arrayRoot
3028
3106
  );
3029
3107
  case "M":
@@ -3033,7 +3111,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3033
3111
  BigInt64Array,
3034
3112
  8,
3035
3113
  obj,
3036
- key,
3114
+ key$jscomp$0,
3037
3115
  arrayRoot
3038
3116
  );
3039
3117
  case "m":
@@ -3043,7 +3121,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3043
3121
  BigUint64Array,
3044
3122
  8,
3045
3123
  obj,
3046
- key,
3124
+ key$jscomp$0,
3047
3125
  arrayRoot
3048
3126
  );
3049
3127
  case "V":
@@ -3053,13 +3131,13 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3053
3131
  DataView,
3054
3132
  1,
3055
3133
  obj,
3056
- key,
3134
+ key$jscomp$0,
3057
3135
  arrayRoot
3058
3136
  );
3059
3137
  case "B":
3060
3138
  return (
3061
3139
  (obj = parseInt(value.slice(2), 16)),
3062
- response._formData.data.get(response._prefix + obj)
3140
+ getBackingBlob(response._formData, response._prefix + obj)
3063
3141
  );
3064
3142
  }
3065
3143
  switch (value[1]) {
@@ -3073,7 +3151,14 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3073
3151
  return parseAsyncIterable(response, value, !0);
3074
3152
  }
3075
3153
  value = value.slice(1);
3076
- return getOutlinedModel(response, value, obj, key, arrayRoot, createModel);
3154
+ return getOutlinedModel(
3155
+ response,
3156
+ value,
3157
+ obj,
3158
+ key$jscomp$0,
3159
+ arrayRoot,
3160
+ createModel
3161
+ );
3077
3162
  }
3078
3163
  null !== arrayRoot && bumpArrayCount(arrayRoot, value.length, response);
3079
3164
  return value;
@@ -3085,11 +3170,20 @@ function createResponse(bundlerConfig, formFieldPrefix, temporaryReferences) {
3085
3170
  : new FormData(),
3086
3171
  arraySizeLimit =
3087
3172
  4 < arguments.length && void 0 !== arguments[4] ? arguments[4] : 1e6,
3088
- chunks = new Map();
3173
+ chunks = new Map(),
3174
+ backingStore = {
3175
+ prefix: formFieldPrefix,
3176
+ referencedEntries: null,
3177
+ keyPointer: 0,
3178
+ stringChunks: null,
3179
+ streamChunks: null,
3180
+ blobs: null
3181
+ };
3182
+ backingFormData.forEach(appendBackingEntry.bind(null, backingStore));
3089
3183
  return {
3090
3184
  _bundlerConfig: bundlerConfig,
3091
3185
  _prefix: formFieldPrefix,
3092
- _formData: { data: backingFormData, keyPointer: -1, keys: null },
3186
+ _formData: backingStore,
3093
3187
  _chunks: chunks,
3094
3188
  _temporaryReferences: temporaryReferences,
3095
3189
  _rootArrayContexts: new WeakMap(),
@@ -3151,44 +3245,41 @@ exports.createTemporaryReferenceSet = function () {
3151
3245
  };
3152
3246
  exports.decodeAction = function (body, serverManifest) {
3153
3247
  var formData = new FormData(),
3154
- action = null,
3155
- seenActions = new Set();
3248
+ maybeActionKey = null;
3156
3249
  body.forEach(function (value, key) {
3157
3250
  key.startsWith("$ACTION_")
3158
3251
  ? key.startsWith("$ACTION_REF_")
3159
- ? seenActions.has(key) ||
3160
- (seenActions.add(key),
3161
- (value = "$ACTION_" + key.slice(12) + ":"),
3162
- (value = decodeBoundActionMetaData(body, serverManifest, value)),
3163
- (action = loadServerReference(serverManifest, value)))
3164
- : key.startsWith("$ACTION_ID_") &&
3165
- !seenActions.has(key) &&
3166
- (seenActions.add(key),
3167
- (value = key.slice(11)),
3168
- (action = loadServerReference(serverManifest, {
3169
- id: value,
3170
- bound: null
3171
- })))
3252
+ ? (maybeActionKey = key)
3253
+ : key.startsWith("$ACTION_ID_") && (maybeActionKey = key)
3172
3254
  : formData.append(key, value);
3173
3255
  });
3174
- return null === action
3175
- ? null
3176
- : action.then(function (fn) {
3177
- return fn.bind(null, formData);
3178
- });
3256
+ if (null === maybeActionKey) return null;
3257
+ var actionKey = maybeActionKey,
3258
+ action = null;
3259
+ if (actionKey.startsWith("$ACTION_REF_"))
3260
+ (actionKey = "$ACTION_" + actionKey.slice(12) + ":"),
3261
+ (body = decodeBoundActionMetaData(body, serverManifest, actionKey)),
3262
+ (action = loadServerReference(serverManifest, body));
3263
+ else if (actionKey.startsWith("$ACTION_ID_"))
3264
+ (body = actionKey.slice(11)),
3265
+ (action = loadServerReference(serverManifest, { id: body, bound: null }));
3266
+ else throw Error("Cannot handle action key. This is a bug in React.");
3267
+ return action.then(function (fn) {
3268
+ return fn.bind(null, formData);
3269
+ });
3179
3270
  };
3180
3271
  exports.decodeFormState = function (actionResult, body, serverManifest) {
3181
3272
  var keyPath = body.get("$ACTION_KEY");
3182
3273
  if ("string" !== typeof keyPath) return Promise.resolve(null);
3183
- var metaData = null;
3274
+ var actionKey = null;
3184
3275
  body.forEach(function (value, key) {
3185
- key.startsWith("$ACTION_REF_") &&
3186
- ((value = "$ACTION_" + key.slice(12) + ":"),
3187
- (metaData = decodeBoundActionMetaData(body, serverManifest, value)));
3276
+ key.startsWith("$ACTION_REF_") && (actionKey = key);
3188
3277
  });
3189
- if (null === metaData) return Promise.resolve(null);
3190
- var referenceId = metaData.id;
3191
- return Promise.resolve(metaData.bound).then(function (bound) {
3278
+ if (null === actionKey) return Promise.resolve(null);
3279
+ var formFieldPrefix = "$ACTION_" + actionKey.slice(12) + ":";
3280
+ body = decodeBoundActionMetaData(body, serverManifest, formFieldPrefix);
3281
+ var referenceId = body.id;
3282
+ return Promise.resolve(body.bound).then(function (bound) {
3192
3283
  return null === bound
3193
3284
  ? null
3194
3285
  : [actionResult, keyPath, referenceId, bound.length - 1];