Skip to content

Commit 5c2981d

Browse files
vanceingallsclaude
andcommitted
fix(registry): reject non-numeric caption-data versions; boot fetch never clobbers a manual attach
Two review findings on the caption-data runtime, applied to all 5 templates: - hfValidate's version gate used Math.floor(Number(v)) > HF_CONTRACT_VERSION, and Number("v2") is NaN — NaN comparisons are always false, so malformed versions slid through with no unsupported-version signal. An explicit Number.isFinite check closes it. - hfBoot's sibling-fetch .then called hfAttach unconditionally; a manual window.__HF_CAPTION_ATTACH__ call landing while the fetch or fonts.ready was still pending got clobbered by the late boot payload. Boot now yields if a timeline already exists. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent e2846eb commit 5c2981d

5 files changed

Lines changed: 55 additions & 10 deletions

File tree

‎registry/components/caption-editorial-emphasis/caption-editorial-emphasis.html‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,13 @@
205205

206206
function hfValidate(data) {
207207
if (!data || typeof data !== "object") return { ok: false, reason: "not-an-object" };
208-
if (data.version != null && Math.floor(Number(data.version)) > HF_CONTRACT_VERSION) {
209-
return { ok: false, reason: "unsupported-version" };
208+
if (data.version != null) {
209+
// Number("v2") is NaN and NaN > x is always false — an explicit
210+
// finite check keeps malformed versions from slipping past the gate.
211+
var hfVersion = Number(data.version);
212+
if (!Number.isFinite(hfVersion) || Math.floor(hfVersion) > HF_CONTRACT_VERSION) {
213+
return { ok: false, reason: "unsupported-version" };
214+
}
210215
}
211216
if (!Array.isArray(data.segments) || data.segments.length === 0) {
212217
return { ok: false, reason: "no-segments" };
@@ -679,6 +684,10 @@
679684
var ready =
680685
document.fonts && document.fonts.ready ? document.fonts.ready : Promise.resolve();
681686
ready.then(function () {
687+
// A manual window.__HF_CAPTION_ATTACH__ call that lands while the
688+
// sibling fetch / fonts.ready are still pending must win — never
689+
// clobber it with the late-arriving boot payload.
690+
if (hfCurrentTimeline) return;
682691
hfAttach(data);
683692
});
684693
}

‎registry/components/caption-emoji-pop/caption-emoji-pop.html‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,13 @@
208208

209209
function hfValidate(data) {
210210
if (!data || typeof data !== "object") return { ok: false, reason: "not-an-object" };
211-
if (data.version != null && Math.floor(Number(data.version)) > HF_CONTRACT_VERSION) {
212-
return { ok: false, reason: "unsupported-version" };
211+
if (data.version != null) {
212+
// Number("v2") is NaN and NaN > x is always false — an explicit
213+
// finite check keeps malformed versions from slipping past the gate.
214+
var hfVersion = Number(data.version);
215+
if (!Number.isFinite(hfVersion) || Math.floor(hfVersion) > HF_CONTRACT_VERSION) {
216+
return { ok: false, reason: "unsupported-version" };
217+
}
213218
}
214219
if (!Array.isArray(data.segments) || data.segments.length === 0) {
215220
return { ok: false, reason: "no-segments" };
@@ -790,6 +795,10 @@
790795
var ready =
791796
document.fonts && document.fonts.ready ? document.fonts.ready : Promise.resolve();
792797
ready.then(function () {
798+
// A manual window.__HF_CAPTION_ATTACH__ call that lands while the
799+
// sibling fetch / fonts.ready are still pending must win — never
800+
// clobber it with the late-arriving boot payload.
801+
if (hfCurrentTimeline) return;
793802
hfAttach(data);
794803
});
795804
}

‎registry/components/caption-highlight/caption-highlight.html‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,13 @@
214214

215215
function hfValidate(data) {
216216
if (!data || typeof data !== "object") return { ok: false, reason: "not-an-object" };
217-
if (data.version != null && Math.floor(Number(data.version)) > HF_CONTRACT_VERSION) {
218-
return { ok: false, reason: "unsupported-version" };
217+
if (data.version != null) {
218+
// Number("v2") is NaN and NaN > x is always false — an explicit
219+
// finite check keeps malformed versions from slipping past the gate.
220+
var hfVersion = Number(data.version);
221+
if (!Number.isFinite(hfVersion) || Math.floor(hfVersion) > HF_CONTRACT_VERSION) {
222+
return { ok: false, reason: "unsupported-version" };
223+
}
219224
}
220225
if (!Array.isArray(data.segments) || data.segments.length === 0) {
221226
return { ok: false, reason: "no-segments" };
@@ -491,6 +496,10 @@
491496
var ready =
492497
document.fonts && document.fonts.ready ? document.fonts.ready : Promise.resolve();
493498
ready.then(function () {
499+
// A manual window.__HF_CAPTION_ATTACH__ call that lands while the
500+
// sibling fetch / fonts.ready are still pending must win — never
501+
// clobber it with the late-arriving boot payload.
502+
if (hfCurrentTimeline) return;
494503
hfAttach(data);
495504
});
496505
}

‎registry/components/caption-pill-karaoke/caption-pill-karaoke.html‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,13 @@
214214

215215
function hfValidate(data) {
216216
if (!data || typeof data !== "object") return { ok: false, reason: "not-an-object" };
217-
if (data.version != null && Math.floor(Number(data.version)) > HF_CONTRACT_VERSION) {
218-
return { ok: false, reason: "unsupported-version" };
217+
if (data.version != null) {
218+
// Number("v2") is NaN and NaN > x is always false — an explicit
219+
// finite check keeps malformed versions from slipping past the gate.
220+
var hfVersion = Number(data.version);
221+
if (!Number.isFinite(hfVersion) || Math.floor(hfVersion) > HF_CONTRACT_VERSION) {
222+
return { ok: false, reason: "unsupported-version" };
223+
}
219224
}
220225
if (!Array.isArray(data.segments) || data.segments.length === 0) {
221226
return { ok: false, reason: "no-segments" };
@@ -599,6 +604,10 @@
599604
var ready =
600605
document.fonts && document.fonts.ready ? document.fonts.ready : Promise.resolve();
601606
ready.then(function () {
607+
// A manual window.__HF_CAPTION_ATTACH__ call that lands while the
608+
// sibling fetch / fonts.ready are still pending must win — never
609+
// clobber it with the late-arriving boot payload.
610+
if (hfCurrentTimeline) return;
602611
hfAttach(data);
603612
});
604613
}

‎registry/components/caption-weight-shift/caption-weight-shift.html‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,13 @@
200200

201201
function hfValidate(data) {
202202
if (!data || typeof data !== "object") return { ok: false, reason: "not-an-object" };
203-
if (data.version != null && Math.floor(Number(data.version)) > HF_CONTRACT_VERSION) {
204-
return { ok: false, reason: "unsupported-version" };
203+
if (data.version != null) {
204+
// Number("v2") is NaN and NaN > x is always false — an explicit
205+
// finite check keeps malformed versions from slipping past the gate.
206+
var hfVersion = Number(data.version);
207+
if (!Number.isFinite(hfVersion) || Math.floor(hfVersion) > HF_CONTRACT_VERSION) {
208+
return { ok: false, reason: "unsupported-version" };
209+
}
205210
}
206211
if (!Array.isArray(data.segments) || data.segments.length === 0) {
207212
return { ok: false, reason: "no-segments" };
@@ -616,6 +621,10 @@
616621
var ready =
617622
document.fonts && document.fonts.ready ? document.fonts.ready : Promise.resolve();
618623
ready.then(function () {
624+
// A manual window.__HF_CAPTION_ATTACH__ call that lands while the
625+
// sibling fetch / fonts.ready are still pending must win — never
626+
// clobber it with the late-arriving boot payload.
627+
if (hfCurrentTimeline) return;
619628
hfAttach(data);
620629
});
621630
}

0 commit comments

Comments
 (0)