|
1 | 1 | import React, { MutableRefObject } from "react"
|
2 |
| -// @ts-ignore - react 18 has createRoot |
3 |
| -import { hydrate, render, createRoot } from "react-dom" |
| 2 | +import ReactDOM from "react-dom" |
4 | 3 | import { GatsbyImageProps } from "./gatsby-image.browser"
|
5 | 4 | import { LayoutWrapper } from "./layout-wrapper"
|
6 | 5 | import { Placeholder } from "./placeholder"
|
@@ -88,28 +87,33 @@ export function lazyHydrate(
|
88 | 87 |
|
89 | 88 | if (root.current) {
|
90 | 89 | // Force render to mitigate "Expected server HTML to contain a matching" in develop
|
91 |
| - if (createRoot) { |
| 90 | + // @ts-ignore react 18 typings |
| 91 | + if (ReactDOM.createRoot) { |
92 | 92 | if (!hydrated.current) {
|
93 |
| - hydrated.current = createRoot(root.current) |
| 93 | + // @ts-ignore react 18 typings |
| 94 | + hydrated.current = ReactDOM.createRoot(root.current) |
94 | 95 | }
|
95 | 96 |
|
96 | 97 | // @ts-ignore react 18 typings
|
97 | 98 | hydrated.current.render(component)
|
98 | 99 | } else {
|
99 | 100 | const doRender =
|
100 |
| - hydrated.current || forceHydrate.current ? render : hydrate |
| 101 | + hydrated.current || forceHydrate.current |
| 102 | + ? ReactDOM.render |
| 103 | + : ReactDOM.hydrate |
101 | 104 | doRender(component, root.current)
|
102 | 105 | hydrated.current = true
|
103 | 106 | }
|
104 | 107 | }
|
105 | 108 |
|
106 | 109 | return (): void => {
|
107 | 110 | if (root.current) {
|
108 |
| - if (createRoot) { |
| 111 | + // @ts-ignore react 18 typings |
| 112 | + if (ReactDOM.createRoot) { |
109 | 113 | // @ts-ignore react 18 typings
|
110 | 114 | hydrated.current.render(null)
|
111 | 115 | } else {
|
112 |
| - render((null as unknown) as ReactElement, root.current) |
| 116 | + ReactDOM.render((null as unknown) as ReactElement, root.current) |
113 | 117 | }
|
114 | 118 | }
|
115 | 119 | }
|
|
0 commit comments