11/* eslint-disable max-classes-per-file */
22
33import type { ReactElement } from 'react' ;
4- import type { RailsContext , RegisteredComponent , RenderFunction , Root } from './types/index.ts' ;
4+ import type { Root } from 'react-dom/client' ;
5+ import type { RailsContext , RegisteredComponent , RenderFunction } from './types/index.ts' ;
56
67import { getRailsContext , resetRailsContext } from './context.ts' ;
78import createReactOutput from './createReactOutput.ts' ;
89import { isServerRenderHash } from './isServerRenderResult.ts' ;
9- import { supportsHydrate , supportsRootApi , unmountComponentAtNode } from './reactApis.cts' ;
1010import reactHydrateOrRender from './reactHydrateOrRender.ts' ;
1111import { debugTurbolinks } from './turbolinksUtils.ts' ;
1212import * as StoreRegistry from './StoreRegistry.ts' ;
@@ -100,8 +100,8 @@ class ComponentRenderer {
100100 return ;
101101 }
102102
103- // Hydrate if available and was server rendered
104- const shouldHydrate = supportsHydrate && ! ! domNode . innerHTML ;
103+ // Hydrate if the node was server rendered
104+ const shouldHydrate = ! ! domNode . innerHTML ;
105105
106106 const reactElementOrRouterResult = createReactOutput ( {
107107 componentObj,
@@ -117,15 +117,12 @@ class ComponentRenderer {
117117You returned a server side type of react-router error: ${ JSON . stringify ( reactElementOrRouterResult ) }
118118You should return a React.Component always for the client side entry point.` ) ;
119119 } else {
120- const rootOrElement = reactHydrateOrRender (
120+ this . root = reactHydrateOrRender (
121121 domNode ,
122122 reactElementOrRouterResult as ReactElement ,
123123 shouldHydrate ,
124124 ) ;
125125 this . state = 'rendered' ;
126- if ( supportsRootApi ) {
127- this . root = rootOrElement as Root ;
128- }
129126 }
130127 }
131128 } catch ( e : unknown ) {
@@ -143,27 +140,8 @@ You should return a React.Component always for the client side entry point.`);
143140 }
144141 this . state = 'unmounted' ;
145142
146- if ( supportsRootApi ) {
147- this . root ?. unmount ( ) ;
148- this . root = undefined ;
149- } else {
150- const domNode = document . getElementById ( this . domNodeId ) ;
151- if ( ! domNode ) {
152- return ;
153- }
154-
155- try {
156- // eslint-disable-next-line @typescript-eslint/no-deprecated
157- unmountComponentAtNode ( domNode ) ;
158- } catch ( e : unknown ) {
159- const error = e instanceof Error ? e : new Error ( 'Unknown error' ) ;
160- console . info (
161- `Caught error calling unmountComponentAtNode: ${ error . message } for domNode` ,
162- domNode ,
163- error ,
164- ) ;
165- }
166- }
143+ this . root ?. unmount ( ) ;
144+ this . root = undefined ;
167145 }
168146
169147 waitUntilRendered ( ) : Promise < void > {
0 commit comments