@@ -12,7 +12,6 @@ import type { Context } from './context';
1212import createReactOutput from './createReactOutput' ;
1313import { isServerRenderHash } from './isServerRenderResult' ;
1414import reactHydrateOrRender from './reactHydrateOrRender' ;
15- import { supportsRootApi } from './reactApis' ;
1615
1716/* eslint-disable @typescript-eslint/no-explicit-any */
1817
@@ -168,9 +167,7 @@ You returned a server side type of react-router error: ${JSON.stringify(reactEle
168167You should return a React.Component always for the client side entry point.` ) ;
169168 } else {
170169 const rootOrElement = reactHydrateOrRender ( domNode , reactElementOrRouterResult as ReactElement , shouldHydrate ) ;
171- if ( supportsRootApi ) {
172- context . roots . push ( rootOrElement as Root ) ;
173- }
170+ context . roots . push ( rootOrElement as Root ) ;
174171 }
175172 }
176173 } catch ( e : any ) {
@@ -211,9 +208,7 @@ export function reactOnRailsPageLoaded(): void {
211208 if ( ! railsContext ) return ;
212209
213210 const context = findContext ( ) ;
214- if ( supportsRootApi ) {
215- context . roots = [ ] ;
216- }
211+ context . roots = [ ] ;
217212 forEachStore ( context , railsContext ) ;
218213 forEachReactOnRailsComponentRender ( context , railsContext ) ;
219214}
@@ -227,46 +222,23 @@ export function reactOnRailsComponentLoaded(domId: string): void {
227222 if ( ! railsContext ) return ;
228223
229224 const context = findContext ( ) ;
230- if ( supportsRootApi ) {
231- context . roots = [ ] ;
232- }
225+ context . roots = [ ] ;
233226
234227 const el = document . querySelector ( `[data-dom-id=${ domId } ]` ) ;
235228 if ( ! el ) return ;
236229
237230 render ( el , context , railsContext ) ;
238231}
239232
240- function unmount ( el : Element ) : void {
241- const domNodeId = domNodeIdForEl ( el ) ;
242- const domNode = document . getElementById ( domNodeId ) ;
243- if ( domNode === null ) {
244- return ;
245- }
246- try {
247- ReactDOM . unmountComponentAtNode ( domNode ) ;
248- } catch ( e : any ) {
249- console . info ( `Caught error calling unmountComponentAtNode: ${ e . message } for domNode` ,
250- domNode , e ) ;
251- }
252- }
253-
254233function reactOnRailsPageUnloaded ( ) : void {
255234 debugTurbolinks ( 'reactOnRailsPageUnloaded' ) ;
256- if ( supportsRootApi ) {
257- const { roots } = findContext ( ) ;
235+ const { roots } = findContext ( ) ;
258236
259- // If no react on rails components
260- if ( ! roots ) return ;
237+ // If no react on rails components
238+ if ( ! roots ) return ;
261239
262- for ( const root of roots ) {
263- root . unmount ( ) ;
264- }
265- } else {
266- const els = reactOnRailsHtmlElements ( ) ;
267- for ( let i = 0 ; i < els . length ; i += 1 ) {
268- unmount ( els [ i ] ) ;
269- }
240+ for ( const root of roots ) {
241+ root . unmount ( ) ;
270242 }
271243}
272244
0 commit comments