You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implements Promise as a valid React node type. When the reconciler
encounters a promise in a child position, it will transparently unwrap
the value before reconciling it. The value of the result will determine
the identity of the child during reconciliation, not the promise itself.
The Server Components response format can take advantage of this feature
by converting lazy child references to promises instead of wrapping them
a `React.lazy` element.
This also fulfills one of the requirements for async components on the
client (note: Server Components can already be written as async
functions). However, we will likely warn and/or lint against this for
the time being because there are major caveats if you re-render an async
component in response to user input.
To suspend, it uses the same algorithm as `use`: by throwing an
exception to unwind the stack, then replaying the begin phase once the
promise resolves. It's a little weird to suspend during reconciliation,
however, `lazy` already does this so if there were any obvious bugs
related to that we likely would have already found them.
Still, the structure is a bit unfortunate. Ideally, we shouldn't need to
replay the entire begin phase of the parent fiber in order to reconcile
the children again. This would require a somewhat significant refactor,
because reconciliation happens deep within the begin phase, and
depending on the type of work, not always at the end. We should consider
as a future improvement.
Unlike `use`, the reconciler will recursively unwrap the value until it
reaches a non-Usable type, e.g. Usable<Usable<Usable<T>>> will resolve
to T.
While eventually we will support all Usable types, Context is not yet
supported because it requires a few more steps. I've left this as a
to-do.
I also haven't yet implemented this in Fizz.
0 commit comments