diff --git a/builder/cpu-worker.mjs b/builder/cpu-worker.mjs index 4950f78a6..359a5ca98 100644 --- a/builder/cpu-worker.mjs +++ b/builder/cpu-worker.mjs @@ -55,11 +55,12 @@ let _payloadSAB = null; // SharedArrayBuffer with packed per-task payloads let _sharedSAB = null; // SharedArrayBuffer with packed shared payload let _shared = null; // _sharedSAB decoded, once per lane -// What dispatch broadcast. A task that reads it runs after dispatch, so the -// SAB is here by then; renderEnvInit, which can be claimed earlier, waits -// for it first. -function sharedData() { - if (!_sharedSAB) throw new Error("the shared payload was read before dispatch broadcast it"); +// What dispatch broadcast. A task that reads it runs after dispatch, but the +// message is not here by then: this lane may still be inside the pull loop +// that claimed the task, so yield until it lands, as taskData does. A +// searchIndex claimed that way threw here. +async function sharedData() { + while (!_sharedSAB) await new Promise((resolve) => setImmediate(resolve)); _shared ??= unpackShared(_sharedSAB); return _shared; } @@ -74,10 +75,6 @@ const handlers = { }, async renderEnvInit() { - while (!_sharedSAB) { - await new Promise((resolve) => setImmediate(resolve)); - } - const { siteData, initData, @@ -95,7 +92,7 @@ const handlers = { pictureSizes, counts, downloads, - } = sharedData(); + } = await sharedData(); const { initHighlighter } = await import("./highlight.mjs"); const highlighter = await initHighlighter(); @@ -227,7 +224,7 @@ const handlers = { // pages are written, and it needs nothing from the main thread that // dispatch has not already broadcast: it reads the offline tree from disk. async helpArchive() { - const { skipOffline } = sharedData(); + const { skipOffline } = await sharedData(); return helpArchiveStep({ src: path.relative(REPO_ROOT, ctx.srcRoot).replaceAll(path.sep, "/"), offlineRoot: skipOffline ? null : `${ctx.destRoot}-offline`, @@ -244,7 +241,7 @@ const handlers = { // offline tree. It builds on threads of its own (search-index.mjs). async searchIndex() { if (ctx.opts.dryRun) return { entries: 0, workers: 0, bytes: 0 }; - const { skipOffline } = sharedData(); + const { skipOffline } = await sharedData(); return writeSearchIndex(ctx.destRoot, { offline: !skipOffline }); }, diff --git a/builder/link-check.mjs b/builder/link-check.mjs index 24c96fe67..cb0b3c2f5 100644 --- a/builder/link-check.mjs +++ b/builder/link-check.mjs @@ -864,6 +864,16 @@ export function settleFragments(pendingFragments, idsByTarget) { // generator rather than being re-derived here. const EXCLUDE = new Set(["book.html", "404.html"]); +// nav.html, the whole nav tree (template.mjs, renderNavTreePage), is no page +// of the site's: the sitemap and the search index leave it out, and it has no +// canonical. Only the tree's root one: a page elsewhere may have that name. +// The build hands it to the check with the redirect stubs, which leaves it out +// already; a tree read from disk does not say so. +const ROOT_EXCLUDE = new Set(["nav.html"]); + +function excluded(rel) { + return EXCLUDE.has(path.posix.basename(rel)) || ROOT_EXCLUDE.has(rel); +} // Every page (except the exclusions) should appear in sitemap.xml. export function checkSitemap(xml, relFiles, basePath, optOut = null) { @@ -885,7 +895,7 @@ export function checkSitemap(xml, relFiles, basePath, optOut = null) { const issues = []; for (const rel of relFiles) { - if (EXCLUDE.has(path.posix.basename(rel))) continue; + if (excluded(rel)) continue; if (optOut?.has(rel)) continue; const urlPath = deriveUrlPath(rel); if (!sitemapPaths.has(urlPath)) issues.push(`${rel}: sitemap-missing: ${urlPath}`); @@ -907,7 +917,7 @@ export function checkSearch(searchData, relFiles, basePath, optOut = null) { const issues = []; for (const rel of relFiles) { - if (EXCLUDE.has(path.posix.basename(rel))) continue; + if (excluded(rel)) continue; if (optOut?.has(rel)) continue; const urlPath = deriveUrlPath(rel); if (!searchPageUrls.has(urlPath)) issues.push(`${rel}: search-missing: ${urlPath}`); @@ -928,7 +938,7 @@ export function checkSearch(searchData, relFiles, basePath, optOut = null) { export function checkCanonical(canonicalByRel, basePath) { const issues = []; for (const [rel, canonical] of canonicalByRel) { - if (EXCLUDE.has(path.posix.basename(rel))) continue; + if (excluded(rel)) continue; const expected = (basePath || "") + deriveUrlPath(rel); let canonicalPath; diff --git a/test/fixtures/check-src/assets/js/nav-tree.js b/test/fixtures/check-src/assets/js/nav-tree.js new file mode 100644 index 000000000..0857d8f08 --- /dev/null +++ b/test/fixtures/check-src/assets/js/nav-tree.js @@ -0,0 +1 @@ +// Placeholder: the template references this unconditionally.