Skip to content

Commit 05771b1

Browse files
authored
docs(examples): guard the react shadow-dom mount target (#10431)
1 parent c945694 commit 05771b1

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

examples/react/shadow-dom/src/main.tsx

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,29 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
66
import { DogList } from './DogList'
77

88
const appRoot = document.getElementById('root')
9+
if (!appRoot) throw new Error('Missing #root element')
910

10-
if (appRoot) {
11-
const queryClient = new QueryClient()
12-
const shadowRoot = appRoot.attachShadow({ mode: 'open' })
13-
const root = ReactDOM.createRoot(shadowRoot)
11+
const queryClient = new QueryClient()
12+
const shadowRoot = appRoot.attachShadow({ mode: 'open' })
13+
const root = ReactDOM.createRoot(shadowRoot)
1414

15-
root.render(
16-
<React.StrictMode>
17-
<QueryClientProvider client={queryClient}>
18-
<div
19-
style={{
20-
width: '100vw',
21-
padding: '30px',
22-
}}
23-
>
24-
<h2>Dog Breeds</h2>
25-
<DogList />
26-
</div>
27-
<ReactQueryDevtools
28-
initialIsOpen={false}
29-
buttonPosition="bottom-left"
30-
shadowDOMTarget={appRoot.shadowRoot!}
31-
/>
32-
</QueryClientProvider>
33-
</React.StrictMode>,
34-
)
35-
}
15+
root.render(
16+
<React.StrictMode>
17+
<QueryClientProvider client={queryClient}>
18+
<div
19+
style={{
20+
width: '100vw',
21+
padding: '30px',
22+
}}
23+
>
24+
<h2>Dog Breeds</h2>
25+
<DogList />
26+
</div>
27+
<ReactQueryDevtools
28+
initialIsOpen={false}
29+
buttonPosition="bottom-left"
30+
shadowDOMTarget={shadowRoot}
31+
/>
32+
</QueryClientProvider>
33+
</React.StrictMode>,
34+
)

0 commit comments

Comments
 (0)