react-server-dom-webpack 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];
@@ -2012,6 +2034,38 @@ function requireModule(metadata) {
2012
2034
  if (hasOwnProperty.call(moduleExports, metadata[2]))
2013
2035
  return moduleExports[metadata[2]];
2014
2036
  }
2037
+ function appendBackingEntry(backingStore, value, key) {
2038
+ var prefix = backingStore.prefix;
2039
+ if (key.startsWith(prefix)) {
2040
+ switch (key[prefix.length]) {
2041
+ case "_":
2042
+ prefix = backingStore.referencedEntries;
2043
+ null === prefix && (prefix = backingStore.referencedEntries = []);
2044
+ prefix.push([key, value]);
2045
+ return;
2046
+ case "S":
2047
+ "string" === typeof value &&
2048
+ ((prefix = backingStore.streamChunks),
2049
+ null === prefix && (prefix = backingStore.streamChunks = new Map()),
2050
+ (backingStore = prefix.get(key)),
2051
+ void 0 === backingStore
2052
+ ? prefix.set(key, [value])
2053
+ : backingStore.push(value));
2054
+ return;
2055
+ }
2056
+ "string" === typeof value
2057
+ ? ((prefix = backingStore.stringChunks),
2058
+ null === prefix && (prefix = backingStore.stringChunks = new Map()),
2059
+ prefix.set(key, value))
2060
+ : ((prefix = backingStore.blobs),
2061
+ null === prefix && (prefix = backingStore.blobs = new Map()),
2062
+ prefix.set(key, value));
2063
+ }
2064
+ }
2065
+ function getBackingBlob(backingStore, key) {
2066
+ backingStore = backingStore.blobs;
2067
+ return null === backingStore ? void 0 : backingStore.get(key);
2068
+ }
2015
2069
  var RESPONSE_SYMBOL = Symbol();
2016
2070
  function ReactPromise(status, value, reason) {
2017
2071
  this.status = status;
@@ -2381,13 +2435,16 @@ function reportGlobalError(response, error) {
2381
2435
  function getChunk(response, id) {
2382
2436
  var chunks = response._chunks,
2383
2437
  chunk = chunks.get(id);
2384
- chunk ||
2385
- ((chunk = response._formData.data.get(response._prefix + id)),
2386
- (chunk =
2438
+ if (!chunk) {
2439
+ chunk = response._prefix;
2440
+ var stringChunks = response._formData.stringChunks;
2441
+ chunk = null === stringChunks ? void 0 : stringChunks.get(chunk + id);
2442
+ chunk =
2387
2443
  "string" === typeof chunk
2388
2444
  ? createResolvedModelChunk(response, chunk, id)
2389
- : new ReactPromise("pending", null, null)),
2390
- chunks.set(id, chunk));
2445
+ : new ReactPromise("pending", null, null);
2446
+ chunks.set(id, chunk);
2447
+ }
2391
2448
  return chunk;
2392
2449
  }
2393
2450
  function fulfillReference(response, reference, value, arrayRoot) {
@@ -2618,7 +2675,7 @@ function parseTypedArray(
2618
2675
  Error("Already initialized typed array.")
2619
2676
  )
2620
2677
  );
2621
- reference = response._formData.data.get(key).arrayBuffer();
2678
+ reference = getBackingBlob(response._formData, key).arrayBuffer();
2622
2679
  if (initializingHandler) {
2623
2680
  var handler = initializingHandler;
2624
2681
  handler.deps++;
@@ -2662,13 +2719,15 @@ function resolveStream(response, id, stream, controller) {
2662
2719
  var chunks = response._chunks;
2663
2720
  stream = new ReactPromise("fulfilled", stream, controller);
2664
2721
  chunks.set(id, stream);
2665
- response = response._formData.data.getAll(response._prefix + id);
2666
- for (id = 0; id < response.length; id++)
2667
- (chunks = response[id]),
2668
- "string" === typeof chunks &&
2669
- ("C" === chunks[0]
2722
+ chunks = response._prefix;
2723
+ response = response._formData.streamChunks;
2724
+ id = null === response ? void 0 : response.get(chunks + "S" + id);
2725
+ if (void 0 !== id)
2726
+ for (response = 0; response < id.length; response++)
2727
+ (chunks = id[response]),
2728
+ "C" === chunks[0]
2670
2729
  ? controller.close("C" === chunks ? '"$undefined"' : chunks.slice(1))
2671
- : controller.enqueueModel(chunks));
2730
+ : controller.enqueueModel(chunks);
2672
2731
  }
2673
2732
  function parseReadableStream(response, reference, type) {
2674
2733
  function enqueue(value) {
@@ -2834,7 +2893,14 @@ function parseAsyncIterable(response, reference, iterator) {
2834
2893
  });
2835
2894
  return iterator;
2836
2895
  }
2837
- function parseModelString(response, obj, key, value, reference, arrayRoot) {
2896
+ function parseModelString(
2897
+ response,
2898
+ obj,
2899
+ key$jscomp$0,
2900
+ value,
2901
+ reference,
2902
+ arrayRoot
2903
+ ) {
2838
2904
  if ("$" === value[0]) {
2839
2905
  switch (value[1]) {
2840
2906
  case "$":
@@ -2852,7 +2918,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2852
2918
  response,
2853
2919
  arrayRoot,
2854
2920
  obj,
2855
- key,
2921
+ key$jscomp$0,
2856
2922
  null,
2857
2923
  loadServerReference$1
2858
2924
  )
@@ -2869,43 +2935,55 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2869
2935
  case "Q":
2870
2936
  return (
2871
2937
  (arrayRoot = value.slice(2)),
2872
- getOutlinedModel(response, arrayRoot, obj, key, null, createMap)
2938
+ getOutlinedModel(
2939
+ response,
2940
+ arrayRoot,
2941
+ obj,
2942
+ key$jscomp$0,
2943
+ null,
2944
+ createMap
2945
+ )
2873
2946
  );
2874
2947
  case "W":
2875
2948
  return (
2876
2949
  (arrayRoot = value.slice(2)),
2877
- getOutlinedModel(response, arrayRoot, obj, key, null, createSet)
2950
+ getOutlinedModel(
2951
+ response,
2952
+ arrayRoot,
2953
+ obj,
2954
+ key$jscomp$0,
2955
+ null,
2956
+ createSet
2957
+ )
2878
2958
  );
2879
2959
  case "K":
2880
- key = value.slice(2);
2881
- obj = response._prefix + "_";
2882
- key = obj + key + "_";
2883
- arrayRoot = new FormData();
2884
- for (response = response._formData; ; ) {
2885
- value = response.keys;
2886
- null === value &&
2887
- ((value = response.keys = Array.from(response.data.keys())),
2888
- (response.keyPointer = 0));
2889
- value = value[response.keyPointer];
2890
- if (void 0 === value) break;
2891
- if (value.startsWith(key)) {
2892
- reference = response.data.getAll(value);
2893
- for (
2894
- var referencedFormDataKey = value.slice(key.length), i = 0;
2895
- i < reference.length;
2896
- i++
2897
- )
2898
- arrayRoot.append(referencedFormDataKey, reference[i]);
2899
- response.data.delete(value);
2900
- response.keyPointer++;
2901
- } else if (value.startsWith(obj)) break;
2902
- else response.keyPointer++;
2960
+ obj = value.slice(2);
2961
+ obj = response._prefix + "_" + obj + "_";
2962
+ response = response._formData;
2963
+ key$jscomp$0 = new FormData();
2964
+ arrayRoot = response.referencedEntries;
2965
+ if (null !== arrayRoot) {
2966
+ for (value = response.keyPointer; value < arrayRoot.length; ) {
2967
+ reference = arrayRoot[value];
2968
+ var key = reference[0];
2969
+ if (!key.startsWith(obj)) break;
2970
+ key$jscomp$0.append(key.slice(obj.length), reference[1]);
2971
+ value++;
2972
+ }
2973
+ response.keyPointer = value;
2903
2974
  }
2904
- return arrayRoot;
2975
+ return key$jscomp$0;
2905
2976
  case "i":
2906
2977
  return (
2907
2978
  (arrayRoot = value.slice(2)),
2908
- getOutlinedModel(response, arrayRoot, obj, key, null, extractIterator)
2979
+ getOutlinedModel(
2980
+ response,
2981
+ arrayRoot,
2982
+ obj,
2983
+ key$jscomp$0,
2984
+ null,
2985
+ extractIterator
2986
+ )
2909
2987
  );
2910
2988
  case "I":
2911
2989
  return Infinity;
@@ -2936,7 +3014,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2936
3014
  ArrayBuffer,
2937
3015
  1,
2938
3016
  obj,
2939
- key,
3017
+ key$jscomp$0,
2940
3018
  arrayRoot
2941
3019
  );
2942
3020
  case "O":
@@ -2946,7 +3024,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2946
3024
  Int8Array,
2947
3025
  1,
2948
3026
  obj,
2949
- key,
3027
+ key$jscomp$0,
2950
3028
  arrayRoot
2951
3029
  );
2952
3030
  case "o":
@@ -2956,7 +3034,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2956
3034
  Uint8Array,
2957
3035
  1,
2958
3036
  obj,
2959
- key,
3037
+ key$jscomp$0,
2960
3038
  arrayRoot
2961
3039
  );
2962
3040
  case "U":
@@ -2966,7 +3044,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2966
3044
  Uint8ClampedArray,
2967
3045
  1,
2968
3046
  obj,
2969
- key,
3047
+ key$jscomp$0,
2970
3048
  arrayRoot
2971
3049
  );
2972
3050
  case "S":
@@ -2976,7 +3054,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2976
3054
  Int16Array,
2977
3055
  2,
2978
3056
  obj,
2979
- key,
3057
+ key$jscomp$0,
2980
3058
  arrayRoot
2981
3059
  );
2982
3060
  case "s":
@@ -2986,7 +3064,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2986
3064
  Uint16Array,
2987
3065
  2,
2988
3066
  obj,
2989
- key,
3067
+ key$jscomp$0,
2990
3068
  arrayRoot
2991
3069
  );
2992
3070
  case "L":
@@ -2996,7 +3074,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
2996
3074
  Int32Array,
2997
3075
  4,
2998
3076
  obj,
2999
- key,
3077
+ key$jscomp$0,
3000
3078
  arrayRoot
3001
3079
  );
3002
3080
  case "l":
@@ -3006,7 +3084,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3006
3084
  Uint32Array,
3007
3085
  4,
3008
3086
  obj,
3009
- key,
3087
+ key$jscomp$0,
3010
3088
  arrayRoot
3011
3089
  );
3012
3090
  case "G":
@@ -3016,7 +3094,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3016
3094
  Float32Array,
3017
3095
  4,
3018
3096
  obj,
3019
- key,
3097
+ key$jscomp$0,
3020
3098
  arrayRoot
3021
3099
  );
3022
3100
  case "g":
@@ -3026,7 +3104,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3026
3104
  Float64Array,
3027
3105
  8,
3028
3106
  obj,
3029
- key,
3107
+ key$jscomp$0,
3030
3108
  arrayRoot
3031
3109
  );
3032
3110
  case "M":
@@ -3036,7 +3114,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3036
3114
  BigInt64Array,
3037
3115
  8,
3038
3116
  obj,
3039
- key,
3117
+ key$jscomp$0,
3040
3118
  arrayRoot
3041
3119
  );
3042
3120
  case "m":
@@ -3046,7 +3124,7 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3046
3124
  BigUint64Array,
3047
3125
  8,
3048
3126
  obj,
3049
- key,
3127
+ key$jscomp$0,
3050
3128
  arrayRoot
3051
3129
  );
3052
3130
  case "V":
@@ -3056,13 +3134,13 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3056
3134
  DataView,
3057
3135
  1,
3058
3136
  obj,
3059
- key,
3137
+ key$jscomp$0,
3060
3138
  arrayRoot
3061
3139
  );
3062
3140
  case "B":
3063
3141
  return (
3064
3142
  (obj = parseInt(value.slice(2), 16)),
3065
- response._formData.data.get(response._prefix + obj)
3143
+ getBackingBlob(response._formData, response._prefix + obj)
3066
3144
  );
3067
3145
  }
3068
3146
  switch (value[1]) {
@@ -3076,7 +3154,14 @@ function parseModelString(response, obj, key, value, reference, arrayRoot) {
3076
3154
  return parseAsyncIterable(response, value, !0);
3077
3155
  }
3078
3156
  value = value.slice(1);
3079
- return getOutlinedModel(response, value, obj, key, arrayRoot, createModel);
3157
+ return getOutlinedModel(
3158
+ response,
3159
+ value,
3160
+ obj,
3161
+ key$jscomp$0,
3162
+ arrayRoot,
3163
+ createModel
3164
+ );
3080
3165
  }
3081
3166
  null !== arrayRoot && bumpArrayCount(arrayRoot, value.length, response);
3082
3167
  return value;
@@ -3088,11 +3173,20 @@ function createResponse(bundlerConfig, formFieldPrefix, temporaryReferences) {
3088
3173
  : new FormData(),
3089
3174
  arraySizeLimit =
3090
3175
  4 < arguments.length && void 0 !== arguments[4] ? arguments[4] : 1e6,
3091
- chunks = new Map();
3176
+ chunks = new Map(),
3177
+ backingStore = {
3178
+ prefix: formFieldPrefix,
3179
+ referencedEntries: null,
3180
+ keyPointer: 0,
3181
+ stringChunks: null,
3182
+ streamChunks: null,
3183
+ blobs: null
3184
+ };
3185
+ backingFormData.forEach(appendBackingEntry.bind(null, backingStore));
3092
3186
  return {
3093
3187
  _bundlerConfig: bundlerConfig,
3094
3188
  _prefix: formFieldPrefix,
3095
- _formData: { data: backingFormData, keyPointer: -1, keys: null },
3189
+ _formData: backingStore,
3096
3190
  _chunks: chunks,
3097
3191
  _temporaryReferences: temporaryReferences,
3098
3192
  _rootArrayContexts: new WeakMap(),
@@ -3154,44 +3248,41 @@ exports.createTemporaryReferenceSet = function () {
3154
3248
  };
3155
3249
  exports.decodeAction = function (body, serverManifest) {
3156
3250
  var formData = new FormData(),
3157
- action = null,
3158
- seenActions = new Set();
3251
+ maybeActionKey = null;
3159
3252
  body.forEach(function (value, key) {
3160
3253
  key.startsWith("$ACTION_")
3161
3254
  ? key.startsWith("$ACTION_REF_")
3162
- ? seenActions.has(key) ||
3163
- (seenActions.add(key),
3164
- (value = "$ACTION_" + key.slice(12) + ":"),
3165
- (value = decodeBoundActionMetaData(body, serverManifest, value)),
3166
- (action = loadServerReference(serverManifest, value)))
3167
- : key.startsWith("$ACTION_ID_") &&
3168
- !seenActions.has(key) &&
3169
- (seenActions.add(key),
3170
- (value = key.slice(11)),
3171
- (action = loadServerReference(serverManifest, {
3172
- id: value,
3173
- bound: null
3174
- })))
3255
+ ? (maybeActionKey = key)
3256
+ : key.startsWith("$ACTION_ID_") && (maybeActionKey = key)
3175
3257
  : formData.append(key, value);
3176
3258
  });
3177
- return null === action
3178
- ? null
3179
- : action.then(function (fn) {
3180
- return fn.bind(null, formData);
3181
- });
3259
+ if (null === maybeActionKey) return null;
3260
+ var actionKey = maybeActionKey,
3261
+ action = null;
3262
+ if (actionKey.startsWith("$ACTION_REF_"))
3263
+ (actionKey = "$ACTION_" + actionKey.slice(12) + ":"),
3264
+ (body = decodeBoundActionMetaData(body, serverManifest, actionKey)),
3265
+ (action = loadServerReference(serverManifest, body));
3266
+ else if (actionKey.startsWith("$ACTION_ID_"))
3267
+ (body = actionKey.slice(11)),
3268
+ (action = loadServerReference(serverManifest, { id: body, bound: null }));
3269
+ else throw Error("Cannot handle action key. This is a bug in React.");
3270
+ return action.then(function (fn) {
3271
+ return fn.bind(null, formData);
3272
+ });
3182
3273
  };
3183
3274
  exports.decodeFormState = function (actionResult, body, serverManifest) {
3184
3275
  var keyPath = body.get("$ACTION_KEY");
3185
3276
  if ("string" !== typeof keyPath) return Promise.resolve(null);
3186
- var metaData = null;
3277
+ var actionKey = null;
3187
3278
  body.forEach(function (value, key) {
3188
- key.startsWith("$ACTION_REF_") &&
3189
- ((value = "$ACTION_" + key.slice(12) + ":"),
3190
- (metaData = decodeBoundActionMetaData(body, serverManifest, value)));
3279
+ key.startsWith("$ACTION_REF_") && (actionKey = key);
3191
3280
  });
3192
- if (null === metaData) return Promise.resolve(null);
3193
- var referenceId = metaData.id;
3194
- return Promise.resolve(metaData.bound).then(function (bound) {
3281
+ if (null === actionKey) return Promise.resolve(null);
3282
+ var formFieldPrefix = "$ACTION_" + actionKey.slice(12) + ":";
3283
+ body = decodeBoundActionMetaData(body, serverManifest, formFieldPrefix);
3284
+ var referenceId = body.id;
3285
+ return Promise.resolve(body.bound).then(function (bound) {
3195
3286
  return null === bound
3196
3287
  ? null
3197
3288
  : [actionResult, keyPath, referenceId, bound.length - 1];