@@ -145,7 +145,9 @@ class ModuleJobBase {
145145 */
146146 syncLink ( requestType ) {
147147 // Store itself into the cache first before linking in case there are circular
148- // references in the linking.
148+ // references in the linking. Track whether we're overwriting an existing entry
149+ // so we know whether to remove the temporary entry in the finally block.
150+ const hadPreviousEntry = this . loader . loadCache . get ( this . url , this . type ) !== undefined ;
149151 this . loader . loadCache . set ( this . url , this . type , this ) ;
150152 const moduleRequests = this . module . getModuleRequests ( ) ;
151153 // Modules should be aligned with the moduleRequests array in order.
@@ -169,9 +171,14 @@ class ModuleJobBase {
169171 }
170172 this . module . link ( modules ) ;
171173 } finally {
172- // Restore it - if it succeeds, we'll reset in the caller; Otherwise it's
173- // not cached and if the error is caught, subsequent attempt would still fail.
174- this . loader . loadCache . delete ( this . url , this . type ) ;
174+ if ( ! hadPreviousEntry ) {
175+ // Remove the temporary entry. On failure this ensures subsequent attempts
176+ // don't return a broken job. On success the caller
177+ // (#getOrCreateModuleJobAfterResolve) will re-insert under the correct key.
178+ this . loader . loadCache . delete ( this . url , this . type ) ;
179+ }
180+ // If there was a previous entry (ensurePhase() path), leave this in cache -
181+ // it is the upgraded job and the caller will not re-insert.
175182 }
176183
177184 return evaluationDepJobs ;
0 commit comments