@@ -20,13 +20,13 @@ type Options = UserOptions<
2020
2121const defaultOpts = {
2222 // required - one or the other or both
23- rootComponent : null ,
24- loadRootComponent : null ,
23+ rootComponent : undefined ,
24+ loadRootComponent : undefined ,
2525
2626 // optional opts
27- renderType : null ,
28- errorBoundary : null ,
29- el : null ,
27+ renderType : undefined ,
28+ errorBoundary : undefined ,
29+ el : undefined ,
3030 canUpdate : true , // by default, allow parcels created with garfish-react-bridge to be updated
3131 suppressComponentDidCatchWarning : false ,
3232 domElements : { } ,
@@ -139,15 +139,21 @@ function mount(opts: Options, appInfo: PropsInfo) {
139139 opts,
140140 } ) ;
141141
142- opts . domElements [ appInfo . appName ] = domElement ;
143- opts . renderResults [ appInfo . appName ] = renderResult ;
142+ if ( opts . domElements ) {
143+ opts . domElements [ appInfo . appName ] = domElement ;
144+ }
145+ if ( opts . renderResults ) {
146+ opts . renderResults [ appInfo . appName ] = renderResult ;
147+ }
144148}
145149
146150function unmount ( opts : Options , appInfo : PropsInfo ) {
147- const root = opts . renderResults [ appInfo . appName ] ;
148- root . unmount ( ) ;
149- delete opts . domElements [ appInfo . appName ] ;
150- delete opts . renderResults [ appInfo . appName ] ;
151+ if ( opts . renderResults ) {
152+ const root = opts . renderResults [ appInfo . appName ] ;
153+ root . unmount ( ) ;
154+ opts . domElements && delete opts . domElements [ appInfo . appName ] ;
155+ delete opts . renderResults [ appInfo . appName ] ;
156+ }
151157}
152158
153159// function update(opts: Options, appInfo: PropsInfo) {
@@ -163,7 +169,7 @@ function unmount(opts: Options, appInfo: PropsInfo) {
163169// });
164170// }
165171
166- function atLeastReact18 ( React : typeReact ) {
172+ function atLeastReact18 ( React ? : typeReact ) {
167173 if (
168174 React &&
169175 typeof React . version === 'string' &&
@@ -198,15 +204,15 @@ function callCreateRoot({ opts, elementToRender, domElement }) {
198204}
199205
200206function getElementToRender ( opts : Options , appInfo : PropsInfo ) {
201- const rootComponentElement = opts . React . createElement (
207+ const rootComponentElement = opts . React ? .createElement (
202208 opts . rootComponent as any ,
203209 appInfo ,
204210 ) ;
205211
206212 let elementToRender = rootComponentElement ;
207213
208214 if ( opts . errorBoundary ) {
209- elementToRender = opts . React . createElement (
215+ elementToRender = opts . React ? .createElement (
210216 createErrorBoundary ( opts ) as any ,
211217 appInfo ,
212218 elementToRender ,
@@ -220,7 +226,7 @@ function createErrorBoundary(opts: Options) {
220226 // to avoid bloat
221227 function GarfishSubAppReactErrorBoundary ( this : any , appInfo : PropsInfo ) {
222228 // super
223- opts . React . Component . apply ( this , arguments ) ;
229+ opts . React ? .Component . apply ( this , arguments ) ;
224230
225231 this . state = {
226232 caughtError : null ,
@@ -232,15 +238,14 @@ function createErrorBoundary(opts: Options) {
232238 ) . displayName = `ReactBridgeReactErrorBoundary(${ appInfo . appName } )` ;
233239 }
234240
235- GarfishSubAppReactErrorBoundary . prototype = Object . create (
236- opts . React . Component . prototype ,
237- ) ;
241+ GarfishSubAppReactErrorBoundary . prototype =
242+ opts . React && Object . create ( opts . React . Component . prototype ) ;
238243
239244 GarfishSubAppReactErrorBoundary . prototype . render = function ( ) {
240245 if ( this . state . caughtError ) {
241246 const errorBoundary = opts . errorBoundary ;
242247
243- return errorBoundary ( this . state . caughtError , this . props ) ;
248+ return errorBoundary && errorBoundary ( this . state . caughtError , this . props ) ;
244249 } else {
245250 return this . props . children ;
246251 }
0 commit comments