-
Notifications
You must be signed in to change notification settings - Fork 536
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
Use @react-aria/ssr for isomorphic ID generation. #1409
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f05353e
Use @react-aria/ssr for isomorphic ID generation.
jfuchs 98326a7
cleanup
jfuchs c614ea6
tests
jfuchs 13fe2da
tests
jfuchs 60a8976
tests
jfuchs 2ab4728
Clarify docs
jfuchs 838b035
changeset
jfuchs 25b9c12
bump react-aria/ssr version
jfuchs 623db6c
update snapshots
jfuchs 6aa3eb8
Update docs/content/ssr.mdx
jfuchs 8f85aea
Update docs/content/ssr.mdx
jfuchs 841ad7f
Doc readability
jfuchs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@primer/components': minor | ||
--- | ||
|
||
Use @react-aria/ssr for isomorphic ID generation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: Server-side rendering with Primer React | ||
--- | ||
|
||
## SSR-safe ID generation | ||
|
||
Some primer components generate their own DOM IDs. Those IDs must be unique across the DOM and isomorphic (so that server-side rendering and client-side rendering yield the same ID, avoiding hydration issues). We use [@react-aria/ssr](https://react-spectrum.adobe.com/react-aria/ssr.html) to generate those IDs. In client-only rendering, this doesn't require any additional work. In SSR contexts, you must wrap your application with at least one `<SSRProvider>`: | ||
jfuchs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
``` | ||
import {SSRProvider} from '@primer/components'; | ||
|
||
<SSRProvider> | ||
<MyApplication /> | ||
</SSRProvider> | ||
jfuchs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
`SSRProvider` maintains the context necessary to ensure IDs are consistent. In cases where some parts of the react tree are rendered asynchronously, you should wrap an additional `SSRProvider` around the conditionally rendered elements: | ||
|
||
``` | ||
function MyApplication() { | ||
const [dataA] = useAsyncData('a'); | ||
const [dataB] = useAsyncData('b'); | ||
|
||
return <> | ||
<SSRProvider> | ||
{dataA && <MyComponentA data={dataA} />} | ||
</SSRProvider> | ||
<SSRProvider> | ||
{dataB && <MyComponentB data={dataB} />} | ||
</SSRProvider> | ||
</> | ||
} | ||
``` | ||
|
||
This will ensure that the IDs are consistent for any sequencing of `dataA` and `dataB` being resolved. | ||
|
||
See also [React Aria's server side rendering documentation](https://react-spectrum.adobe.com/react-aria/ssr.html). |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
Thank you for writing docs! 💖
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.
Can you add this doc to the side nav? https://github.com/primer/react/blob/main/docs/src/%40primer/gatsby-theme-doctocat/nav.yml