fix(image-pipeline): preserve worker errors and skip aborted histograms

This commit is contained in:
Matthias
2026-04-04 11:56:38 +02:00
parent b650485e81
commit d73db3a612
7 changed files with 421 additions and 131 deletions

View File

@@ -99,7 +99,9 @@ function isAbortError(error: unknown): boolean {
}
function handleWorkerFailure(error: Error): void {
workerInitError = error;
const normalized =
error instanceof WorkerUnavailableError ? error : new WorkerUnavailableError(error.message);
workerInitError = normalized;
if (workerInstance) {
workerInstance.terminate();
@@ -107,11 +109,15 @@ function handleWorkerFailure(error: Error): void {
}
for (const [requestId, pending] of pendingRequests.entries()) {
pending.reject(error);
pending.reject(normalized);
pendingRequests.delete(requestId);
}
}
function shouldFallbackToMainThread(error: unknown): error is WorkerUnavailableError {
return error instanceof WorkerUnavailableError;
}
function getWorker(): Worker {
if (typeof window === "undefined" || typeof Worker === "undefined") {
throw new WorkerUnavailableError("Worker API is not available.");
@@ -281,6 +287,10 @@ export async function renderPreviewWithWorkerFallback(options: {
throw error;
}
if (!shouldFallbackToMainThread(error)) {
throw error;
}
return await renderPreview(options);
}
}
@@ -299,6 +309,10 @@ export async function renderFullWithWorkerFallback(
throw error;
}
if (!shouldFallbackToMainThread(error)) {
throw error;
}
return await renderFull(options);
}
}