Skip to content

Update transition docs for React 19 #6837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 4, 2024

Conversation

rickhanlonii
Copy link
Member

@rickhanlonii rickhanlonii commented May 5, 2024

Preview

This PR updates the useTransition docs to include actions.

  • Reworks existing content that says it's only sync
  • Updated all the examples with the proper action naming and to use use
  • Adds "Perform non-blocking updates with Actions" to explain actions
  • Adds "Exposing action prop from components" to explain how to expose an action prop
  • Adds troubleshooting for set state after await
  • Adds troubleshooting for out-of-order requests
  • Removes "Marking a state update as a non-blocking Transition ", since there's already a section below

Also makes minor edits to startTransition to use actions.

Copy link

vercel bot commented May 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
19-react-dev ✅ Ready (Inspect) Visit Preview 💬 2 unresolved
✅ 18 resolved
Dec 4, 2024 9:11pm
react-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 4, 2024 9:11pm

Copy link

vercel bot commented May 5, 2024

@rickhanlonii is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@rickhanlonii rickhanlonii changed the title Add async transitions to React 19 docs [WIP] Add async transitions to React 19 docs May 6, 2024
@tom-sherman
Copy link
Contributor

To be honest I really don't see async transitions (with useTransition) being practically adoptable without the race condition handling built in. Without this, they are simply a target for libraries as the queue handling is very tricky.

There are so many footguns with using them on their own that I think there needs to be some massive disclaimer, and for them to be called out as a tool for library and framework authors.

@rickhanlonii
Copy link
Member Author

rickhanlonii commented May 7, 2024

@tom-sherman it's going to be more common for app developers to use useActionState or use components with an action prop like <form> to create an Action, instead of using raw transitions directly. Using async transitions directly is targeted to library developers who intend to write their own queuing logic or component library authors to expose an action prop.

@rickhanlonii
Copy link
Member Author

It's similar to how doing event handlers to submit data on your own is tricky (for example, this case isn't handled in a raw event handler either), and libraries make that easier using raw events and exposing props to limit the complexity to app developers.

@rickhanlonii rickhanlonii marked this pull request as draft May 7, 2024 19:46
@rickhanlonii
Copy link
Member Author

Converting back to WIP, I think there is a better way to explain this.

@rickhanlonii
Copy link
Member Author

Updated this page based on feedback, some notable changes:

  • An Action is not just an async transition, you can have sync actions too (like mutations to local data that doesn't need a network request). The new framing is that the function passed to startTransition (sync or async) is the "action" and by convention if a function is called inside startTransition then it's called an "Action".
  • Added "Perform non-blocking updates with Actions" to explain actions
  • Added "Exposing action prop from components" to explain how to expose an action prop
  • Removed "Marking a state update as a non-blocking Transition ", since there's already a section below for "Building a Suspense-enabled router" for navigation, but I think we need a new usage example for this.
  • Updated all the examples with the proper action naming and to use use

Copy link
Collaborator

@noahlemen noahlemen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added some minor suggestions

@rickhanlonii rickhanlonii changed the title [WIP] Add async transitions to React 19 docs Update transition docs for React 19 Dec 4, 2024
@rickhanlonii rickhanlonii merged commit 3c6c1fd into reactjs:v19 Dec 4, 2024
4 of 6 checks passed
@rickhanlonii rickhanlonii deleted the 19-async-transitions branch December 4, 2024 21:44
rickhanlonii added a commit that referenced this pull request Dec 5, 2024
* Convert "Canary" callouts to "React 19 beta" (#6811)

* Convert "Canary" callouts to "React 19 beta"

* Starting in

* Bump version string

* Bump deploy

* Bump deploy

* Bump deploy

* [19] Remove <NextMajor> callouts (#6844)

* Remove <NextMajor> callouts

* rm if(node)

* Delete removed APIs from 19 docs (#6845)

* Add information about ref handling in strict mode (#6777)

* Add information about DOM ref handling in strict mode

* switch order of ref object / ref callback in strictmode doc

* use 'refs to components' terminology instead of 'DOM refs'

* update references to canary/r19

* Expand usage example and remove badges

---------

Co-authored-by: Rick Hanlon <[email protected]>

* [19] s/"Server Action"/"Server Function" (#7180)

* [19] s/Server Action/Server Function

* Revert /blog and change redirect

* Add note

* Tweak note

* [v19] Update sandboxes to 19 RC (#7196)

* Update transition docs for React 19 (#6837)

* Add async transitions to React 19 docs

* Updates from feedback

* tweaks

* grammar

* Add startTranstion API

* Apply suggestions from code review

Co-authored-by: Noah Lemen <[email protected]>

* Updated

* capitalization

* grammar

---------

Co-authored-by: Noah Lemen <[email protected]>

* [19] Add docs for prerender APIs (#7320)

* Add prerender APIs

* fix code blocks

---------

Co-authored-by: Noah Lemen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants