From 040f8286e97eab7aac23a89d5f59967be3bf8f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Wed, 2 Apr 2025 10:49:44 -0400 Subject: [PATCH] Follow through all the phases when an error happens during snapshotting (#32803) This can happen for example if you have duplicate names in the "old" state. This errors the transition before the updateCallback is invoked so we haven't yet applied mutations etc. This runs through those phases after the error to get us back to a consistent state. --- .../src/client/ReactFiberConfigDOM.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js index 4cad08575f..8b7b552238 100644 --- a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js +++ b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js @@ -1802,6 +1802,12 @@ export function startViewTransition( } } finally { // Continue the reset of the work. + // If the error happened in the snapshot phase before the update callback + // was invoked, then we need to first finish the mutation and layout phases. + // If they're already invoked it's still safe to call them due the status check. + mutationCallback(); + layoutCallback(); + // Skip afterMutationCallback() since we're not animating. spawnedWorkCallback(); } }; @@ -2137,7 +2143,13 @@ export function startGestureTransition( } } finally { // Continue the reset of the work. - readyCallback(); + // If the error happened in the snapshot phase before the update callback + // was invoked, then we need to first finish the mutation and layout phases. + // If they're already invoked it's still safe to call them due the status check. + mutationCallback(); + // Skip readyCallback() and go straight to animateCallbck() since we're not animating. + // animateCallback() is still required to restore states. + animateCallback(); } }; transition.ready.then(readyForAnimations, handleError);