Removes onNavigate from transition scope #78605
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Fixes a bug in the Link component where state updates inside an onNavigate callback aren't committed.
Why?
onNavigate
is intended to provide a way to create transition animations and pending states during navigation, but state updates within the handler weren't taking effect due to them being batched with the page state change transition. This made it impossible to properly implement pending UI states using this API, forcing developers to fall back to the less appropriate onClick handler (which had its own issues like triggering when opening links in new tabs).See this comment on #78361 for details.
How?
By removing the onNavigate handler from the transition scope that the navigation action is called within, user's are given the option to determine whether their state update should be priority — not batched with the route update — or a background update — batched with the route update, by whether or not they call
startTransition
themselves in the callback they pass toonNavigate
.Calling
preventDefault()
on the passed event works as before.Fixes #78361