Skip to content

Commit 2ab4728

Browse files
committed
Clarify docs
1 parent 60a8976 commit 2ab4728

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

docs/content/ssr.mdx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,34 @@ title: Server-side rendering with Primer React
44

55
## SSR-safe ID generation
66

7-
Some primer components generate IDs for elements that unique and are isomorphic (server-side rendering and client-side rendering are the same). 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 work. In SSR contexts, you must wrap your application with `<SSRProvider>`:
7+
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>`:
88

99
```
10-
<SSRProvider></SSRProvider>
10+
import {SSRProvider} from '@primer/components';
11+
12+
<SSRProvider>
13+
<MyApplication />
14+
</SSRProvider>
15+
```
16+
17+
`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:
18+
1119
```
20+
function MyApplication() {
21+
const [dataA] = useAsyncData('a');
22+
const [dataB] = useAsyncData('b');
23+
24+
return <>
25+
<SSRProvider>
26+
{dataA && <MyComponentA data={dataA} />}
27+
</SSRProvider>
28+
<SSRProvider>
29+
{dataB && <MyComponentB data={dataB} />}
30+
</SSRProvider>
31+
</>
32+
}
33+
```
34+
35+
This will ensure that the IDs are consistent for any sequencing of `dataA` and `dataB` being resolved.
1236

13-
SSRProvider maintains the context necessary to ensure IDs are consistent.
37+
See also [React Aria's server side rendering documentation](https://react-spectrum.adobe.com/react-aria/ssr.html).

0 commit comments

Comments
 (0)