mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-11 23:00:03 +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,3 +1,4 @@
|
||||
import { swallow } from "./diagnostics";
|
||||
import type { RuntimeBridgeControlMessage, RuntimeOutboundMessage } from "./types";
|
||||
|
||||
type BridgeDeps = {
|
||||
@@ -15,8 +16,9 @@ type BridgeDeps = {
|
||||
export function postRuntimeMessage(payload: RuntimeOutboundMessage): void {
|
||||
try {
|
||||
window.parent.postMessage(payload, "*");
|
||||
} catch {
|
||||
// Ignore cross-frame posting failures.
|
||||
} catch (err) {
|
||||
// Cross-frame posting can throw if the parent is gone or origin-isolated.
|
||||
swallow("bridge.postMessage", err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,8 +106,9 @@ function flashElements(selectors: string[], duration: number): void {
|
||||
el.classList.add("__hf-flash");
|
||||
setTimeout(() => el.classList.remove("__hf-flash"), duration);
|
||||
});
|
||||
} catch {
|
||||
} catch (err) {
|
||||
// Invalid selector — skip
|
||||
swallow("bridge.flashElements.querySelector", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user