From 0328d0ade9a4fb0fdd91ccb56d4b817881e8b2b7 Mon Sep 17 00:00:00 2001 From: xiaomage Date: Sun, 20 Sep 2026 14:32:37 +0800 Subject: [PATCH] fix(build): don't block deploys when Algolia sync fails The Algolia sync step ran inside 'npm run build' and any Algolia API error (the app is currently blocked: 'This operation cannot be processed, the application is blocked') failed the whole Cloudflare build, so merged docs never got published. Catch sync errors and continue deploying; the search index just stays stale until the account issue is resolved. Also skip the sync on Cloudflare preview builds (CF_PAGES_BRANCH != main). Each preview re-indexed all ~2.5k pages and burned the Algolia operation quota, which is the likely cause of the block. Verified locally: no-key skip, preview-branch skip, and an Algolia ApiError (invalid key) all exit 0 with a log line; successful sync behavior is unchanged. --- scripts/sync-algolia.mjs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/sync-algolia.mjs b/scripts/sync-algolia.mjs index ceb491f0..d79e95c7 100644 --- a/scripts/sync-algolia.mjs +++ b/scripts/sync-algolia.mjs @@ -11,9 +11,23 @@ if (!adminApiKey) { process.exit(0); } +// Preview builds (pull requests) re-index the whole site on every push and +// burn through the Algolia operation quota; only sync production deploys. +const branch = process.env.CF_PAGES_BRANCH; +if (branch && branch !== "main") { + console.log(`Algolia sync skipped: preview build (branch ${branch})`); + process.exit(0); +} + const content = await readFile("dist/public/algolia-index.json", "utf8"); const documents = JSON.parse(content); const client = algoliasearch(appId, adminApiKey); -await sync(client, { indexName, documents }); -console.log(`Algolia sync: wrote ${documents.length} documents to ${indexName}`); +// A search-index hiccup must never block publishing the docs themselves. +try { + await sync(client, { indexName, documents }); + console.log(`Algolia sync: wrote ${documents.length} documents to ${indexName}`); +} catch (error) { + console.warn(`Algolia sync failed, deploying without re-indexing search: ${error}`); + process.exit(0); +}