|
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 */ |
3 | 2 |
|
4 |
| -import * as ReactDOM from 'react-dom'; |
5 | 3 | import type { ReactElement } from 'react';
|
6 |
| -import type { RailsContext, RegisteredComponent, RenderFunction, Root } from './types'; |
| 4 | +import type { RailsContext, RegisteredComponent, RenderFunction, Root } from './types/index.ts'; |
7 | 5 |
|
8 |
| -import { getRailsContext, resetRailsContext } 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'; |
14 |
| -import * as StoreRegistry from './StoreRegistry'; |
15 |
| -import * as ComponentRegistry from './ComponentRegistry'; |
| 6 | +import { getRailsContext, resetRailsContext } from './context.ts'; |
| 7 | +import createReactOutput from './createReactOutput.ts'; |
| 8 | +import { isServerRenderHash } from './isServerRenderResult.ts'; |
| 9 | +import { supportsHydrate, supportsRootApi, unmountComponentAtNode } from './reactApis.cts'; |
| 10 | +import reactHydrateOrRender from './reactHydrateOrRender.ts'; |
| 11 | +import { debugTurbolinks } from './turbolinksUtils.ts'; |
| 12 | +import * as StoreRegistry from './StoreRegistry.ts'; |
| 13 | +import * as ComponentRegistry from './ComponentRegistry.ts'; |
16 | 14 |
|
17 | 15 | const REACT_ON_RAILS_STORE_ATTRIBUTE = 'data-js-react-on-rails-store';
|
18 | 16 |
|
@@ -103,8 +101,7 @@ class ComponentRenderer {
|
103 | 101 | }
|
104 | 102 |
|
105 | 103 | // Hydrate if available and was server rendered
|
106 |
| - // @ts-expect-error potentially present if React 18 or greater |
107 |
| - const shouldHydrate = !!(ReactDOM.hydrate || ReactDOM.hydrateRoot) && !!domNode.innerHTML; |
| 104 | + const shouldHydrate = supportsHydrate && !!domNode.innerHTML; |
108 | 105 |
|
109 | 106 | const reactElementOrRouterResult = createReactOutput({
|
110 | 107 | componentObj,
|
@@ -156,7 +153,8 @@ You should return a React.Component always for the client side entry point.`);
|
156 | 153 | }
|
157 | 154 |
|
158 | 155 | try {
|
159 |
| - ReactDOM.unmountComponentAtNode(domNode); |
| 156 | + // eslint-disable-next-line @typescript-eslint/no-deprecated |
| 157 | + unmountComponentAtNode(domNode); |
160 | 158 | } catch (e: unknown) {
|
161 | 159 | const error = e instanceof Error ? e : new Error('Unknown error');
|
162 | 160 | console.info(
|
|
0 commit comments