From 3653802e77067d081391bb99e649665da9d1380c Mon Sep 17 00:00:00 2001 From: grzdev Date: Wed, 4 Mar 2026 20:17:57 +0100 Subject: [PATCH] fix(examples): guard missing mount targets in react examples --- examples/react/basic/src/index.tsx | 3 ++- examples/react/rick-morty/src/index.tsx | 3 ++- examples/react/simple/src/index.tsx | 3 ++- examples/react/star-wars/src/index.tsx | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/react/basic/src/index.tsx b/examples/react/basic/src/index.tsx index 59a186be1bb..9ddea366c33 100644 --- a/examples/react/basic/src/index.tsx +++ b/examples/react/basic/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/rick-morty/src/index.tsx b/examples/react/rick-morty/src/index.tsx index 5482de0621b..066f7751ea3 100644 --- a/examples/react/rick-morty/src/index.tsx +++ b/examples/react/rick-morty/src/index.tsx @@ -1,5 +1,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/simple/src/index.tsx b/examples/react/simple/src/index.tsx index 6a137cb9e26..ba0332f5e6d 100644 --- a/examples/react/simple/src/index.tsx +++ b/examples/react/simple/src/index.tsx @@ -45,5 +45,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/star-wars/src/index.tsx b/examples/react/star-wars/src/index.tsx index 5482de0621b..066f7751ea3 100644 --- a/examples/react/star-wars/src/index.tsx +++ b/examples/react/star-wars/src/index.tsx @@ -1,5 +1,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()