From b6732167076ffd2de46a7e6a4d1ee8836156a4db Mon Sep 17 00:00:00 2001 From: William Zujkowski Date: Tue, 6 Oct 2026 11:01:14 -0400 Subject: [PATCH] perf(web): statically compile chapter full-text rollups during build Pre-render full chapter content at build time via Astro SSG, eliminating client-side DOMParser network waterfalls for large chapters while preserving instant toggles and deep links. Closes #279 --- .../src/pages/browse/[title]/[chapter].astro | 242 +++++++----------- 1 file changed, 93 insertions(+), 149 deletions(-) diff --git a/apps/web/src/pages/browse/[title]/[chapter].astro b/apps/web/src/pages/browse/[title]/[chapter].astro index 12ecc6a..40b2616 100644 --- a/apps/web/src/pages/browse/[title]/[chapter].astro +++ b/apps/web/src/pages/browse/[title]/[chapter].astro @@ -51,20 +51,17 @@ const sectionMeta = sortedSections.map((entry) => { return { entry, isInactive, statusLabel }; }); -// Only render full content at build time for small chapters (≤50 sections) -// Large chapters render on-demand via the toggle +// Statically compile all section bodies into the chapter rollup at build time +const renderedSections = await Promise.all( + sectionMeta.map(async ({ entry, isInactive, statusLabel }) => { + const { Content } = await render(entry); + return { entry, Content, isInactive, statusLabel }; + }) +); + const INLINE_THRESHOLD = 50; const isSmallChapter = sortedSections.length <= INLINE_THRESHOLD; -const renderedSections = isSmallChapter - ? await Promise.all( - sectionMeta.map(async ({ entry, isInactive, statusLabel }) => { - const { Content } = await render(entry); - return { entry, Content, isInactive, statusLabel }; - }) - ) - : []; - const base = import.meta.env.BASE_URL; const activeCount = sectionMeta.filter(s => !s.isInactive).length; --- @@ -135,42 +132,36 @@ const activeCount = sectionMeta.filter(s => !s.isInactive).length; - +
- {isSmallChapter ? ( - renderedSections.map(({ entry, Content, isInactive, statusLabel }) => ( - + ))}
@@ -180,126 +171,79 @@ const activeCount = sectionMeta.filter(s => !s.isInactive).length; - + {!isSmallChapter && ( )} - - {isSmallChapter && ( - - )} + }); + })(); +