@@ -12,7 +12,6 @@ import type { Context } from './context';
12
12
import createReactOutput from './createReactOutput' ;
13
13
import { isServerRenderHash } from './isServerRenderResult' ;
14
14
import reactHydrateOrRender from './reactHydrateOrRender' ;
15
- import { supportsRootApi } from './reactApis' ;
16
15
17
16
/* eslint-disable @typescript-eslint/no-explicit-any */
18
17
@@ -168,9 +167,7 @@ You returned a server side type of react-router error: ${JSON.stringify(reactEle
168
167
You should return a React.Component always for the client side entry point.` ) ;
169
168
} else {
170
169
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 ) ;
174
171
}
175
172
}
176
173
} catch ( e : any ) {
@@ -211,9 +208,7 @@ export function reactOnRailsPageLoaded(): void {
211
208
if ( ! railsContext ) return ;
212
209
213
210
const context = findContext ( ) ;
214
- if ( supportsRootApi ) {
215
- context . roots = [ ] ;
216
- }
211
+ context . roots = [ ] ;
217
212
forEachStore ( context , railsContext ) ;
218
213
forEachReactOnRailsComponentRender ( context , railsContext ) ;
219
214
}
@@ -227,46 +222,23 @@ export function reactOnRailsComponentLoaded(domId: string): void {
227
222
if ( ! railsContext ) return ;
228
223
229
224
const context = findContext ( ) ;
230
- if ( supportsRootApi ) {
231
- context . roots = [ ] ;
232
- }
225
+ context . roots = [ ] ;
233
226
234
227
const el = document . querySelector ( `[data-dom-id=${ domId } ]` ) ;
235
228
if ( ! el ) return ;
236
229
237
230
render ( el , context , railsContext ) ;
238
231
}
239
232
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
-
254
233
function reactOnRailsPageUnloaded ( ) : void {
255
234
debugTurbolinks ( 'reactOnRailsPageUnloaded' ) ;
256
- if ( supportsRootApi ) {
257
- const { roots } = findContext ( ) ;
235
+ const { roots } = findContext ( ) ;
258
236
259
- // If no react on rails components
260
- if ( ! roots ) return ;
237
+ // If no react on rails components
238
+ if ( ! roots ) return ;
261
239
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 ( ) ;
270
242
}
271
243
}
272
244
0 commit comments