@@ -45,6 +45,7 @@ export type Scalprum<T extends Record<string, any> = Record<string, any>> = {
45
45
pendingPrefetch : {
46
46
[ key : string ] : Promise < unknown > ;
47
47
} ;
48
+ existingScopes : Set < string > ;
48
49
exposedModules : {
49
50
[ moduleId : string ] : ExposedScalprumModule ;
50
51
} ;
@@ -248,6 +249,7 @@ export const initialize = <T extends Record<string, any> = Record<string, any>>(
248
249
pendingInjections : { } ,
249
250
pendingLoading : { } ,
250
251
pendingPrefetch : { } ,
252
+ existingScopes : new Set < string > ( ) ,
251
253
exposedModules : { } ,
252
254
scalprumOptions : defaultOptions ,
253
255
api : api || { } ,
@@ -263,7 +265,11 @@ export const removeScalprum = () => {
263
265
264
266
export const getAppData = ( name : string ) : AppMetadata => getScalprum ( ) . appsConfig [ name ] ;
265
267
266
- const setExposedModule = ( moduleId : string , exposedModule : ExposedScalprumModule ) => {
268
+ const setExposedModule = ( scope : string , module : string , exposedModule : ExposedScalprumModule ) => {
269
+ if ( ! getScalprum ( ) . existingScopes . has ( scope ) ) {
270
+ getScalprum ( ) . existingScopes . add ( scope ) ;
271
+ }
272
+ const moduleId = getModuleIdentifier ( scope , module ) ;
267
273
getScalprum ( ) . exposedModules [ moduleId ] = exposedModule ;
268
274
} ;
269
275
@@ -302,11 +308,23 @@ export async function processManifest(
302
308
processor ?: ( manifest : any ) => string [ ] ,
303
309
) : Promise < void > {
304
310
let pendingInjection = getPendingInjection ( scope ) ;
305
- const { pluginStore } = getScalprum ( ) ;
311
+ const { pluginStore, existingScopes } = getScalprum ( ) ;
312
+
313
+ if ( existingScopes . has ( scope ) ) {
314
+ try {
315
+ const exposedModule = await pluginStore . getExposedModule < ExposedScalprumModule > ( scope , module ) ;
316
+ setExposedModule ( scope , module , exposedModule ) ;
317
+ return ;
318
+ } catch ( error ) {
319
+ console . warn ( 'Unable to load module from existing container' , error ) ;
320
+ console . warn ( 'Scalprum will try to process manifest from scratch.' ) ;
321
+ }
322
+ }
323
+
306
324
if ( pendingInjection ) {
307
325
await pendingInjection ;
308
326
const exposedModule = await pluginStore . getExposedModule < ExposedScalprumModule > ( scope , module ) ;
309
- setExposedModule ( getModuleIdentifier ( scope , module ) , exposedModule ) ;
327
+ setExposedModule ( scope , module , exposedModule ) ;
310
328
return ;
311
329
}
312
330
@@ -361,7 +379,7 @@ export async function processManifest(
361
379
await pluginStore . loadPlugin ( sdkManifest ) ;
362
380
try {
363
381
const exposedModule = await pluginStore . getExposedModule < ExposedScalprumModule > ( scope , module ) ;
364
- setExposedModule ( getModuleIdentifier ( scope , module ) , exposedModule ) ;
382
+ setExposedModule ( scope , module , exposedModule ) ;
365
383
return ;
366
384
} catch ( error ) {
367
385
clearPendingInjection ( scope ) ;
0 commit comments