react-dom 19.0.0-rc-6d3110b4d9-20240531 → 19.0.0-rc.0

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.
@@ -13873,15 +13873,39 @@ function useThenable(thenable) {
13873
13873
  thenableState = createThenableState();
13874
13874
  }
13875
13875
 
13876
- var result = trackUsedThenable(thenableState, thenable, index);
13876
+ var result = trackUsedThenable(thenableState, thenable, index); // When something suspends with `use`, we replay the component with the
13877
+ // "re-render" dispatcher instead of the "mount" or "update" dispatcher.
13878
+ //
13879
+ // But if there are additional hooks that occur after the `use` invocation
13880
+ // that suspended, they wouldn't have been processed during the previous
13881
+ // attempt. So after we invoke `use` again, we may need to switch from the
13882
+ // "re-render" dispatcher back to the "mount" or "update" dispatcher. That's
13883
+ // what the following logic accounts for.
13884
+ //
13885
+ // TODO: Theoretically this logic only needs to go into the rerender
13886
+ // dispatcher. Could optimize, but probably not be worth it.
13887
+ // This is the same logic as in updateWorkInProgressHook.
13888
+
13889
+ var workInProgressFiber = currentlyRenderingFiber$1;
13890
+ var nextWorkInProgressHook = workInProgressHook === null ? // We're at the beginning of the list, so read from the first hook from
13891
+ // the fiber.
13892
+ workInProgressFiber.memoizedState : workInProgressHook.next;
13893
+
13894
+ if (nextWorkInProgressHook !== null) ; else {
13895
+ // There are no remaining hooks from the previous attempt. We're no longer
13896
+ // in "re-render" mode. Switch to the normal mount or update dispatcher.
13897
+ //
13898
+ // This is the same as the logic in renderWithHooks, except we don't bother
13899
+ // to track the hook types debug information in this case (sufficient to
13900
+ // only do that when nothing suspends).
13901
+ var currentFiber = workInProgressFiber.alternate;
13877
13902
 
13878
- if (currentlyRenderingFiber$1.alternate === null && (workInProgressHook === null ? currentlyRenderingFiber$1.memoizedState === null : workInProgressHook.next === null)) {
13879
- // Initial render, and either this is the first time the component is
13880
- // called, or there were no Hooks called after this use() the previous
13881
- // time (perhaps because it threw). Subsequent Hook calls should use the
13882
- // mount dispatcher.
13883
13903
  {
13884
- ReactSharedInternals.H = HooksDispatcherOnMountInDEV;
13904
+ if (currentFiber !== null && currentFiber.memoizedState !== null) {
13905
+ ReactSharedInternals.H = HooksDispatcherOnUpdateInDEV;
13906
+ } else {
13907
+ ReactSharedInternals.H = HooksDispatcherOnMountInDEV;
13908
+ }
13885
13909
  }
13886
13910
  }
13887
13911
 
@@ -14643,112 +14667,155 @@ function dispatchActionState(fiber, actionQueue, setPendingState, setState, payl
14643
14667
  throw new Error('Cannot update form state while rendering.');
14644
14668
  }
14645
14669
 
14670
+ var currentAction = actionQueue.action;
14671
+
14672
+ if (currentAction === null) {
14673
+ // An earlier action errored. Subsequent actions should not run.
14674
+ return;
14675
+ }
14676
+
14677
+ var actionNode = {
14678
+ payload: payload,
14679
+ action: currentAction,
14680
+ next: null,
14681
+ // circular
14682
+ isTransition: true,
14683
+ status: 'pending',
14684
+ value: null,
14685
+ reason: null,
14686
+ listeners: [],
14687
+ then: function (listener) {
14688
+ // We know the only thing that subscribes to these promises is `use` so
14689
+ // this implementation is simpler than a generic thenable. E.g. we don't
14690
+ // bother to check if the thenable is still pending because `use` already
14691
+ // does that.
14692
+ actionNode.listeners.push(listener);
14693
+ }
14694
+ }; // Check if we're inside a transition. If so, we'll need to restore the
14695
+ // transition context when the action is run.
14696
+
14697
+ var prevTransition = ReactSharedInternals.T;
14698
+
14699
+ if (prevTransition !== null) {
14700
+ // Optimistically update the pending state, similar to useTransition.
14701
+ // This will be reverted automatically when all actions are finished.
14702
+ setPendingState(true); // `actionNode` is a thenable that resolves to the return value of
14703
+ // the action.
14704
+
14705
+ setState(actionNode);
14706
+ } else {
14707
+ // This is not a transition.
14708
+ actionNode.isTransition = false;
14709
+ setState(actionNode);
14710
+ }
14711
+
14646
14712
  var last = actionQueue.pending;
14647
14713
 
14648
14714
  if (last === null) {
14649
14715
  // There are no pending actions; this is the first one. We can run
14650
14716
  // it immediately.
14651
- var newLast = {
14652
- payload: payload,
14653
- action: actionQueue.action,
14654
- next: null // circular
14655
-
14656
- };
14657
- newLast.next = actionQueue.pending = newLast;
14658
- runActionStateAction(actionQueue, setPendingState, setState, newLast);
14717
+ actionNode.next = actionQueue.pending = actionNode;
14718
+ runActionStateAction(actionQueue, actionNode);
14659
14719
  } else {
14660
14720
  // There's already an action running. Add to the queue.
14661
14721
  var first = last.next;
14662
- var _newLast = {
14663
- payload: payload,
14664
- action: actionQueue.action,
14665
- next: first
14666
- };
14667
- actionQueue.pending = last.next = _newLast;
14722
+ actionNode.next = first;
14723
+ actionQueue.pending = last.next = actionNode;
14668
14724
  }
14669
14725
  }
14670
14726
 
14671
- function runActionStateAction(actionQueue, setPendingState, setState, node) {
14672
- // This is a fork of startTransition
14673
- var prevTransition = ReactSharedInternals.T;
14674
- var currentTransition = {};
14675
- ReactSharedInternals.T = currentTransition;
14676
-
14677
- {
14678
- ReactSharedInternals.T._updatedFibers = new Set();
14679
- } // Optimistically update the pending state, similar to useTransition.
14680
- // This will be reverted automatically when all actions are finished.
14681
-
14682
-
14683
- setPendingState(true); // `node.action` represents the action function at the time it was dispatched.
14727
+ function runActionStateAction(actionQueue, node) {
14728
+ // `node.action` represents the action function at the time it was dispatched.
14684
14729
  // If this action was queued, it might be stale, i.e. it's not necessarily the
14685
14730
  // most current implementation of the action, stored on `actionQueue`. This is
14686
14731
  // intentional. The conceptual model for queued actions is that they are
14687
14732
  // queued in a remote worker; the dispatch happens immediately, only the
14688
14733
  // execution is delayed.
14689
-
14690
14734
  var action = node.action;
14691
14735
  var payload = node.payload;
14692
14736
  var prevState = actionQueue.state;
14693
14737
 
14694
- try {
14695
- var returnValue = action(prevState, payload);
14696
- var onStartTransitionFinish = ReactSharedInternals.S;
14738
+ if (node.isTransition) {
14739
+ // The original dispatch was part of a transition. We restore its
14740
+ // transition context here.
14741
+ // This is a fork of startTransition
14742
+ var prevTransition = ReactSharedInternals.T;
14743
+ var currentTransition = {};
14744
+ ReactSharedInternals.T = currentTransition;
14697
14745
 
14698
- if (onStartTransitionFinish !== null) {
14699
- onStartTransitionFinish(currentTransition, returnValue);
14746
+ {
14747
+ ReactSharedInternals.T._updatedFibers = new Set();
14700
14748
  }
14701
14749
 
14702
- if (returnValue !== null && typeof returnValue === 'object' && // $FlowFixMe[method-unbinding]
14703
- typeof returnValue.then === 'function') {
14704
- var thenable = returnValue; // Attach a listener to read the return state of the action. As soon as
14705
- // this resolves, we can run the next action in the sequence.
14750
+ try {
14751
+ var returnValue = action(prevState, payload);
14752
+ var onStartTransitionFinish = ReactSharedInternals.S;
14706
14753
 
14707
- thenable.then(function (nextState) {
14708
- actionQueue.state = nextState;
14709
- finishRunningActionStateAction(actionQueue, setPendingState, setState);
14710
- }, function () {
14711
- return finishRunningActionStateAction(actionQueue, setPendingState, setState);
14712
- });
14713
- setState(thenable);
14714
- } else {
14715
- setState(returnValue);
14716
- var nextState = returnValue;
14717
- actionQueue.state = nextState;
14718
- finishRunningActionStateAction(actionQueue, setPendingState, setState);
14719
- }
14720
- } catch (error) {
14721
- // This is a trick to get the `useActionState` hook to rethrow the error.
14722
- // When it unwraps the thenable with the `use` algorithm, the error
14723
- // will be thrown.
14724
- var rejectedThenable = {
14725
- then: function () {},
14726
- status: 'rejected',
14727
- reason: error // $FlowFixMe: Not sure why this doesn't work
14754
+ if (onStartTransitionFinish !== null) {
14755
+ onStartTransitionFinish(currentTransition, returnValue);
14756
+ }
14728
14757
 
14729
- };
14730
- setState(rejectedThenable);
14731
- finishRunningActionStateAction(actionQueue, setPendingState, setState);
14732
- } finally {
14733
- ReactSharedInternals.T = prevTransition;
14758
+ handleActionReturnValue(actionQueue, node, returnValue);
14759
+ } catch (error) {
14760
+ onActionError(actionQueue, node, error);
14761
+ } finally {
14762
+ ReactSharedInternals.T = prevTransition;
14734
14763
 
14735
- {
14736
- if (prevTransition === null && currentTransition._updatedFibers) {
14737
- var updatedFibersCount = currentTransition._updatedFibers.size;
14764
+ {
14765
+ if (prevTransition === null && currentTransition._updatedFibers) {
14766
+ var updatedFibersCount = currentTransition._updatedFibers.size;
14738
14767
 
14739
- currentTransition._updatedFibers.clear();
14768
+ currentTransition._updatedFibers.clear();
14740
14769
 
14741
- if (updatedFibersCount > 10) {
14742
- 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.');
14770
+ if (updatedFibersCount > 10) {
14771
+ 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.');
14772
+ }
14743
14773
  }
14744
14774
  }
14745
14775
  }
14776
+ } else {
14777
+ // The original dispatch was not part of a transition.
14778
+ try {
14779
+ var _returnValue = action(prevState, payload);
14780
+
14781
+ handleActionReturnValue(actionQueue, node, _returnValue);
14782
+ } catch (error) {
14783
+ onActionError(actionQueue, node, error);
14784
+ }
14746
14785
  }
14747
14786
  }
14748
14787
 
14749
- function finishRunningActionStateAction(actionQueue, setPendingState, setState) {
14750
- // The action finished running. Pop it from the queue and run the next pending
14751
- // action, if there are any.
14788
+ function handleActionReturnValue(actionQueue, node, returnValue) {
14789
+ if (returnValue !== null && typeof returnValue === 'object' && // $FlowFixMe[method-unbinding]
14790
+ typeof returnValue.then === 'function') {
14791
+ var thenable = returnValue; // Attach a listener to read the return state of the action. As soon as
14792
+ // this resolves, we can run the next action in the sequence.
14793
+
14794
+ thenable.then(function (nextState) {
14795
+ onActionSuccess(actionQueue, node, nextState);
14796
+ }, function (error) {
14797
+ return onActionError(actionQueue, node, error);
14798
+ });
14799
+
14800
+ {
14801
+ if (!node.isTransition) {
14802
+ 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`');
14803
+ }
14804
+ }
14805
+ } else {
14806
+ var nextState = returnValue;
14807
+ onActionSuccess(actionQueue, node, nextState);
14808
+ }
14809
+ }
14810
+
14811
+ function onActionSuccess(actionQueue, actionNode, nextState) {
14812
+ // The action finished running.
14813
+ actionNode.status = 'fulfilled';
14814
+ actionNode.value = nextState;
14815
+ notifyActionListeners(actionNode);
14816
+ actionQueue.state = nextState; // Pop the action from the queue and run the next pending action, if there
14817
+ // are any.
14818
+
14752
14819
  var last = actionQueue.pending;
14753
14820
 
14754
14821
  if (last !== null) {
@@ -14762,11 +14829,43 @@ function finishRunningActionStateAction(actionQueue, setPendingState, setState)
14762
14829
  var next = first.next;
14763
14830
  last.next = next; // Run the next action.
14764
14831
 
14765
- runActionStateAction(actionQueue, setPendingState, setState, next);
14832
+ runActionStateAction(actionQueue, next);
14766
14833
  }
14767
14834
  }
14768
14835
  }
14769
14836
 
14837
+ function onActionError(actionQueue, actionNode, error) {
14838
+ // Mark all the following actions as rejected.
14839
+ var last = actionQueue.pending;
14840
+ actionQueue.pending = null;
14841
+
14842
+ if (last !== null) {
14843
+ var first = last.next;
14844
+
14845
+ do {
14846
+ actionNode.status = 'rejected';
14847
+ actionNode.reason = error;
14848
+ notifyActionListeners(actionNode);
14849
+ actionNode = actionNode.next;
14850
+ } while (actionNode !== first);
14851
+ } // Prevent subsequent actions from being dispatched.
14852
+
14853
+
14854
+ actionQueue.action = null;
14855
+ }
14856
+
14857
+ function notifyActionListeners(actionNode) {
14858
+ // Notify React that the action has finished.
14859
+ var listeners = actionNode.listeners;
14860
+
14861
+ for (var i = 0; i < listeners.length; i++) {
14862
+ // This is always a React internal listener, so we don't need to worry
14863
+ // about it throwing.
14864
+ var listener = listeners[i];
14865
+ listener();
14866
+ }
14867
+ }
14868
+
14770
14869
  function actionStateReducer(oldState, newState) {
14771
14870
  return newState;
14772
14871
  }
@@ -18537,14 +18636,22 @@ function updateHostComponent$1(current, workInProgress, renderLanes) {
18537
18636
 
18538
18637
  function updateHostHoistable(current, workInProgress, renderLanes) {
18539
18638
  markRef(current, workInProgress);
18540
- var currentProps = current === null ? null : current.memoizedProps;
18541
- var resource = workInProgress.memoizedState = getResource(workInProgress.type, currentProps, workInProgress.pendingProps);
18542
18639
 
18543
18640
  if (current === null) {
18544
- if (!getIsHydrating() && resource === null) {
18545
- // This is not a Resource Hoistable and we aren't hydrating so we construct the instance.
18546
- workInProgress.stateNode = createHoistableInstance(workInProgress.type, workInProgress.pendingProps, getRootHostContainer(), workInProgress);
18641
+ var resource = getResource(workInProgress.type, null, workInProgress.pendingProps, null);
18642
+
18643
+ if (resource) {
18644
+ workInProgress.memoizedState = resource;
18645
+ } else {
18646
+ if (!getIsHydrating()) {
18647
+ // This is not a Resource Hoistable and we aren't hydrating so we construct the instance.
18648
+ workInProgress.stateNode = createHoistableInstance(workInProgress.type, workInProgress.pendingProps, getRootHostContainer(), workInProgress);
18649
+ }
18547
18650
  }
18651
+ } else {
18652
+ // Get Resource may or may not return a resource. either way we stash the result
18653
+ // on memoized state.
18654
+ workInProgress.memoizedState = getResource(workInProgress.type, current.memoizedProps, workInProgress.pendingProps, current.memoizedState);
18548
18655
  } // Resources never have reconciler managed children. It is possible for
18549
18656
  // the host implementation of getResource to consider children in the
18550
18657
  // resource construction but they will otherwise be discarded. In practice
@@ -26130,29 +26237,28 @@ function completeWork(current, workInProgress, renderLanes) {
26130
26237
  return null;
26131
26238
  }
26132
26239
  } else {
26133
- // We are updating.
26134
- var currentResource = current.memoizedState;
26240
+ // This is an update.
26241
+ if (nextResource) {
26242
+ // This is a Resource
26243
+ if (nextResource !== current.memoizedState) {
26244
+ // we have a new Resource. we need to update
26245
+ markUpdate(workInProgress); // This must come at the very end of the complete phase.
26246
+
26247
+ bubbleProperties(workInProgress); // This must come at the very end of the complete phase, because it might
26248
+ // throw to suspend, and if the resource immediately loads, the work loop
26249
+ // will resume rendering as if the work-in-progress completed. So it must
26250
+ // fully complete.
26135
26251
 
26136
- if (nextResource !== currentResource) {
26137
- // We are transitioning to, from, or between Hoistable Resources
26138
- // and require an update
26139
- markUpdate(workInProgress);
26140
- }
26141
-
26142
- if (nextResource !== null) {
26143
- // This is a Hoistable Resource
26144
- // This must come at the very end of the complete phase.
26145
- bubbleProperties(workInProgress);
26146
-
26147
- if (nextResource === currentResource) {
26148
- workInProgress.flags &= ~MaySuspendCommit;
26149
- } else {
26150
26252
  preloadResourceAndSuspendIfNeeded(workInProgress, nextResource);
26253
+ return null;
26254
+ } else {
26255
+ // This must come at the very end of the complete phase.
26256
+ bubbleProperties(workInProgress);
26257
+ workInProgress.flags &= ~MaySuspendCommit;
26258
+ return null;
26151
26259
  }
26152
-
26153
- return null;
26154
26260
  } else {
26155
- // This is a Hoistable Instance
26261
+ // This is an Instance
26156
26262
  // We may have props to update on the Hoistable instance.
26157
26263
  {
26158
26264
  var oldProps = current.memoizedProps;
@@ -35200,7 +35306,7 @@ function preinitModuleScript(src, options) {
35200
35306
  } // This function is called in begin work and we should always have a currentDocument set
35201
35307
 
35202
35308
 
35203
- function getResource(type, currentProps, pendingProps) {
35309
+ function getResource(type, currentProps, pendingProps, currentResource) {
35204
35310
  var resourceRoot = getCurrentResourceRoot();
35205
35311
 
35206
35312
  if (!resourceRoot) {
@@ -35273,10 +35379,34 @@ function getResource(type, currentProps, pendingProps) {
35273
35379
  }
35274
35380
  }
35275
35381
 
35382
+ if (currentProps && currentResource === null) {
35383
+ // This node was previously an Instance type and is becoming a Resource type
35384
+ // For now we error because we don't support flavor changes
35385
+ var diff = '';
35386
+
35387
+ {
35388
+ diff = "\n\n - " + describeLinkForResourceErrorDEV(currentProps) + "\n + " + describeLinkForResourceErrorDEV(pendingProps);
35389
+ }
35390
+
35391
+ 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);
35392
+ }
35393
+
35276
35394
  return _resource;
35277
- }
35395
+ } else {
35396
+ if (currentProps && currentResource !== null) {
35397
+ // This node was previously a Resource type and is becoming an Instance type
35398
+ // For now we error because we don't support flavor changes
35399
+ var _diff = '';
35278
35400
 
35279
- return null;
35401
+ {
35402
+ _diff = "\n\n - " + describeLinkForResourceErrorDEV(currentProps) + "\n + " + describeLinkForResourceErrorDEV(pendingProps);
35403
+ }
35404
+
35405
+ 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);
35406
+ }
35407
+
35408
+ return null;
35409
+ }
35280
35410
  }
35281
35411
 
35282
35412
  case 'script':
@@ -35319,6 +35449,44 @@ function getResource(type, currentProps, pendingProps) {
35319
35449
  }
35320
35450
  }
35321
35451
 
35452
+ function describeLinkForResourceErrorDEV(props) {
35453
+ {
35454
+ var describedProps = 0;
35455
+ var description = '<link';
35456
+
35457
+ if (typeof props.rel === 'string') {
35458
+ describedProps++;
35459
+ description += " rel=\"" + props.rel + "\"";
35460
+ } else if (hasOwnProperty.call(props, 'rel')) {
35461
+ describedProps++;
35462
+ description += " rel=\"" + (props.rel === null ? 'null' : 'invalid type ' + typeof props.rel) + "\"";
35463
+ }
35464
+
35465
+ if (typeof props.href === 'string') {
35466
+ describedProps++;
35467
+ description += " href=\"" + props.href + "\"";
35468
+ } else if (hasOwnProperty.call(props, 'href')) {
35469
+ describedProps++;
35470
+ description += " href=\"" + (props.href === null ? 'null' : 'invalid type ' + typeof props.href) + "\"";
35471
+ }
35472
+
35473
+ if (typeof props.precedence === 'string') {
35474
+ describedProps++;
35475
+ description += " precedence=\"" + props.precedence + "\"";
35476
+ } else if (hasOwnProperty.call(props, 'precedence')) {
35477
+ describedProps++;
35478
+ description += " precedence={" + (props.precedence === null ? 'null' : 'invalid type ' + typeof props.precedence) + "}";
35479
+ }
35480
+
35481
+ if (Object.getOwnPropertyNames(props).length > describedProps) {
35482
+ description += ' ...';
35483
+ }
35484
+
35485
+ description += ' />';
35486
+ return description;
35487
+ }
35488
+ }
35489
+
35322
35490
  function styleTagPropsFromRawProps(rawProps) {
35323
35491
  return assign({}, rawProps, {
35324
35492
  'data-href': rawProps.href,
@@ -36246,7 +36414,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
36246
36414
  return root;
36247
36415
  }
36248
36416
 
36249
- var ReactVersion = '19.0.0-rc-6d3110b4d9-20240531';
36417
+ var ReactVersion = '19.0.0';
36250
36418
 
36251
36419
  // Might add PROFILE later.
36252
36420