fix(home): early boot reads load as an async data: script so stylesheets no longer hold them back (BUG-1127)

An inline classic script after the stylesheets waited for them to download;
on staging the reads left at 2.4-3.1 s. Measurement script gains
--css-delay and --ua iphone.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N4f2nya58RoRu4yEmJgRGE
This commit is contained in:
Jesse_Chen
2026-10-01 01:36:35 +08:00
co-authored by Claude Opus 5.5
parent 6e2f0af5a2
commit c2265dabb2
4 changed files with 47 additions and 6 deletions
+5 -3
View File
@@ -5,7 +5,7 @@ import { Toaster } from "@/components/ui/sonner";
import { StaleBuildGuard } from "@/components/stale-build-guard";
import { StaleClientRecovery } from "@/components/stale-client-recovery";
import { ViewportScrollLock } from "@/components/viewport-scroll-lock";
import { bootEarlyReadsScript } from "@/lib/boot-early-reads";
import { bootEarlyReadsScriptSrc } from "@/lib/boot-early-reads";
import { firstPaintFallbackBootScript } from "@/lib/first-paint-fallback";
import { themePreferenceBootScript } from "@/lib/theme-preference";
@@ -59,8 +59,10 @@ export default function RootLayout({ children }: Readonly<{ children: React.Reac
{/* Classic script, not a module: it has to run when the client bundle never does. */}
<script dangerouslySetInnerHTML={{ __html: firstPaintFallbackBootScript() }} />
{/* Home cold-boot reads leave with the HTML instead of after the bundle
runs (BUG-1127). The script is a no-op on every path except "/". */}
<script dangerouslySetInnerHTML={{ __html: bootEarlyReadsScript() }} />
runs (BUG-1127). The script is a no-op on every path except "/".
async + data: URL, not inline: an inline script after the
stylesheets would wait for them to download (fix 2026-10-01). */}
<script async src={bootEarlyReadsScriptSrc()} />
{enableReactDevTools && (
<>
<Script
+12
View File
@@ -78,6 +78,18 @@ export function bootEarlyReadsScript(): string {
})();`;
}
/**
* The script as an async data: URL (BUG-1127 fix, 2026-10-01). An inline
* classic script placed after the page's stylesheets waits until they have
* downloaded (script-blocking stylesheets), which on staging held the early
* reads back 2.4-3.1 s. An `async` external classic script is not blocked by
* stylesheets, and a data: URL costs no round trip. Plain ASCII base64, so
* the attribute needs no escaping.
*/
export function bootEarlyReadsScriptSrc(): string {
return `data:text/javascript;base64,${Buffer.from(bootEarlyReadsScript(), "utf8").toString("base64")}`;
}
function bootReads(): BootReads | null {
if (typeof window === "undefined") return null;
const reads = (window as unknown as Record<string, BootReads | undefined>)[BOOT_READS_GLOBAL];