|
1 | 1 | /* eslint-disable max-classes-per-file */ |
2 | | -/* eslint-disable react/no-deprecated,@typescript-eslint/no-deprecated -- while we need to support React 16 */ |
| 2 | +/* eslint-disable @typescript-eslint/no-deprecated -- while we need to support React 16 */ |
3 | 3 |
|
4 | | -import * as ReactDOM from 'react-dom'; |
5 | 4 | import type { ReactElement } from 'react'; |
6 | | -import type { RailsContext, RegisteredComponent, RenderFunction, Root } from './types'; |
| 5 | +import type { RailsContext, RegisteredComponent, RenderFunction, Root } from './_types.ts'; |
7 | 6 |
|
8 | | -import { getContextAndRailsContext, resetContextAndRailsContext, type Context } from './context'; |
9 | | -import createReactOutput from './createReactOutput'; |
10 | | -import { isServerRenderHash } from './isServerRenderResult'; |
11 | | -import reactHydrateOrRender from './reactHydrateOrRender'; |
12 | | -import { supportsRootApi } from './reactApis'; |
13 | | -import { debugTurbolinks } from './turbolinksUtils'; |
| 7 | +import { getContextAndRailsContext, resetContextAndRailsContext, type Context } from './context.ts'; |
| 8 | +import createReactOutput from './createReactOutput.ts'; |
| 9 | +import { isServerRenderHash } from './isServerRenderResult.ts'; |
| 10 | +import { reactHydrateOrRender } from './reactHydrateOrRender.cts'; |
| 11 | +import { canHydrate, unmountComponentAtNode, supportsRootApi } from './reactApis.cts'; |
| 12 | +import { debugTurbolinks } from './turbolinksUtils.ts'; |
14 | 13 |
|
15 | 14 | const REACT_ON_RAILS_STORE_ATTRIBUTE = 'data-js-react-on-rails-store'; |
16 | 15 |
|
@@ -101,8 +100,7 @@ class ComponentRenderer { |
101 | 100 | } |
102 | 101 |
|
103 | 102 | // Hydrate if available and was server rendered |
104 | | - // @ts-expect-error potentially present if React 18 or greater |
105 | | - const shouldHydrate = !!(ReactDOM.hydrate || ReactDOM.hydrateRoot) && !!domNode.innerHTML; |
| 103 | + const shouldHydrate = canHydrate && !!domNode.innerHTML; |
106 | 104 |
|
107 | 105 | const reactElementOrRouterResult = createReactOutput({ |
108 | 106 | componentObj, |
@@ -154,7 +152,7 @@ You should return a React.Component always for the client side entry point.`); |
154 | 152 | } |
155 | 153 |
|
156 | 154 | try { |
157 | | - ReactDOM.unmountComponentAtNode(domNode); |
| 155 | + unmountComponentAtNode(domNode); |
158 | 156 | } catch (e: unknown) { |
159 | 157 | const error = e instanceof Error ? e : new Error('Unknown error'); |
160 | 158 | console.info( |
|
0 commit comments