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:
co-authored by
Claude Opus 5.5
parent
6e2f0af5a2
commit
c2265dabb2
@@ -8,7 +8,7 @@ import { renderToStaticMarkup } from "react-dom/server";
|
||||
import * as acorn from "acorn";
|
||||
|
||||
import { bindCurrentSubjectAccount, currentSubjectStorageKey, LAST_SUBJECT_ACCOUNT_KEY, readCurrentSubjectId, resetSubjectCatalogForTests } from "../src/lib/current-subject.ts";
|
||||
import { BOOT_ACCOUNT_PATH, BOOT_CHART_PROFILES_PATH, BOOT_MODELS_PATH, BOOT_READ_INIT, BOOT_READ_MAX_AGE_MS, BOOT_READS_GLOBAL, bootEarlyReadsScript, bootSessionsPath, clearBootReads, takeBootRead, takeBootSessionsRead, withBootFallback } from "../src/lib/boot-early-reads.ts";
|
||||
import { BOOT_ACCOUNT_PATH, BOOT_CHART_PROFILES_PATH, BOOT_MODELS_PATH, BOOT_READ_INIT, BOOT_READ_MAX_AGE_MS, BOOT_READS_GLOBAL, bootEarlyReadsScript, bootEarlyReadsScriptSrc, bootSessionsPath, clearBootReads, takeBootRead, takeBootSessionsRead, withBootFallback } from "../src/lib/boot-early-reads.ts";
|
||||
import { chinaLocations } from "../src/data/china-locations.ts";
|
||||
import { ensureChinaLocations, loadedChinaCountry, profileNeedsChinaLocations, resetChinaLocationsForTests } from "../src/lib/china-locations-client.ts";
|
||||
import { readProfile, selectedBirthPlace } from "../src/lib/home-profile.ts";
|
||||
@@ -233,7 +233,13 @@ test("the early-read script is classic ES5 and only acts on / (T8)", () => {
|
||||
assert.deepEqual(runBootScript(path).sent, [], `${path} sends nothing`);
|
||||
}
|
||||
const layout = readFileSync(new URL("../src/app/layout.tsx", import.meta.url), "utf8");
|
||||
assert.match(layout, /__html: bootEarlyReadsScript\(\)/);
|
||||
// 原值:assert.match(layout, /__html: bootEarlyReadsScript\(\)/)(内联经典脚本)。
|
||||
// 新值:<script async src={bootEarlyReadsScriptSrc()} />,src 是同一段脚本的 base64 data: URL。
|
||||
// 原因:TASK-home-first-load-fix-20261001——内联脚本排在样式表之后,要等样式表下完才执行,线上早发推迟 2.4~3.1 s。
|
||||
assert.match(layout, /<script async src=\{bootEarlyReadsScriptSrc\(\)\} \/>/);
|
||||
const src = bootEarlyReadsScriptSrc();
|
||||
assert.match(src, /^data:text\/javascript;base64,[A-Za-z0-9+/=]+$/);
|
||||
assert.equal(Buffer.from(src.slice(src.indexOf(",") + 1), "base64").toString("utf8"), bootEarlyReadsScript(), "the data URL carries exactly the ES5 script");
|
||||
});
|
||||
|
||||
test("the early reads are the normal requests, byte for byte (T8)", () => {
|
||||
|
||||
Reference in New Issue
Block a user