@@ -45,6 +45,7 @@ export type Scalprum<T extends Record<string, any> = Record<string, any>> = {
4545 pendingPrefetch : {
4646 [ key : string ] : Promise < unknown > ;
4747 } ;
48+ existingScopes : Set < string > ;
4849 exposedModules : {
4950 [ moduleId : string ] : ExposedScalprumModule ;
5051 } ;
@@ -248,6 +249,7 @@ export const initialize = <T extends Record<string, any> = Record<string, any>>(
248249 pendingInjections : { } ,
249250 pendingLoading : { } ,
250251 pendingPrefetch : { } ,
252+ existingScopes : new Set < string > ( ) ,
251253 exposedModules : { } ,
252254 scalprumOptions : defaultOptions ,
253255 api : api || { } ,
@@ -263,7 +265,11 @@ export const removeScalprum = () => {
263265
264266export const getAppData = ( name : string ) : AppMetadata => getScalprum ( ) . appsConfig [ name ] ;
265267
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 ) ;
267273 getScalprum ( ) . exposedModules [ moduleId ] = exposedModule ;
268274} ;
269275
@@ -302,11 +308,23 @@ export async function processManifest(
302308 processor ?: ( manifest : any ) => string [ ] ,
303309) : Promise < void > {
304310 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+
306324 if ( pendingInjection ) {
307325 await pendingInjection ;
308326 const exposedModule = await pluginStore . getExposedModule < ExposedScalprumModule > ( scope , module ) ;
309- setExposedModule ( getModuleIdentifier ( scope , module ) , exposedModule ) ;
327+ setExposedModule ( scope , module , exposedModule ) ;
310328 return ;
311329 }
312330
@@ -361,7 +379,7 @@ export async function processManifest(
361379 await pluginStore . loadPlugin ( sdkManifest ) ;
362380 try {
363381 const exposedModule = await pluginStore . getExposedModule < ExposedScalprumModule > ( scope , module ) ;
364- setExposedModule ( getModuleIdentifier ( scope , module ) , exposedModule ) ;
382+ setExposedModule ( scope , module , exposedModule ) ;
365383 return ;
366384 } catch ( error ) {
367385 clearPendingInjection ( scope ) ;
0 commit comments