File tree Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -131,11 +131,8 @@ var ReactRailsUJS = {
131
131
if ( hydrate && supportsHydration ( ) ) {
132
132
component = reactHydrate ( node , component ) ;
133
133
} else {
134
- const root = createReactRootLike ( node )
134
+ const root = this . findOrCreateRoot ( node ) ;
135
135
component = root . render ( component ) ;
136
- if ( supportsRootApi ) {
137
- this . roots . push ( { "node" : node , "root" : root } )
138
- }
139
136
}
140
137
}
141
138
}
@@ -164,6 +161,32 @@ var ReactRailsUJS = {
164
161
detectEvents ( this )
165
162
} ,
166
163
164
+ findOrCreateRoot : function ( node ) {
165
+ var root = this . findRoot ( node ) ;
166
+ if ( ! root ) {
167
+ root = createReactRootLike ( node ) ;
168
+ if ( supportsRootApi ) {
169
+ this . roots . push ( { "node" : node , "root" : root } )
170
+ }
171
+ }
172
+
173
+ return root ;
174
+ } ,
175
+
176
+ findRoot : function ( node ) {
177
+ if ( ! supportsRootApi ) {
178
+ return ;
179
+ }
180
+ var rootElement = this . roots . find (
181
+ function ( rootElement ) {
182
+ return rootElement [ "node" ] && ( rootElement [ "node" ] === node )
183
+ }
184
+ ) ;
185
+ if ( rootElement ) {
186
+ return rootElement [ "root" ] ;
187
+ }
188
+ } ,
189
+
167
190
unmountRoot : function ( node ) {
168
191
var targetRoots = this . roots . filter (
169
192
function ( rootElement ) {
You can’t perform that action at this time.
0 commit comments