@@ -5,7 +5,7 @@ import * as ReactDOM from 'react-dom';
55import type { ReactElement } from 'react' ;
66import type { RailsContext , RegisteredComponent , RenderFunction , Root } from './types' ;
77
8- import { getContextAndRailsContext , resetContextAndRailsContext , type Context } from './context' ;
8+ import { getRailsContext , resetRailsContext } from './context' ;
99import createReactOutput from './createReactOutput' ;
1010import { isServerRenderHash } from './isServerRenderResult' ;
1111import reactHydrateOrRender from './reactHydrateOrRender' ;
@@ -61,23 +61,23 @@ class ComponentRenderer {
6161 const storeDependencies = el . getAttribute ( 'data-store-dependencies' ) ;
6262 const storeDependenciesArray = storeDependencies ? ( JSON . parse ( storeDependencies ) as string [ ] ) : [ ] ;
6363
64- const { context , railsContext } = getContextAndRailsContext ( ) ;
65- if ( ! context || ! railsContext ) return ;
64+ const { railsContext } = getRailsContext ( ) ;
65+ if ( ! railsContext ) return ;
6666
6767 // Wait for all store dependencies to be loaded
6868 this . renderPromise = Promise . all (
69- storeDependenciesArray . map ( ( storeName ) => context . ReactOnRails . getOrWaitForStore ( storeName ) ) ,
69+ storeDependenciesArray . map ( ( storeName ) => globalThis . ReactOnRails . getOrWaitForStore ( storeName ) ) ,
7070 ) . then ( ( ) => {
7171 if ( this . state === 'unmounted' ) return Promise . resolve ( ) ;
72- return this . render ( el , context , railsContext ) ;
72+ return this . render ( el , railsContext ) ;
7373 } ) ;
7474 }
7575
7676 /**
7777 * Used for client rendering by ReactOnRails. Either calls ReactDOM.hydrate, ReactDOM.render, or
7878 * delegates to a renderer registered by the user.
7979 */
80- private async render ( el : Element , context : Context , railsContext : RailsContext ) : Promise < void > {
80+ private async render ( el : Element , railsContext : RailsContext ) : Promise < void > {
8181 // This must match lib/react_on_rails/helper.rb
8282 const name = el . getAttribute ( 'data-component-name' ) || '' ;
8383 const { domNodeId } = this ;
@@ -87,7 +87,7 @@ class ComponentRenderer {
8787 try {
8888 const domNode = document . getElementById ( domNodeId ) ;
8989 if ( domNode ) {
90- const componentObj = await context . ReactOnRails . getOrWaitForComponent ( name ) ;
90+ const componentObj = await globalThis . ReactOnRails . getOrWaitForComponent ( name ) ;
9191 if ( this . state === 'unmounted' ) {
9292 return ;
9393 }
@@ -181,8 +181,8 @@ class StoreRenderer {
181181
182182 constructor ( storeDataElement : Element ) {
183183 this . state = 'hydrating' ;
184- const { context , railsContext } = getContextAndRailsContext ( ) ;
185- if ( ! context || ! railsContext ) {
184+ const { railsContext } = getRailsContext ( ) ;
185+ if ( ! railsContext ) {
186186 return ;
187187 }
188188
@@ -191,22 +191,17 @@ class StoreRenderer {
191191 storeDataElement . textContent !== null
192192 ? ( JSON . parse ( storeDataElement . textContent ) as Record < string , unknown > )
193193 : { } ;
194- this . hydratePromise = this . hydrate ( context , railsContext , name , props ) ;
194+ this . hydratePromise = this . hydrate ( railsContext , name , props ) ;
195195 }
196196
197- private async hydrate (
198- context : Context ,
199- railsContext : RailsContext ,
200- name : string ,
201- props : Record < string , unknown > ,
202- ) {
203- const storeGenerator = await context . ReactOnRails . getOrWaitForStoreGenerator ( name ) ;
197+ private async hydrate ( railsContext : RailsContext , name : string , props : Record < string , unknown > ) {
198+ const storeGenerator = await globalThis . ReactOnRails . getOrWaitForStoreGenerator ( name ) ;
204199 if ( this . state === 'unmounted' ) {
205200 return ;
206201 }
207202
208203 const store = storeGenerator ( props , railsContext ) ;
209- context . ReactOnRails . setStore ( name , store ) ;
204+ globalThis . ReactOnRails . setStore ( name , store ) ;
210205 this . state = 'hydrated' ;
211206 }
212207
@@ -252,7 +247,7 @@ export const renderOrHydrateAllComponents = () =>
252247function unmountAllComponents ( ) : void {
253248 renderedRoots . forEach ( ( root ) => root . unmount ( ) ) ;
254249 renderedRoots . clear ( ) ;
255- resetContextAndRailsContext ( ) ;
250+ resetRailsContext ( ) ;
256251}
257252
258253const storeRenderers = new Map < string , StoreRenderer > ( ) ;
0 commit comments