Skip to content

[Flight] Implement useId hook#24172

Merged
gnoff merged 6 commits intofacebook:mainfrom
gnoff:flight-useid
May 31, 2022
Merged

[Flight] Implement useId hook#24172
gnoff merged 6 commits intofacebook:mainfrom
gnoff:flight-useid

Conversation

@gnoff
Copy link
Copy Markdown
Collaborator

@gnoff gnoff commented Mar 27, 2022

The approach for ids for Flight is different from Fizz/Client where there is a need for determinancy. Flight rendered elements will not be rendered on the client and as such the ids generated in a request only need to be unique. However since FLight does support refetching subtrees it is possible a client will need to patch up a part of the tree rather than replacing the entire thing so it is not safe to use a simple incrementing counter. To solve for this we allow the caller to specify a prefix. On an initial fetch it is likely this will be empty but on refetches or subtrees we expect to have a client useId provide the prefix since it will guaranteed be unique for that subtree and thus for the entire tree. It is also possible that we will automatically provide prefixes based on a client/Fizz useId on refetches

in addition to the core change I also modified the structure of options for renderToReadableStream where onError, context, and the new identifierPrefix are properties of an Options object argument to avoid the clumsiness of a growing list of optional function arguments.

Loading
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