From f64bdd1945f09f04dd46c93195912851a6b408ed Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Wed, 17 Apr 2024 12:07:14 +0200 Subject: [PATCH] Get rid of non-null assertion --- sample/create-react-app-5/public/index.html | 2 +- sample/create-react-app-5/src/index.tsx | 8 +++++++- sample/parcel2/index.html | 2 +- sample/parcel2/index.tsx | 8 +++++++- sample/vite/index.html | 2 +- sample/vite/index.tsx | 8 +++++++- sample/webpack5/index.html | 2 +- sample/webpack5/index.tsx | 8 +++++++- test/index.html | 2 +- test/index.tsx | 8 +++++++- 10 files changed, 40 insertions(+), 10 deletions(-) diff --git a/sample/create-react-app-5/public/index.html b/sample/create-react-app-5/public/index.html index b46c97572..33e2510a1 100644 --- a/sample/create-react-app-5/public/index.html +++ b/sample/create-react-app-5/public/index.html @@ -6,6 +6,6 @@ react-pdf sample page -
+
diff --git a/sample/create-react-app-5/src/index.tsx b/sample/create-react-app-5/src/index.tsx index d94d4c5a1..bb3d81417 100644 --- a/sample/create-react-app-5/src/index.tsx +++ b/sample/create-react-app-5/src/index.tsx @@ -2,4 +2,10 @@ import { createRoot } from 'react-dom/client'; import Sample from './Sample'; -createRoot(document.getElementById('react-root')!).render(); +const root = document.getElementById('root'); + +if (!root) { + throw new Error('Could not find root element'); +} + +createRoot(root).render(); diff --git a/sample/parcel2/index.html b/sample/parcel2/index.html index a61064916..7b10e33b6 100644 --- a/sample/parcel2/index.html +++ b/sample/parcel2/index.html @@ -6,7 +6,7 @@ react-pdf sample page -
+
diff --git a/sample/parcel2/index.tsx b/sample/parcel2/index.tsx index d94d4c5a1..bb3d81417 100644 --- a/sample/parcel2/index.tsx +++ b/sample/parcel2/index.tsx @@ -2,4 +2,10 @@ import { createRoot } from 'react-dom/client'; import Sample from './Sample'; -createRoot(document.getElementById('react-root')!).render(); +const root = document.getElementById('root'); + +if (!root) { + throw new Error('Could not find root element'); +} + +createRoot(root).render(); diff --git a/sample/vite/index.html b/sample/vite/index.html index a61064916..7b10e33b6 100644 --- a/sample/vite/index.html +++ b/sample/vite/index.html @@ -6,7 +6,7 @@ react-pdf sample page -
+
diff --git a/sample/vite/index.tsx b/sample/vite/index.tsx index e9d48690b..3c8d66cf4 100644 --- a/sample/vite/index.tsx +++ b/sample/vite/index.tsx @@ -2,4 +2,10 @@ import { createRoot } from 'react-dom/client'; import Sample from './Sample.js'; -createRoot(document.getElementById('react-root')!).render(); +const root = document.getElementById('root'); + +if (!root) { + throw new Error('Could not find root element'); +} + +createRoot(root).render(); diff --git a/sample/webpack5/index.html b/sample/webpack5/index.html index b46c97572..33e2510a1 100644 --- a/sample/webpack5/index.html +++ b/sample/webpack5/index.html @@ -6,6 +6,6 @@ react-pdf sample page -
+
diff --git a/sample/webpack5/index.tsx b/sample/webpack5/index.tsx index d94d4c5a1..bb3d81417 100644 --- a/sample/webpack5/index.tsx +++ b/sample/webpack5/index.tsx @@ -2,4 +2,10 @@ import { createRoot } from 'react-dom/client'; import Sample from './Sample'; -createRoot(document.getElementById('react-root')!).render(); +const root = document.getElementById('root'); + +if (!root) { + throw new Error('Could not find root element'); +} + +createRoot(root).render(); diff --git a/test/index.html b/test/index.html index 157885ba7..5d799a77e 100644 --- a/test/index.html +++ b/test/index.html @@ -6,7 +6,7 @@ react-pdf test page -
+
diff --git a/test/index.tsx b/test/index.tsx index caf8bfe27..fabd14fe9 100644 --- a/test/index.tsx +++ b/test/index.tsx @@ -3,7 +3,13 @@ import { createRoot } from 'react-dom/client'; import Test from './Test.js'; -createRoot(document.getElementById('react-root')!).render( +const root = document.getElementById('root'); + +if (!root) { + throw new Error('Could not find root element'); +} + +createRoot(root).render( ,