From 2f150c82399cf2581b8d07eb05feb0e3c4636dca Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 11 Jun 2026 12:07:24 +0000 Subject: [PATCH] Boost: Critical CSS: don't fail the whole local generation run when one provider errors unexpectedly Previously, any error other than SuccessTargetError thrown while generating Critical CSS for a single provider was re-thrown, aborting generation for all remaining providers and discarding their results. Now such errors are recorded as that provider's errors (via the existing set-provider-errors data-sync action, using the UnknownError type the UI already understands), and generation continues with the remaining providers. Truly global failures (e.g. the generator library failing to load) still abort the run, and SuccessTargetError handling is unchanged. Fixes #38217 https://claude.ai/code/session_01PgpTrtTCH4hpz6Krh3ssho --- .../critical-css/lib/generate-critical-css.ts | 24 ++++++++++++++++--- ...fix-critical-css-provider-error-resilience | 4 ++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 projects/plugins/boost/changelog/fix-critical-css-provider-error-resilience 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.