@@ -15,7 +15,6 @@ import type {
1515 AuthenticityHeaders ,
1616 Store ,
1717 StoreGenerator ,
18- ReactOnRailsOptions
1918} from './types' ;
2019import reactHydrateOrRender from './reactHydrateOrRender' ;
2120
@@ -34,14 +33,13 @@ Check your Webpack configuration. Read more at https://github.com/shakacode/reac
3433 /* eslint-enable @typescript-eslint/no-base-to-string */
3534}
3635
37- const DEFAULT_OPTIONS : ReactOnRailsOptions = {
36+ const DEFAULT_OPTIONS = {
3837 traceTurbolinks : false ,
3938 turbo : false ,
40- rscPayloadGenerationUrlPath : '/rsc_payload' ,
4139} ;
4240
4341ctx . ReactOnRails = {
44- options : { ... DEFAULT_OPTIONS } ,
42+ options : { } ,
4543 /**
4644 * Main entry point to using the react-on-rails npm package. This is how Rails will be able to
4745 * find you components for rendering.
@@ -119,29 +117,27 @@ ctx.ReactOnRails = {
119117 * Available Options:
120118 * `traceTurbolinks: true|false Gives you debugging messages on Turbolinks events
121119 * `turbo: true|false Turbo (the follower of Turbolinks) events will be registered, if set to true.
122- * `rscPayloadGenerationUrlPath: string The path or url of the endpoint that will generate the RSC payload.
123120 */
124- setOptions ( newOptions : Partial < ReactOnRailsOptions > ) : void {
125- if ( ! newOptions || typeof newOptions !== 'object' ) {
126- throw new Error ( 'Error calling ReactOnRails.setOptions: newOptions must be a plain object.' ) ;
121+ setOptions ( newOptions : { traceTurbolinks ?: boolean , turbo ?: boolean } ) : void {
122+ if ( typeof newOptions . traceTurbolinks !== 'undefined' ) {
123+ this . options . traceTurbolinks = newOptions . traceTurbolinks ;
124+
125+ // eslint-disable-next-line no-param-reassign
126+ delete newOptions . traceTurbolinks ;
127127 }
128128
129- const validOptionKeys = Object . keys ( DEFAULT_OPTIONS ) ;
130- const providedOptionKeys = Object . keys ( newOptions ) ;
131-
132- const invalidOptions = providedOptionKeys . filter ( key => ! validOptionKeys . includes ( key ) ) ;
133- if ( invalidOptions . length > 0 ) {
129+ if ( typeof newOptions . turbo !== 'undefined' ) {
130+ this . options . turbo = newOptions . turbo ;
131+
132+ // eslint-disable-next-line no-param-reassign
133+ delete newOptions . turbo ;
134+ }
135+
136+ if ( Object . keys ( newOptions ) . length > 0 ) {
134137 throw new Error (
135- `Invalid options passed to ReactOnRails.options: ${ JSON . stringify ( invalidOptions ) } ` ,
138+ `Invalid options passed to ReactOnRails.options: ${ JSON . stringify ( newOptions ) } ` ,
136139 ) ;
137140 }
138-
139- // Filter out undefined values before merging
140- const definedOptions = Object . fromEntries (
141- Object . entries ( newOptions ) . filter ( ( [ _ , value ] ) => value !== undefined )
142- ) ;
143-
144- this . options = { ...this . options , ...definedOptions } ;
145141 } ,
146142
147143 /**
@@ -190,7 +186,7 @@ ctx.ReactOnRails = {
190186 * @param key
191187 * @returns option value
192188 */
193- option ( key : keyof ReactOnRailsOptions ) : string | number | boolean | undefined {
189+ option ( key : string ) : string | number | boolean | undefined {
194190 return this . options [ key ] ;
195191 } ,
196192
@@ -343,12 +339,12 @@ ctx.ReactOnRails = {
343339 } ,
344340
345341 resetOptions ( ) : void {
346- this . options = { ... DEFAULT_OPTIONS } ;
342+ this . options = Object . assign ( { } , DEFAULT_OPTIONS ) ;
347343 } ,
348-
349- isRSCBundle : false ,
350344} ;
351345
346+ ctx . ReactOnRails . resetOptions ( ) ;
347+
352348ClientStartup . clientStartup ( ctx ) ;
353349
354350export * from './types' ;
0 commit comments