react-server-dom-webpack 19.0.0-canary-fd0da3eef-20240404 → 19.0.0-canary-4c12339ce-20240408

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.
Files changed (37) hide show
  1. package/cjs/react-server-dom-webpack-client.browser.development.js +32 -8
  2. package/cjs/react-server-dom-webpack-client.browser.production.js +22 -1
  3. package/cjs/react-server-dom-webpack-client.browser.production.min.js +4 -3
  4. package/cjs/react-server-dom-webpack-client.browser.production.min.js.map +1 -1
  5. package/cjs/react-server-dom-webpack-client.edge.development.js +32 -8
  6. package/cjs/react-server-dom-webpack-client.edge.production.js +22 -1
  7. package/cjs/react-server-dom-webpack-client.edge.production.min.js +3 -3
  8. package/cjs/react-server-dom-webpack-client.edge.production.min.js.map +1 -1
  9. package/cjs/react-server-dom-webpack-client.node.development.js +32 -8
  10. package/cjs/react-server-dom-webpack-client.node.production.js +22 -1
  11. package/cjs/react-server-dom-webpack-client.node.production.min.js +8 -8
  12. package/cjs/react-server-dom-webpack-client.node.production.min.js.map +1 -1
  13. package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +32 -8
  14. package/cjs/react-server-dom-webpack-client.node.unbundled.production.js +22 -1
  15. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js +31 -31
  16. package/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js.map +1 -1
  17. package/cjs/react-server-dom-webpack-server.browser.development.js +278 -21
  18. package/cjs/react-server-dom-webpack-server.browser.production.js +24 -5
  19. package/cjs/react-server-dom-webpack-server.browser.production.min.js +45 -45
  20. package/cjs/react-server-dom-webpack-server.browser.production.min.js.map +1 -1
  21. package/cjs/react-server-dom-webpack-server.edge.development.js +278 -21
  22. package/cjs/react-server-dom-webpack-server.edge.production.js +24 -5
  23. package/cjs/react-server-dom-webpack-server.edge.production.min.js +45 -45
  24. package/cjs/react-server-dom-webpack-server.edge.production.min.js.map +1 -1
  25. package/cjs/react-server-dom-webpack-server.node.development.js +278 -21
  26. package/cjs/react-server-dom-webpack-server.node.production.js +24 -5
  27. package/cjs/react-server-dom-webpack-server.node.production.min.js +2 -2
  28. package/cjs/react-server-dom-webpack-server.node.production.min.js.map +1 -1
  29. package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +278 -21
  30. package/cjs/react-server-dom-webpack-server.node.unbundled.production.js +24 -5
  31. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js +2 -2
  32. package/cjs/react-server-dom-webpack-server.node.unbundled.production.min.js.map +1 -1
  33. package/package.json +3 -3
  34. package/umd/react-server-dom-webpack-client.browser.development.js +32 -8
  35. package/umd/react-server-dom-webpack-client.browser.production.min.js +16 -16
  36. package/umd/react-server-dom-webpack-server.browser.development.js +278 -21
  37. package/umd/react-server-dom-webpack-server.browser.production.min.js +45 -45
@@ -455,6 +455,7 @@
455
455
  var ReactDOMCurrentDispatcher = ReactDOMSharedInternals.ReactDOMCurrentDispatcher;
456
456
  var previousDispatcher = ReactDOMCurrentDispatcher.current;
457
457
  ReactDOMCurrentDispatcher.current = {
458
+ flushSyncWork: previousDispatcher.flushSyncWork,
458
459
  prefetchDNS: prefetchDNS,
459
460
  preconnect: preconnect,
460
461
  preload: preload,
@@ -922,21 +923,34 @@
922
923
  var currentRequest$1 = null;
923
924
  var thenableIndexCounter = 0;
924
925
  var thenableState = null;
926
+ var currentComponentDebugInfo = null;
925
927
  function prepareToUseHooksForRequest(request) {
926
928
  currentRequest$1 = request;
927
929
  }
928
930
  function resetHooksForRequest() {
929
931
  currentRequest$1 = null;
930
932
  }
931
- function prepareToUseHooksForComponent(prevThenableState) {
933
+ function prepareToUseHooksForComponent(prevThenableState, componentDebugInfo) {
932
934
  thenableIndexCounter = 0;
933
935
  thenableState = prevThenableState;
936
+
937
+ {
938
+ currentComponentDebugInfo = componentDebugInfo;
939
+ }
934
940
  }
935
941
  function getThenableStateAfterSuspending() {
936
942
  // If you use() to Suspend this should always exist but if you throw a Promise instead,
937
943
  // which is not really supported anymore, it will be empty. We use the empty set as a
938
944
  // marker to know if this was a replay of the same component or first attempt.
939
945
  var state = thenableState || createThenableState();
946
+
947
+ {
948
+ // This is a hack but we stash the debug info here so that we don't need a completely
949
+ // different data structure just for this in DEV. Not too happy about it.
950
+ state._componentDebugInfo = currentComponentDebugInfo;
951
+ currentComponentDebugInfo = null;
952
+ }
953
+
940
954
  thenableState = null;
941
955
  return state;
942
956
  }
@@ -1415,6 +1429,7 @@
1415
1429
  var NEVER_OUTLINED = -2;
1416
1430
  var ReactCurrentCache = ReactSharedServerInternals.ReactCurrentCache;
1417
1431
  var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
1432
+ var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
1418
1433
 
1419
1434
  function defaultErrorHandler(error) {
1420
1435
  console['error'](error); // Don't transform to our wrapper
@@ -1635,33 +1650,56 @@
1635
1650
  return lazyType;
1636
1651
  }
1637
1652
 
1638
- function renderFunctionComponent(request, task, key, Component, props) {
1653
+ function renderFunctionComponent(request, task, key, Component, props, owner) {
1639
1654
  // Reset the task's thenable state before continuing, so that if a later
1640
1655
  // component suspends we can reuse the same task object. If the same
1641
1656
  // component suspends again, the thenable state will be restored.
1642
1657
  var prevThenableState = task.thenableState;
1643
1658
  task.thenableState = null;
1659
+ var componentDebugInfo = null;
1644
1660
 
1645
1661
  {
1646
1662
  if (debugID === null) {
1647
1663
  // We don't have a chunk to assign debug info. We need to outline this
1648
1664
  // component to assign it an ID.
1649
1665
  return outlineTask(request, task);
1650
- } else if (prevThenableState !== null) ; else {
1666
+ } else if (prevThenableState !== null) {
1667
+ // This is a replay and we've already emitted the debug info of this component
1668
+ // in the first pass. We skip emitting a duplicate line.
1669
+ // As a hack we stashed the previous component debug info on this object in DEV.
1670
+ componentDebugInfo = prevThenableState._componentDebugInfo;
1671
+ } else {
1651
1672
  // This is a new component in the same task so we can emit more debug info.
1652
1673
  var componentName = Component.displayName || Component.name || '';
1653
1674
  request.pendingChunks++;
1654
- emitDebugChunk(request, debugID, {
1675
+ var componentDebugID = debugID;
1676
+ componentDebugInfo = {
1655
1677
  name: componentName,
1656
- env: request.environmentName
1657
- });
1678
+ env: request.environmentName,
1679
+ owner: owner
1680
+ }; // We outline this model eagerly so that we can refer to by reference as an owner.
1681
+ // If we had a smarter way to dedupe we might not have to do this if there ends up
1682
+ // being no references to this as an owner.
1683
+
1684
+ outlineModel(request, componentDebugInfo);
1685
+ emitDebugChunk(request, componentDebugID, componentDebugInfo);
1658
1686
  }
1659
1687
  }
1660
1688
 
1661
- prepareToUseHooksForComponent(prevThenableState); // The secondArg is always undefined in Server Components since refs error early.
1689
+ prepareToUseHooksForComponent(prevThenableState, componentDebugInfo); // The secondArg is always undefined in Server Components since refs error early.
1662
1690
 
1663
1691
  var secondArg = undefined;
1664
- var result = Component(props, secondArg);
1692
+ var result;
1693
+
1694
+ {
1695
+ ReactCurrentOwner.current = componentDebugInfo;
1696
+
1697
+ try {
1698
+ result = Component(props, secondArg);
1699
+ } finally {
1700
+ ReactCurrentOwner.current = null;
1701
+ }
1702
+ }
1665
1703
 
1666
1704
  if (typeof result === 'object' && result !== null && typeof result.then === 'function') {
1667
1705
  // When the return value is in children position we can resolve it immediately,
@@ -1752,7 +1790,8 @@
1752
1790
  return children;
1753
1791
  }
1754
1792
 
1755
- function renderClientElement(task, type, key, props) {
1793
+ function renderClientElement(task, type, key, props, owner) // DEV-only
1794
+ {
1756
1795
  // the keys of any Server Components which are not serialized.
1757
1796
 
1758
1797
 
@@ -1764,7 +1803,7 @@
1764
1803
  key = keyPath + ',' + key;
1765
1804
  }
1766
1805
 
1767
- var element = [REACT_ELEMENT_TYPE, type, key, props];
1806
+ var element = [REACT_ELEMENT_TYPE, type, key, props, owner] ;
1768
1807
 
1769
1808
  if (task.implicitSlot && key !== null) {
1770
1809
  // The root Server Component had no key so it was in an implicit slot.
@@ -1802,7 +1841,8 @@
1802
1841
  return serializeLazyID(newTask.id);
1803
1842
  }
1804
1843
 
1805
- function renderElement(request, task, type, key, ref, props) {
1844
+ function renderElement(request, task, type, key, ref, props, owner) // DEV only
1845
+ {
1806
1846
  if (ref !== null && ref !== undefined) {
1807
1847
  // When the ref moves to the regular props object this will implicitly
1808
1848
  // throw for functions. We could probably relax it to a DEV warning for other
@@ -1823,14 +1863,14 @@
1823
1863
  if (typeof type === 'function') {
1824
1864
  if (isClientReference(type) || isTemporaryReference(type)) {
1825
1865
  // This is a reference to a Client Component.
1826
- return renderClientElement(task, type, key, props);
1866
+ return renderClientElement(task, type, key, props, owner);
1827
1867
  } // This is a Server Component.
1828
1868
 
1829
1869
 
1830
- return renderFunctionComponent(request, task, key, type, props);
1870
+ return renderFunctionComponent(request, task, key, type, props, owner);
1831
1871
  } else if (typeof type === 'string') {
1832
1872
  // This is a host element. E.g. HTML.
1833
- return renderClientElement(task, type, key, props);
1873
+ return renderClientElement(task, type, key, props, owner);
1834
1874
  } else if (typeof type === 'symbol') {
1835
1875
  if (type === REACT_FRAGMENT_TYPE && key === null) {
1836
1876
  // For key-less fragments, we add a small optimization to avoid serializing
@@ -1848,11 +1888,11 @@
1848
1888
  // Any built-in works as long as its props are serializable.
1849
1889
 
1850
1890
 
1851
- return renderClientElement(task, type, key, props);
1891
+ return renderClientElement(task, type, key, props, owner);
1852
1892
  } else if (type != null && typeof type === 'object') {
1853
1893
  if (isClientReference(type)) {
1854
1894
  // This is a reference to a Client Component.
1855
- return renderClientElement(task, type, key, props);
1895
+ return renderClientElement(task, type, key, props, owner);
1856
1896
  }
1857
1897
 
1858
1898
  switch (type.$$typeof) {
@@ -1861,17 +1901,17 @@
1861
1901
  var payload = type._payload;
1862
1902
  var init = type._init;
1863
1903
  var wrappedType = init(payload);
1864
- return renderElement(request, task, wrappedType, key, ref, props);
1904
+ return renderElement(request, task, wrappedType, key, ref, props, owner);
1865
1905
  }
1866
1906
 
1867
1907
  case REACT_FORWARD_REF_TYPE:
1868
1908
  {
1869
- return renderFunctionComponent(request, task, key, type.render, props);
1909
+ return renderFunctionComponent(request, task, key, type.render, props, owner);
1870
1910
  }
1871
1911
 
1872
1912
  case REACT_MEMO_TYPE:
1873
1913
  {
1874
- return renderElement(request, task, type.type, key, ref, props);
1914
+ return renderElement(request, task, type.type, key, ref, props, owner);
1875
1915
  }
1876
1916
  }
1877
1917
  }
@@ -1950,6 +1990,10 @@
1950
1990
  return '$L' + id.toString(16);
1951
1991
  }
1952
1992
 
1993
+ function serializeInfinitePromise() {
1994
+ return '$@';
1995
+ }
1996
+
1953
1997
  function serializePromiseID(id) {
1954
1998
  return '$@' + id.toString(16);
1955
1999
  }
@@ -2114,6 +2158,12 @@
2114
2158
  return '$Q' + id.toString(16);
2115
2159
  }
2116
2160
 
2161
+ function serializeFormData(request, formData) {
2162
+ var entries = Array.from(formData.entries());
2163
+ var id = outlineModel(request, entries);
2164
+ return '$K' + id.toString(16);
2165
+ }
2166
+
2117
2167
  function serializeSet(request, set) {
2118
2168
  var entries = Array.from(set);
2119
2169
 
@@ -2290,7 +2340,7 @@
2290
2340
 
2291
2341
 
2292
2342
  return renderElement(request, task, element.type, // $FlowFixMe[incompatible-call] the key of an element is null | string
2293
- element.key, ref, props);
2343
+ element.key, ref, props, element._owner );
2294
2344
  }
2295
2345
 
2296
2346
  case REACT_LAZY_TYPE:
@@ -2388,6 +2438,11 @@
2388
2438
 
2389
2439
  if (value instanceof Set) {
2390
2440
  return serializeSet(request, value);
2441
+ } // TODO: FormData is not available in old Node. Remove the typeof later.
2442
+
2443
+
2444
+ if (typeof FormData === 'function' && value instanceof FormData) {
2445
+ return serializeFormData(request, value);
2391
2446
  }
2392
2447
 
2393
2448
  var iteratorFn = getIteratorFn(value);
@@ -2649,14 +2704,216 @@
2649
2704
  }
2650
2705
 
2651
2706
  function emitDebugChunk(request, id, debugInfo) {
2707
+ // use the full serialization that requires a task.
2708
+
2709
+
2710
+ var counter = {
2711
+ objectCount: 0
2712
+ };
2652
2713
 
2714
+ function replacer(parentPropertyName, value) {
2715
+ return renderConsoleValue(request, counter, this, parentPropertyName, value);
2716
+ } // $FlowFixMe[incompatible-type] stringify can return null
2653
2717
 
2654
- var json = stringify(debugInfo);
2718
+
2719
+ var json = stringify(debugInfo, replacer);
2655
2720
  var row = serializeRowHeader('D', id) + json + '\n';
2656
2721
  var processedChunk = stringToChunk(row);
2657
2722
  request.completedRegularChunks.push(processedChunk);
2658
2723
  }
2659
2724
 
2725
+ function serializeEval(source) {
2726
+
2727
+ return '$E' + source;
2728
+ } // This is a forked version of renderModel which should never error, never suspend and is limited
2729
+ // in the depth it can encode.
2730
+
2731
+
2732
+ function renderConsoleValue(request, counter, parent, parentPropertyName, value) {
2733
+ // Make sure that `parent[parentPropertyName]` wasn't JSONified before `value` was passed to us
2734
+ // $FlowFixMe[incompatible-use]
2735
+ var originalValue = parent[parentPropertyName];
2736
+
2737
+ if (value === null) {
2738
+ return null;
2739
+ }
2740
+
2741
+ if (typeof value === 'object') {
2742
+ if (isClientReference(value)) {
2743
+ // We actually have this value on the client so we could import it.
2744
+ // This might be confusing though because on the Server it won't actually
2745
+ // be this value, so if you're debugging client references maybe you'd be
2746
+ // better with a place holder.
2747
+ return serializeClientReference(request, parent, parentPropertyName, value);
2748
+ }
2749
+
2750
+ if (counter.objectCount > 20) {
2751
+ // We've reached our max number of objects to serialize across the wire so we serialize this
2752
+ // object but no properties inside of it, as a place holder.
2753
+ return Array.isArray(value) ? [] : {};
2754
+ }
2755
+
2756
+ counter.objectCount++;
2757
+ var writtenObjects = request.writtenObjects;
2758
+ var existingId = writtenObjects.get(value); // $FlowFixMe[method-unbinding]
2759
+
2760
+ if (typeof value.then === 'function') {
2761
+ if (existingId !== undefined) {
2762
+ // We've seen this promise before, so we can just refer to the same result.
2763
+ return serializePromiseID(existingId);
2764
+ }
2765
+
2766
+ var thenable = value;
2767
+
2768
+ switch (thenable.status) {
2769
+ case 'fulfilled':
2770
+ {
2771
+ return serializePromiseID(outlineConsoleValue(request, counter, thenable.value));
2772
+ }
2773
+
2774
+ case 'rejected':
2775
+ {
2776
+ var x = thenable.reason;
2777
+ request.pendingChunks++;
2778
+ var errorId = request.nextChunkId++;
2779
+
2780
+ {
2781
+ // We don't log these errors since they didn't actually throw into Flight.
2782
+ var digest = '';
2783
+ emitErrorChunk(request, errorId, digest, x);
2784
+ }
2785
+
2786
+ return serializePromiseID(errorId);
2787
+ }
2788
+ } // If it hasn't already resolved (and been instrumented) we just encode an infinite
2789
+ // promise that will never resolve.
2790
+
2791
+
2792
+ return serializeInfinitePromise();
2793
+ }
2794
+
2795
+ if (existingId !== undefined && existingId >= 0) {
2796
+ // We've already emitted this as a real object, so we can
2797
+ // just refer to that by its existing ID.
2798
+ return serializeByValueID(existingId);
2799
+ }
2800
+
2801
+ if (isArray(value)) {
2802
+ return value;
2803
+ }
2804
+
2805
+ if (value instanceof Map) {
2806
+ return serializeMap(request, value);
2807
+ }
2808
+
2809
+ if (value instanceof Set) {
2810
+ return serializeSet(request, value);
2811
+ } // TODO: FormData is not available in old Node. Remove the typeof later.
2812
+
2813
+
2814
+ if (typeof FormData === 'function' && value instanceof FormData) {
2815
+ return serializeFormData(request, value);
2816
+ }
2817
+
2818
+ var iteratorFn = getIteratorFn(value);
2819
+
2820
+ if (iteratorFn) {
2821
+ return Array.from(value);
2822
+ } // $FlowFixMe[incompatible-return]
2823
+
2824
+
2825
+ return value;
2826
+ }
2827
+
2828
+ if (typeof value === 'string') {
2829
+ if (value[value.length - 1] === 'Z') {
2830
+ // Possibly a Date, whose toJSON automatically calls toISOString
2831
+ if (originalValue instanceof Date) {
2832
+ return serializeDateFromDateJSON(value);
2833
+ }
2834
+ }
2835
+
2836
+ if (value.length >= 1024) {
2837
+ // For large strings, we encode them outside the JSON payload so that we
2838
+ // don't have to double encode and double parse the strings. This can also
2839
+ // be more compact in case the string has a lot of escaped characters.
2840
+ return serializeLargeTextString(request, value);
2841
+ }
2842
+
2843
+ return escapeStringValue(value);
2844
+ }
2845
+
2846
+ if (typeof value === 'boolean') {
2847
+ return value;
2848
+ }
2849
+
2850
+ if (typeof value === 'number') {
2851
+ return serializeNumber(value);
2852
+ }
2853
+
2854
+ if (typeof value === 'undefined') {
2855
+ return serializeUndefined();
2856
+ }
2857
+
2858
+ if (typeof value === 'function') {
2859
+ if (isClientReference(value)) {
2860
+ return serializeClientReference(request, parent, parentPropertyName, value);
2861
+ }
2862
+
2863
+ if (isTemporaryReference(value)) {
2864
+ return serializeTemporaryReference(request, value);
2865
+ } // Serialize the body of the function as an eval so it can be printed.
2866
+ // $FlowFixMe[method-unbinding]
2867
+
2868
+
2869
+ return serializeEval('(' + Function.prototype.toString.call(value) + ')');
2870
+ }
2871
+
2872
+ if (typeof value === 'symbol') {
2873
+ var writtenSymbols = request.writtenSymbols;
2874
+
2875
+ var _existingId3 = writtenSymbols.get(value);
2876
+
2877
+ if (_existingId3 !== undefined) {
2878
+ return serializeByValueID(_existingId3);
2879
+ } // $FlowFixMe[incompatible-type] `description` might be undefined
2880
+
2881
+
2882
+ var name = value.description; // We use the Symbol.for version if it's not a global symbol. Close enough.
2883
+
2884
+ request.pendingChunks++;
2885
+ var symbolId = request.nextChunkId++;
2886
+ emitSymbolChunk(request, symbolId, name);
2887
+ return serializeByValueID(symbolId);
2888
+ }
2889
+
2890
+ if (typeof value === 'bigint') {
2891
+ return serializeBigInt(value);
2892
+ }
2893
+
2894
+ return 'unknown type ' + typeof value;
2895
+ }
2896
+
2897
+ function outlineConsoleValue(request, counter, model) {
2898
+
2899
+ function replacer(parentPropertyName, value) {
2900
+ try {
2901
+ return renderConsoleValue(request, counter, this, parentPropertyName, value);
2902
+ } catch (x) {
2903
+ return 'unknown value';
2904
+ }
2905
+ } // $FlowFixMe[incompatible-type] stringify can return null
2906
+
2907
+
2908
+ var json = stringify(model, replacer);
2909
+ request.pendingChunks++;
2910
+ var id = request.nextChunkId++;
2911
+ var row = id.toString(16) + ':' + json + '\n';
2912
+ var processedChunk = stringToChunk(row);
2913
+ request.completedRegularChunks.push(processedChunk);
2914
+ return id;
2915
+ }
2916
+
2660
2917
  function forwardDebugInfo(request, id, debugInfo) {
2661
2918
  for (var i = 0; i < debugInfo.length; i++) {
2662
2919
  request.pendingChunks++;