From 7f3b02ddf1a52ed019a030ba2a24c7d46180aa98 Mon Sep 17 00:00:00 2001 From: grzdev Date: Fri, 20 Mar 2026 20:24:00 +0100 Subject: [PATCH] fix(examples): guard missing mount targets in remaining react examples --- examples/react/algolia/src/index.tsx | 3 ++- examples/react/basic-graphql-request/src/index.tsx | 3 ++- examples/react/chat/src/index.tsx | 3 ++- examples/react/default-query-function/src/index.tsx | 3 ++- examples/react/devtools-panel/src/index.tsx | 3 ++- examples/react/eslint-legacy/src/index.tsx | 3 ++- examples/react/offline/src/index.tsx | 3 ++- examples/react/playground/src/index.tsx | 3 ++- examples/react/react-router/src/index.tsx | 3 ++- examples/react/suspense/src/index.tsx | 3 ++- 10 files changed, 20 insertions(+), 10 deletions(-) diff --git a/examples/react/algolia/src/index.tsx b/examples/react/algolia/src/index.tsx index 5580576a6b6..7a7be0a6925 100644 --- a/examples/react/algolia/src/index.tsx +++ b/examples/react/algolia/src/index.tsx @@ -2,5 +2,6 @@ import ReactDOM from 'react-dom/client' import App from './App' -const rootElement = document.getElementById('root') as HTMLElement +const rootElement = document.getElementById('root') +if (!rootElement) throw new Error('Missing #root element') ReactDOM.createRoot(rootElement).render() diff --git a/examples/react/basic-graphql-request/src/index.tsx b/examples/react/basic-graphql-request/src/index.tsx index 09995939cd8..af4e81a8d4f 100644 --- a/examples/react/basic-graphql-request/src/index.tsx +++ b/examples/react/basic-graphql-request/src/index.tsx @@ -172,5 +172,6 @@ function Post({ ) } -const rootElement = document.getElementById('root') as HTMLElement +const rootElement = document.getElementById('root') +if (!rootElement) throw new Error('Missing #root element') ReactDOM.createRoot(rootElement).render() diff --git a/examples/react/chat/src/index.tsx b/examples/react/chat/src/index.tsx index 4e95c7b37c3..5ddbcfe5e19 100644 --- a/examples/react/chat/src/index.tsx +++ b/examples/react/chat/src/index.tsx @@ -96,5 +96,6 @@ function Example() { ) } -const rootElement = document.getElementById('root') as HTMLElement +const rootElement = document.getElementById('root') +if (!rootElement) throw new Error('Missing #root element') ReactDOM.createRoot(rootElement).render() diff --git a/examples/react/default-query-function/src/index.tsx b/examples/react/default-query-function/src/index.tsx index 72a45b7f3cf..b3cec50224c 100644 --- a/examples/react/default-query-function/src/index.tsx +++ b/examples/react/default-query-function/src/index.tsx @@ -146,5 +146,6 @@ function Post({ ) } -const rootElement = document.getElementById('root') as HTMLElement +const rootElement = document.getElementById('root') +if (!rootElement) throw new Error('Missing #root element') ReactDOM.createRoot(rootElement).render() diff --git a/examples/react/devtools-panel/src/index.tsx b/examples/react/devtools-panel/src/index.tsx index 7278a000e31..bc2ca5e65dd 100644 --- a/examples/react/devtools-panel/src/index.tsx +++ b/examples/react/devtools-panel/src/index.tsx @@ -54,5 +54,6 @@ function Example() { ) } -const rootElement = document.getElementById('root') as HTMLElement +const rootElement = document.getElementById('root') +if (!rootElement) throw new Error('Missing #root element') ReactDOM.createRoot(rootElement).render() diff --git a/examples/react/eslint-legacy/src/index.tsx b/examples/react/eslint-legacy/src/index.tsx index 59a186be1bb..9ddea366c33 100644 --- a/examples/react/eslint-legacy/src/index.tsx +++ b/examples/react/eslint-legacy/src/index.tsx @@ -157,5 +157,6 @@ function App() { ) } -const rootElement = document.getElementById('root') as HTMLElement +const rootElement = document.getElementById('root') +if (!rootElement) throw new Error('Missing #root element') ReactDOM.createRoot(rootElement).render() diff --git a/examples/react/offline/src/index.tsx b/examples/react/offline/src/index.tsx index d6791b40c19..fd0eb555c85 100644 --- a/examples/react/offline/src/index.tsx +++ b/examples/react/offline/src/index.tsx @@ -5,7 +5,8 @@ import { worker } from './api' worker.start() -const rootElement = document.getElementById('root') as HTMLElement +const rootElement = document.getElementById('root') +if (!rootElement) throw new Error('Missing #root element') ReactDOM.createRoot(rootElement).render(
diff --git a/examples/react/playground/src/index.tsx b/examples/react/playground/src/index.tsx index 8da861804cf..053585522de 100644 --- a/examples/react/playground/src/index.tsx +++ b/examples/react/playground/src/index.tsx @@ -457,5 +457,6 @@ function patchTodo(todo?: Todo): Promise { }) } -const rootElement = document.getElementById('root') as HTMLElement +const rootElement = document.getElementById('root') +if (!rootElement) throw new Error('Missing #root element') ReactDOM.createRoot(rootElement).render() diff --git a/examples/react/react-router/src/index.tsx b/examples/react/react-router/src/index.tsx index e4037015ea1..01cabf89f45 100644 --- a/examples/react/react-router/src/index.tsx +++ b/examples/react/react-router/src/index.tsx @@ -67,7 +67,8 @@ const router = createBrowserRouter([ ]) const rootElement = document.getElementById('root') -ReactDOM.createRoot(rootElement!).render( +if (!rootElement) throw new Error('Missing #root element') +ReactDOM.createRoot(rootElement).render( diff --git a/examples/react/suspense/src/index.tsx b/examples/react/suspense/src/index.tsx index 2402fa9393a..34047650471 100755 --- a/examples/react/suspense/src/index.tsx +++ b/examples/react/suspense/src/index.tsx @@ -90,5 +90,6 @@ function Example() { ) } -const rootElement = document.getElementById('root') as HTMLElement +const rootElement = document.getElementById('root') +if (!rootElement) throw new Error('Missing #root element') ReactDOM.createRoot(rootElement).render()