diff --git a/projects/plugins/boost/app/assets/src/js/features/critical-css/lib/generate-critical-css.ts b/projects/plugins/boost/app/assets/src/js/features/critical-css/lib/generate-critical-css.ts index 6474dd43ddff..972ad9b65f6b 100644 --- a/projects/plugins/boost/app/assets/src/js/features/critical-css/lib/generate-critical-css.ts +++ b/projects/plugins/boost/app/assets/src/js/features/critical-css/lib/generate-critical-css.ts @@ -181,7 +181,9 @@ async function createBrowserInterface( /** * Generate Critical CSS for the specified Provider Keys, sending each block - * to the server. Throws on error or cancellation. + * to the server. Per-provider errors are recorded against the offending + * provider and do not stop the remaining providers from generating. Only + * throws on global failures (e.g. the generator library failing to load). * * @param {Object} providers - Set of URLs to use for each provider key * @param {Viewport[]} viewports - Viewports to use when generating Critical CSS. @@ -312,11 +314,17 @@ async function generateForKeys( recordBoostEvent( 'critical_css_url_error', eventProps ); } } else { + // Swallow errors caused by cancelling the process. + if ( signal.aborted ) { + return; + } + + stepsFailed++; const stdError = standardizeError( err ); const type = ( 'type' in stdError && typeof stdError.type === 'string' && stdError.type ) || 'unknown'; - // Track showstopper Critical CSS generation error. + // Track unexpected per-provider Critical CSS generation error. const eventProps = { time: Date.now() - startTime, provider_key: key, @@ -326,7 +334,17 @@ async function generateForKeys( recordBoostEvent( 'critical_css_failure', eventProps ); - throw err; + // Record the error against this provider, and continue generating + // Critical CSS for the remaining providers. + await callbacks.setProviderErrors( + key, + urls.map( url => ( { + url, + message: stdError.message, + type: 'UnknownError', + meta: {}, + } ) ) + ); } } finally { // Always increment provider index and update boundary progress, diff --git a/projects/plugins/boost/changelog/fix-critical-css-provider-error-resilience b/projects/plugins/boost/changelog/fix-critical-css-provider-error-resilience new file mode 100644 index 000000000000..e4bfe0cdf085 --- /dev/null +++ b/projects/plugins/boost/changelog/fix-critical-css-provider-error-resilience @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Critical CSS: continue generating for remaining providers when one provider fails unexpectedly, instead of failing the whole run.