-
Notifications
You must be signed in to change notification settings - Fork 47.9k
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
[Flight] Basic Streaming Suspense Support #17285
Conversation
When something suspends a new chunk is created.
The WHATWG API is designed to be pulled recursively. We should refactor to favor that approach.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 387c233:
|
Size changes (stable)ReactDOM: size: 🔺+62.2%, gzip: 🔺+58.2% Details of bundled changes.Comparing: 62ef250...387c233 react-dom
react-server
react-flight
|
Size changes (experimental)ReactDOM: size: 0.0%, gzip: -0.0% Details of bundled changes.Comparing: 62ef250...387c233 react-dom
react-server
react-flight
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Want to add tests?
x.then(ping, ping); | ||
return; | ||
} else { | ||
// This errored, we need to serialize this error to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to the...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thing
If connection dies, how do I implement a Retry button? |
Error boundary and do the request from the root again. |
Let me rephrase the tests question. Do you want me to write tests? 😄 |
I can also just make an app.. |
If you want to write tests that would be great. Like the suspending and error cases. |
Cool, I'll do that. |
This adds basic Suspense support to Flight by streaming the response.
First it sends one line with the root JSON model. Within the model holes are replaced with "$" followed by a hex ID. E.g. "$12AB3".
Subsequent lines begin with "J" followed by a hex ID.
So an example response may look something like:
The client suspends if you try to access an unresolved value. Once a new line comes in it unsuspends that part of the model.
Currently this suspending is implemented as a getter but it could also be a Proxy. However, more likely is that we'll hide this behind an explicit API that unwraps both components and its data in the future.
Errors
If the server errors while rendering one of the models that error is encoded with an "E" prefix:
When this happens, the previously suspended part of the model now resolves and starts throwing an error on the client. This will then be caught by an error boundary on the client. Unrelated parts of the response can still continue rendering though.
If the connection dies, then all remaining pending promises resolve and start throwing an error which are caught by error boundaries. Previously resolved parts don't error though.
There's a prioritization scheme so errors are emitted at lower priority in the stream than models.
Future Additions
I added a comment describing the protocol. The protocol also includes space for a few other types of data.