Skip to content

Commit c7c0cd9

Browse files
authored
fix(examples): guard missing mount targets in remaining react examples (#10305)
1 parent 4d7de83 commit c7c0cd9

10 files changed

Lines changed: 20 additions & 10 deletions

File tree

examples/react/algolia/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import ReactDOM from 'react-dom/client'
22

33
import App from './App'
44

5-
const rootElement = document.getElementById('root') as HTMLElement
5+
const rootElement = document.getElementById('root')
6+
if (!rootElement) throw new Error('Missing #root element')
67
ReactDOM.createRoot(rootElement).render(<App />)

examples/react/basic-graphql-request/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,6 @@ function Post({
172172
)
173173
}
174174

175-
const rootElement = document.getElementById('root') as HTMLElement
175+
const rootElement = document.getElementById('root')
176+
if (!rootElement) throw new Error('Missing #root element')
176177
ReactDOM.createRoot(rootElement).render(<App />)

examples/react/chat/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@ function Example() {
9696
)
9797
}
9898

99-
const rootElement = document.getElementById('root') as HTMLElement
99+
const rootElement = document.getElementById('root')
100+
if (!rootElement) throw new Error('Missing #root element')
100101
ReactDOM.createRoot(rootElement).render(<App />)

examples/react/default-query-function/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,6 @@ function Post({
146146
)
147147
}
148148

149-
const rootElement = document.getElementById('root') as HTMLElement
149+
const rootElement = document.getElementById('root')
150+
if (!rootElement) throw new Error('Missing #root element')
150151
ReactDOM.createRoot(rootElement).render(<App />)

examples/react/devtools-panel/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ function Example() {
5454
)
5555
}
5656

57-
const rootElement = document.getElementById('root') as HTMLElement
57+
const rootElement = document.getElementById('root')
58+
if (!rootElement) throw new Error('Missing #root element')
5859
ReactDOM.createRoot(rootElement).render(<App />)

examples/react/eslint-legacy/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,6 @@ function App() {
157157
)
158158
}
159159

160-
const rootElement = document.getElementById('root') as HTMLElement
160+
const rootElement = document.getElementById('root')
161+
if (!rootElement) throw new Error('Missing #root element')
161162
ReactDOM.createRoot(rootElement).render(<App />)

examples/react/offline/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { worker } from './api'
55

66
worker.start()
77

8-
const rootElement = document.getElementById('root') as HTMLElement
8+
const rootElement = document.getElementById('root')
9+
if (!rootElement) throw new Error('Missing #root element')
910
ReactDOM.createRoot(rootElement).render(
1011
<div style={{ padding: '16px' }}>
1112
<App />

examples/react/playground/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,5 +457,6 @@ function patchTodo(todo?: Todo): Promise<Todo> {
457457
})
458458
}
459459

460-
const rootElement = document.getElementById('root') as HTMLElement
460+
const rootElement = document.getElementById('root')
461+
if (!rootElement) throw new Error('Missing #root element')
461462
ReactDOM.createRoot(rootElement).render(<Root />)

examples/react/react-router/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ const router = createBrowserRouter([
6767
])
6868

6969
const rootElement = document.getElementById('root')
70-
ReactDOM.createRoot(rootElement!).render(
70+
if (!rootElement) throw new Error('Missing #root element')
71+
ReactDOM.createRoot(rootElement).render(
7172
<React.StrictMode>
7273
<QueryClientProvider client={queryClient}>
7374
<RouterProvider router={router} />

examples/react/suspense/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,6 @@ function Example() {
9090
)
9191
}
9292

93-
const rootElement = document.getElementById('root') as HTMLElement
93+
const rootElement = document.getElementById('root')
94+
if (!rootElement) throw new Error('Missing #root element')
9495
ReactDOM.createRoot(rootElement).render(<App />)

0 commit comments

Comments
 (0)