react-dom 19.0.0-rc-6d3110b4d9-20240531 → 19.0.0-rc-9598c41a20-20240603

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.
@@ -13921,15 +13921,39 @@ function useThenable(thenable) {
13921
13921
  thenableState = createThenableState();
13922
13922
  }
13923
13923
 
13924
- var result = trackUsedThenable(thenableState, thenable, index);
13924
+ var result = trackUsedThenable(thenableState, thenable, index); // When something suspends with `use`, we replay the component with the
13925
+ // "re-render" dispatcher instead of the "mount" or "update" dispatcher.
13926
+ //
13927
+ // But if there are additional hooks that occur after the `use` invocation
13928
+ // that suspended, they wouldn't have been processed during the previous
13929
+ // attempt. So after we invoke `use` again, we may need to switch from the
13930
+ // "re-render" dispatcher back to the "mount" or "update" dispatcher. That's
13931
+ // what the following logic accounts for.
13932
+ //
13933
+ // TODO: Theoretically this logic only needs to go into the rerender
13934
+ // dispatcher. Could optimize, but probably not be worth it.
13935
+ // This is the same logic as in updateWorkInProgressHook.
13936
+
13937
+ var workInProgressFiber = currentlyRenderingFiber$1;
13938
+ var nextWorkInProgressHook = workInProgressHook === null ? // We're at the beginning of the list, so read from the first hook from
13939
+ // the fiber.
13940
+ workInProgressFiber.memoizedState : workInProgressHook.next;
13941
+
13942
+ if (nextWorkInProgressHook !== null) ; else {
13943
+ // There are no remaining hooks from the previous attempt. We're no longer
13944
+ // in "re-render" mode. Switch to the normal mount or update dispatcher.
13945
+ //
13946
+ // This is the same as the logic in renderWithHooks, except we don't bother
13947
+ // to track the hook types debug information in this case (sufficient to
13948
+ // only do that when nothing suspends).
13949
+ var currentFiber = workInProgressFiber.alternate;
13925
13950
 
13926
- if (currentlyRenderingFiber$1.alternate === null && (workInProgressHook === null ? currentlyRenderingFiber$1.memoizedState === null : workInProgressHook.next === null)) {
13927
- // Initial render, and either this is the first time the component is
13928
- // called, or there were no Hooks called after this use() the previous
13929
- // time (perhaps because it threw). Subsequent Hook calls should use the
13930
- // mount dispatcher.
13931
13951
  {
13932
- ReactSharedInternals.H = HooksDispatcherOnMountInDEV;
13952
+ if (currentFiber !== null && currentFiber.memoizedState !== null) {
13953
+ ReactSharedInternals.H = HooksDispatcherOnUpdateInDEV;
13954
+ } else {
13955
+ ReactSharedInternals.H = HooksDispatcherOnMountInDEV;
13956
+ }
13933
13957
  }
13934
13958
  }
13935
13959
 
@@ -14691,112 +14715,155 @@ function dispatchActionState(fiber, actionQueue, setPendingState, setState, payl
14691
14715
  throw new Error('Cannot update form state while rendering.');
14692
14716
  }
14693
14717
 
14718
+ var currentAction = actionQueue.action;
14719
+
14720
+ if (currentAction === null) {
14721
+ // An earlier action errored. Subsequent actions should not run.
14722
+ return;
14723
+ }
14724
+
14725
+ var actionNode = {
14726
+ payload: payload,
14727
+ action: currentAction,
14728
+ next: null,
14729
+ // circular
14730
+ isTransition: true,
14731
+ status: 'pending',
14732
+ value: null,
14733
+ reason: null,
14734
+ listeners: [],
14735
+ then: function (listener) {
14736
+ // We know the only thing that subscribes to these promises is `use` so
14737
+ // this implementation is simpler than a generic thenable. E.g. we don't
14738
+ // bother to check if the thenable is still pending because `use` already
14739
+ // does that.
14740
+ actionNode.listeners.push(listener);
14741
+ }
14742
+ }; // Check if we're inside a transition. If so, we'll need to restore the
14743
+ // transition context when the action is run.
14744
+
14745
+ var prevTransition = ReactSharedInternals.T;
14746
+
14747
+ if (prevTransition !== null) {
14748
+ // Optimistically update the pending state, similar to useTransition.
14749
+ // This will be reverted automatically when all actions are finished.
14750
+ setPendingState(true); // `actionNode` is a thenable that resolves to the return value of
14751
+ // the action.
14752
+
14753
+ setState(actionNode);
14754
+ } else {
14755
+ // This is not a transition.
14756
+ actionNode.isTransition = false;
14757
+ setState(actionNode);
14758
+ }
14759
+
14694
14760
  var last = actionQueue.pending;
14695
14761
 
14696
14762
  if (last === null) {
14697
14763
  // There are no pending actions; this is the first one. We can run
14698
14764
  // it immediately.
14699
- var newLast = {
14700
- payload: payload,
14701
- action: actionQueue.action,
14702
- next: null // circular
14703
-
14704
- };
14705
- newLast.next = actionQueue.pending = newLast;
14706
- runActionStateAction(actionQueue, setPendingState, setState, newLast);
14765
+ actionNode.next = actionQueue.pending = actionNode;
14766
+ runActionStateAction(actionQueue, actionNode);
14707
14767
  } else {
14708
14768
  // There's already an action running. Add to the queue.
14709
14769
  var first = last.next;
14710
- var _newLast = {
14711
- payload: payload,
14712
- action: actionQueue.action,
14713
- next: first
14714
- };
14715
- actionQueue.pending = last.next = _newLast;
14770
+ actionNode.next = first;
14771
+ actionQueue.pending = last.next = actionNode;
14716
14772
  }
14717
14773
  }
14718
14774
 
14719
- function runActionStateAction(actionQueue, setPendingState, setState, node) {
14720
- // This is a fork of startTransition
14721
- var prevTransition = ReactSharedInternals.T;
14722
- var currentTransition = {};
14723
- ReactSharedInternals.T = currentTransition;
14724
-
14725
- {
14726
- ReactSharedInternals.T._updatedFibers = new Set();
14727
- } // Optimistically update the pending state, similar to useTransition.
14728
- // This will be reverted automatically when all actions are finished.
14729
-
14730
-
14731
- setPendingState(true); // `node.action` represents the action function at the time it was dispatched.
14775
+ function runActionStateAction(actionQueue, node) {
14776
+ // `node.action` represents the action function at the time it was dispatched.
14732
14777
  // If this action was queued, it might be stale, i.e. it's not necessarily the
14733
14778
  // most current implementation of the action, stored on `actionQueue`. This is
14734
14779
  // intentional. The conceptual model for queued actions is that they are
14735
14780
  // queued in a remote worker; the dispatch happens immediately, only the
14736
14781
  // execution is delayed.
14737
-
14738
14782
  var action = node.action;
14739
14783
  var payload = node.payload;
14740
14784
  var prevState = actionQueue.state;
14741
14785
 
14742
- try {
14743
- var returnValue = action(prevState, payload);
14744
- var onStartTransitionFinish = ReactSharedInternals.S;
14786
+ if (node.isTransition) {
14787
+ // The original dispatch was part of a transition. We restore its
14788
+ // transition context here.
14789
+ // This is a fork of startTransition
14790
+ var prevTransition = ReactSharedInternals.T;
14791
+ var currentTransition = {};
14792
+ ReactSharedInternals.T = currentTransition;
14745
14793
 
14746
- if (onStartTransitionFinish !== null) {
14747
- onStartTransitionFinish(currentTransition, returnValue);
14794
+ {
14795
+ ReactSharedInternals.T._updatedFibers = new Set();
14748
14796
  }
14749
14797
 
14750
- if (returnValue !== null && typeof returnValue === 'object' && // $FlowFixMe[method-unbinding]
14751
- typeof returnValue.then === 'function') {
14752
- var thenable = returnValue; // Attach a listener to read the return state of the action. As soon as
14753
- // this resolves, we can run the next action in the sequence.
14798
+ try {
14799
+ var returnValue = action(prevState, payload);
14800
+ var onStartTransitionFinish = ReactSharedInternals.S;
14754
14801
 
14755
- thenable.then(function (nextState) {
14756
- actionQueue.state = nextState;
14757
- finishRunningActionStateAction(actionQueue, setPendingState, setState);
14758
- }, function () {
14759
- return finishRunningActionStateAction(actionQueue, setPendingState, setState);
14760
- });
14761
- setState(thenable);
14762
- } else {
14763
- setState(returnValue);
14764
- var nextState = returnValue;
14765
- actionQueue.state = nextState;
14766
- finishRunningActionStateAction(actionQueue, setPendingState, setState);
14767
- }
14768
- } catch (error) {
14769
- // This is a trick to get the `useActionState` hook to rethrow the error.
14770
- // When it unwraps the thenable with the `use` algorithm, the error
14771
- // will be thrown.
14772
- var rejectedThenable = {
14773
- then: function () {},
14774
- status: 'rejected',
14775
- reason: error // $FlowFixMe: Not sure why this doesn't work
14802
+ if (onStartTransitionFinish !== null) {
14803
+ onStartTransitionFinish(currentTransition, returnValue);
14804
+ }
14776
14805
 
14777
- };
14778
- setState(rejectedThenable);
14779
- finishRunningActionStateAction(actionQueue, setPendingState, setState);
14780
- } finally {
14781
- ReactSharedInternals.T = prevTransition;
14806
+ handleActionReturnValue(actionQueue, node, returnValue);
14807
+ } catch (error) {
14808
+ onActionError(actionQueue, node, error);
14809
+ } finally {
14810
+ ReactSharedInternals.T = prevTransition;
14782
14811
 
14783
- {
14784
- if (prevTransition === null && currentTransition._updatedFibers) {
14785
- var updatedFibersCount = currentTransition._updatedFibers.size;
14812
+ {
14813
+ if (prevTransition === null && currentTransition._updatedFibers) {
14814
+ var updatedFibersCount = currentTransition._updatedFibers.size;
14786
14815
 
14787
- currentTransition._updatedFibers.clear();
14816
+ currentTransition._updatedFibers.clear();
14788
14817
 
14789
- if (updatedFibersCount > 10) {
14790
- warn('Detected a large number of updates inside startTransition. ' + 'If this is due to a subscription please re-write it to use React provided hooks. ' + 'Otherwise concurrent mode guarantees are off the table.');
14818
+ if (updatedFibersCount > 10) {
14819
+ warn('Detected a large number of updates inside startTransition. ' + 'If this is due to a subscription please re-write it to use React provided hooks. ' + 'Otherwise concurrent mode guarantees are off the table.');
14820
+ }
14791
14821
  }
14792
14822
  }
14793
14823
  }
14824
+ } else {
14825
+ // The original dispatch was not part of a transition.
14826
+ try {
14827
+ var _returnValue = action(prevState, payload);
14828
+
14829
+ handleActionReturnValue(actionQueue, node, _returnValue);
14830
+ } catch (error) {
14831
+ onActionError(actionQueue, node, error);
14832
+ }
14794
14833
  }
14795
14834
  }
14796
14835
 
14797
- function finishRunningActionStateAction(actionQueue, setPendingState, setState) {
14798
- // The action finished running. Pop it from the queue and run the next pending
14799
- // action, if there are any.
14836
+ function handleActionReturnValue(actionQueue, node, returnValue) {
14837
+ if (returnValue !== null && typeof returnValue === 'object' && // $FlowFixMe[method-unbinding]
14838
+ typeof returnValue.then === 'function') {
14839
+ var thenable = returnValue; // Attach a listener to read the return state of the action. As soon as
14840
+ // this resolves, we can run the next action in the sequence.
14841
+
14842
+ thenable.then(function (nextState) {
14843
+ onActionSuccess(actionQueue, node, nextState);
14844
+ }, function (error) {
14845
+ return onActionError(actionQueue, node, error);
14846
+ });
14847
+
14848
+ {
14849
+ if (!node.isTransition) {
14850
+ error('An async function was passed to useActionState, but it was ' + 'dispatched outside of an action context. This is likely not ' + 'what you intended. Either pass the dispatch function to an ' + '`action` prop, or dispatch manually inside `startTransition`');
14851
+ }
14852
+ }
14853
+ } else {
14854
+ var nextState = returnValue;
14855
+ onActionSuccess(actionQueue, node, nextState);
14856
+ }
14857
+ }
14858
+
14859
+ function onActionSuccess(actionQueue, actionNode, nextState) {
14860
+ // The action finished running.
14861
+ actionNode.status = 'fulfilled';
14862
+ actionNode.value = nextState;
14863
+ notifyActionListeners(actionNode);
14864
+ actionQueue.state = nextState; // Pop the action from the queue and run the next pending action, if there
14865
+ // are any.
14866
+
14800
14867
  var last = actionQueue.pending;
14801
14868
 
14802
14869
  if (last !== null) {
@@ -14810,11 +14877,43 @@ function finishRunningActionStateAction(actionQueue, setPendingState, setState)
14810
14877
  var next = first.next;
14811
14878
  last.next = next; // Run the next action.
14812
14879
 
14813
- runActionStateAction(actionQueue, setPendingState, setState, next);
14880
+ runActionStateAction(actionQueue, next);
14814
14881
  }
14815
14882
  }
14816
14883
  }
14817
14884
 
14885
+ function onActionError(actionQueue, actionNode, error) {
14886
+ // Mark all the following actions as rejected.
14887
+ var last = actionQueue.pending;
14888
+ actionQueue.pending = null;
14889
+
14890
+ if (last !== null) {
14891
+ var first = last.next;
14892
+
14893
+ do {
14894
+ actionNode.status = 'rejected';
14895
+ actionNode.reason = error;
14896
+ notifyActionListeners(actionNode);
14897
+ actionNode = actionNode.next;
14898
+ } while (actionNode !== first);
14899
+ } // Prevent subsequent actions from being dispatched.
14900
+
14901
+
14902
+ actionQueue.action = null;
14903
+ }
14904
+
14905
+ function notifyActionListeners(actionNode) {
14906
+ // Notify React that the action has finished.
14907
+ var listeners = actionNode.listeners;
14908
+
14909
+ for (var i = 0; i < listeners.length; i++) {
14910
+ // This is always a React internal listener, so we don't need to worry
14911
+ // about it throwing.
14912
+ var listener = listeners[i];
14913
+ listener();
14914
+ }
14915
+ }
14916
+
14818
14917
  function actionStateReducer(oldState, newState) {
14819
14918
  return newState;
14820
14919
  }
@@ -18585,14 +18684,22 @@ function updateHostComponent$1(current, workInProgress, renderLanes) {
18585
18684
 
18586
18685
  function updateHostHoistable(current, workInProgress, renderLanes) {
18587
18686
  markRef(current, workInProgress);
18588
- var currentProps = current === null ? null : current.memoizedProps;
18589
- var resource = workInProgress.memoizedState = getResource(workInProgress.type, currentProps, workInProgress.pendingProps);
18590
18687
 
18591
18688
  if (current === null) {
18592
- if (!getIsHydrating() && resource === null) {
18593
- // This is not a Resource Hoistable and we aren't hydrating so we construct the instance.
18594
- workInProgress.stateNode = createHoistableInstance(workInProgress.type, workInProgress.pendingProps, getRootHostContainer(), workInProgress);
18689
+ var resource = getResource(workInProgress.type, null, workInProgress.pendingProps, null);
18690
+
18691
+ if (resource) {
18692
+ workInProgress.memoizedState = resource;
18693
+ } else {
18694
+ if (!getIsHydrating()) {
18695
+ // This is not a Resource Hoistable and we aren't hydrating so we construct the instance.
18696
+ workInProgress.stateNode = createHoistableInstance(workInProgress.type, workInProgress.pendingProps, getRootHostContainer(), workInProgress);
18697
+ }
18595
18698
  }
18699
+ } else {
18700
+ // Get Resource may or may not return a resource. either way we stash the result
18701
+ // on memoized state.
18702
+ workInProgress.memoizedState = getResource(workInProgress.type, current.memoizedProps, workInProgress.pendingProps, current.memoizedState);
18596
18703
  } // Resources never have reconciler managed children. It is possible for
18597
18704
  // the host implementation of getResource to consider children in the
18598
18705
  // resource construction but they will otherwise be discarded. In practice
@@ -26178,29 +26285,28 @@ function completeWork(current, workInProgress, renderLanes) {
26178
26285
  return null;
26179
26286
  }
26180
26287
  } else {
26181
- // We are updating.
26182
- var currentResource = current.memoizedState;
26288
+ // This is an update.
26289
+ if (nextResource) {
26290
+ // This is a Resource
26291
+ if (nextResource !== current.memoizedState) {
26292
+ // we have a new Resource. we need to update
26293
+ markUpdate(workInProgress); // This must come at the very end of the complete phase.
26294
+
26295
+ bubbleProperties(workInProgress); // This must come at the very end of the complete phase, because it might
26296
+ // throw to suspend, and if the resource immediately loads, the work loop
26297
+ // will resume rendering as if the work-in-progress completed. So it must
26298
+ // fully complete.
26183
26299
 
26184
- if (nextResource !== currentResource) {
26185
- // We are transitioning to, from, or between Hoistable Resources
26186
- // and require an update
26187
- markUpdate(workInProgress);
26188
- }
26189
-
26190
- if (nextResource !== null) {
26191
- // This is a Hoistable Resource
26192
- // This must come at the very end of the complete phase.
26193
- bubbleProperties(workInProgress);
26194
-
26195
- if (nextResource === currentResource) {
26196
- workInProgress.flags &= ~MaySuspendCommit;
26197
- } else {
26198
26300
  preloadResourceAndSuspendIfNeeded(workInProgress, nextResource);
26301
+ return null;
26302
+ } else {
26303
+ // This must come at the very end of the complete phase.
26304
+ bubbleProperties(workInProgress);
26305
+ workInProgress.flags &= ~MaySuspendCommit;
26306
+ return null;
26199
26307
  }
26200
-
26201
- return null;
26202
26308
  } else {
26203
- // This is a Hoistable Instance
26309
+ // This is an Instance
26204
26310
  // We may have props to update on the Hoistable instance.
26205
26311
  {
26206
26312
  var oldProps = current.memoizedProps;
@@ -35248,7 +35354,7 @@ function preinitModuleScript(src, options) {
35248
35354
  } // This function is called in begin work and we should always have a currentDocument set
35249
35355
 
35250
35356
 
35251
- function getResource(type, currentProps, pendingProps) {
35357
+ function getResource(type, currentProps, pendingProps, currentResource) {
35252
35358
  var resourceRoot = getCurrentResourceRoot();
35253
35359
 
35254
35360
  if (!resourceRoot) {
@@ -35321,10 +35427,34 @@ function getResource(type, currentProps, pendingProps) {
35321
35427
  }
35322
35428
  }
35323
35429
 
35430
+ if (currentProps && currentResource === null) {
35431
+ // This node was previously an Instance type and is becoming a Resource type
35432
+ // For now we error because we don't support flavor changes
35433
+ var diff = '';
35434
+
35435
+ {
35436
+ diff = "\n\n - " + describeLinkForResourceErrorDEV(currentProps) + "\n + " + describeLinkForResourceErrorDEV(pendingProps);
35437
+ }
35438
+
35439
+ throw new Error('Expected <link> not to update to be updated to a stylesheet with precedence.' + ' Check the `rel`, `href`, and `precedence` props of this component.' + ' Alternatively, check whether two different <link> components render in the same slot or share the same key.' + diff);
35440
+ }
35441
+
35324
35442
  return _resource;
35325
- }
35443
+ } else {
35444
+ if (currentProps && currentResource !== null) {
35445
+ // This node was previously a Resource type and is becoming an Instance type
35446
+ // For now we error because we don't support flavor changes
35447
+ var _diff = '';
35326
35448
 
35327
- return null;
35449
+ {
35450
+ _diff = "\n\n - " + describeLinkForResourceErrorDEV(currentProps) + "\n + " + describeLinkForResourceErrorDEV(pendingProps);
35451
+ }
35452
+
35453
+ throw new Error('Expected stylesheet with precedence to not be updated to a different kind of <link>.' + ' Check the `rel`, `href`, and `precedence` props of this component.' + ' Alternatively, check whether two different <link> components render in the same slot or share the same key.' + _diff);
35454
+ }
35455
+
35456
+ return null;
35457
+ }
35328
35458
  }
35329
35459
 
35330
35460
  case 'script':
@@ -35367,6 +35497,44 @@ function getResource(type, currentProps, pendingProps) {
35367
35497
  }
35368
35498
  }
35369
35499
 
35500
+ function describeLinkForResourceErrorDEV(props) {
35501
+ {
35502
+ var describedProps = 0;
35503
+ var description = '<link';
35504
+
35505
+ if (typeof props.rel === 'string') {
35506
+ describedProps++;
35507
+ description += " rel=\"" + props.rel + "\"";
35508
+ } else if (hasOwnProperty.call(props, 'rel')) {
35509
+ describedProps++;
35510
+ description += " rel=\"" + (props.rel === null ? 'null' : 'invalid type ' + typeof props.rel) + "\"";
35511
+ }
35512
+
35513
+ if (typeof props.href === 'string') {
35514
+ describedProps++;
35515
+ description += " href=\"" + props.href + "\"";
35516
+ } else if (hasOwnProperty.call(props, 'href')) {
35517
+ describedProps++;
35518
+ description += " href=\"" + (props.href === null ? 'null' : 'invalid type ' + typeof props.href) + "\"";
35519
+ }
35520
+
35521
+ if (typeof props.precedence === 'string') {
35522
+ describedProps++;
35523
+ description += " precedence=\"" + props.precedence + "\"";
35524
+ } else if (hasOwnProperty.call(props, 'precedence')) {
35525
+ describedProps++;
35526
+ description += " precedence={" + (props.precedence === null ? 'null' : 'invalid type ' + typeof props.precedence) + "}";
35527
+ }
35528
+
35529
+ if (Object.getOwnPropertyNames(props).length > describedProps) {
35530
+ description += ' ...';
35531
+ }
35532
+
35533
+ description += ' />';
35534
+ return description;
35535
+ }
35536
+ }
35537
+
35370
35538
  function styleTagPropsFromRawProps(rawProps) {
35371
35539
  return assign({}, rawProps, {
35372
35540
  'data-href': rawProps.href,
@@ -36294,7 +36462,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
36294
36462
  return root;
36295
36463
  }
36296
36464
 
36297
- var ReactVersion = '19.0.0-rc-6d3110b4d9-20240531';
36465
+ var ReactVersion = '19.0.0-rc-9598c41a20-20240603';
36298
36466
 
36299
36467
  function createPortal$1(children, containerInfo, // TODO: figure out the API for cross-renderer implementation.
36300
36468
  implementation) {