mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-09 12:00:26 +00:00
feat(runtime): swallow() helper replaces empty catches in inlined runtime
After hf#641 inlined the runtime IIFE into every bundle, lint tools
inspecting bundled output (including Abhay's c2v eval) started flagging
empty `catch {}` blocks across the runtime. The source had explanatory
comments inside, but esbuild's minifier strips them — the IIFE ships
~10 visible patterns of `}catch{}` and consumers' linters fire on each.
Each empty catch is intentional best-effort error swallowing —
postMessage to a parent frame that may not exist, `media.play()` /
`pause()` that throw under autoplay restrictions, timeline `seek()` on
a disposed timeline, anime.js / lottie feature detection on hosts that
don't load those libraries, etc. The right behaviour stays "tried,
didn't work, move on", but doing it visibly improves three things:
- lint clean: helper call is a real statement; no `no-empty` warnings
survive minification
- debuggable: flip `window.__hfDebug = true` in DevTools to see every
swallow site with `console.debug` (silent in prod by default)
- observable: studio / embeddings can install
`window.__hf.onSwallowed = handler` to collect runtime swallow
events without polluting the page console
Implementation: `packages/core/src/runtime/diagnostics.ts` exports
`swallow(label, err?)`. 41 catch sites across 12 runtime files
converted via mechanical pass (auto-generated `runtime.<module>.siteN`
labels — labels can be tightened site-by-site as a follow-up; the
shape of the change is what matters here).
Verification:
- core 674/674 (incl. 6 new diagnostics tests covering silent default,
__hfDebug logging, legacy __HYPERFRAMES_DEBUG flag, handler hook,
handler-throws-doesn't-recurse, both-active)
- typecheck clean
- format / lint clean
- runtime IIFE rebuilds successfully (`bun run build:hyperframes-runtime`)
Refs Abhay's c2v eval — bundler artefacts now lint-clean with the
runtime body inlined.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { RuntimeDeterministicAdapter } from "../types";
|
||||
import { swallow } from "../diagnostics";
|
||||
|
||||
export function createCssAdapter(params?: {
|
||||
resolveStartSeconds?: (element: Element) => number;
|
||||
@@ -22,13 +23,15 @@ export function createCssAdapter(params?: {
|
||||
for (const animation of animations) {
|
||||
try {
|
||||
animation.currentTime = timeMs;
|
||||
} catch {
|
||||
} catch (err) {
|
||||
// ignore animations that reject currentTime writes
|
||||
swallow("runtime.adapters.css.site1", err);
|
||||
}
|
||||
try {
|
||||
animation.pause();
|
||||
} catch {
|
||||
} catch (err) {
|
||||
// infinite unresolved animations can throw on pause before currentTime sticks
|
||||
swallow("runtime.adapters.css.site2", err);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -37,8 +40,9 @@ export function createCssAdapter(params?: {
|
||||
for (const animation of animations) {
|
||||
try {
|
||||
animation.play();
|
||||
} catch {
|
||||
} catch (err) {
|
||||
// ignore animation edge-cases
|
||||
swallow("runtime.adapters.css.site3", err);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -47,8 +51,9 @@ export function createCssAdapter(params?: {
|
||||
for (const animation of animations) {
|
||||
try {
|
||||
animation.pause();
|
||||
} catch {
|
||||
} catch (err) {
|
||||
// ignore animation edge-cases
|
||||
swallow("runtime.adapters.css.site4", err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user