Skip to content

Commit b6c1e54

Browse files
authored
Merge pull request #1098 from vorth/resources-once
Defect fix: resources for exporters only loaded once
2 parents 95bf519 + 3d45b2f commit b6c1e54

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

online/src/worker/vzome-worker-static.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,25 @@ const createDesign = async ( report, fieldName ) =>
168168
design = await legacy .newDesign( fieldName, clientEvents( report ) );
169169
report({ type: 'CONTROLLER_CREATED' }); // do we really need this for previewing?
170170
reportDefaultScene( report );
171-
172-
// Support exports that rely on resources being loaded
173-
Promise.all( resourceIndex .map( path => legacy.loadAndInjectResource( path, new URL( `/app/classic/resources/${path}`, baseURL ) ) ) );
174171
} catch (error) {
175172
console.log(`createDesign failure: ${error.message}`);
176173
report({ type: 'ALERT_RAISED', payload: 'Failed to create vZome model.' });
177174
return false;
178175
}
179176
}
180177

178+
let resourcesPromise = null;
179+
180+
export const whenResourcesLoaded = async () =>
181+
{
182+
if ( resourcesPromise === null ) {
183+
// Support exports that rely on resources being loaded
184+
const legacy = await importLegacy();
185+
resourcesPromise = Promise.all( resourceIndex .map( path => legacy.loadAndInjectResource( path, new URL( `/app/classic/resources/${path}`, baseURL ) ) ) );
186+
}
187+
return resourcesPromise;
188+
}
189+
181190
const openDesign = async ( xmlLoading, name, report, debug, polygons, shapshot=DEFAULT_SNAPSHOT ) =>
182191
{
183192
const events = clientEvents( report );
@@ -215,9 +224,6 @@ const openDesign = async ( xmlLoading, name, report, debug, polygons, shapshot=D
215224
console.log( `openDesign failure: ${error.message}` );
216225
report( { type: 'ALERT_RAISED', payload: `Failed to load vZome model: ${error.message}` } );
217226
});
218-
219-
// Support exports that rely on resources being loaded
220-
Promise.all( resourceIndex .map( path => legacy.loadAndInjectResource( path, new URL( `/app/classic/resources/${path}`, baseURL ) ) ) );
221227
} )
222228

223229
.catch( error => {
@@ -485,7 +491,9 @@ onmessage = ({ data }) =>
485491
clientEvents( sendToClient ) .textExported( 'exportText', xml );
486492
return;
487493
}
488-
design.wrapper .doAction( '', 'exportText', payload );
494+
whenResourcesLoaded() .then( () => {
495+
design.wrapper .doAction( '', 'exportText', payload );
496+
} );
489497
break;
490498
}
491499

0 commit comments

Comments
 (0)