fix(yivi): start decrypt session on DOM readiness instead of fixed delay#118
Conversation
retrieveUSKViaYivi always waited a hardcoded 500ms setTimeout before handing the host element to yivi-core. Replace it with waitForElement, which resolves as soon as the target element is in the DOM (mirroring the signing flow, which builds YiviCore with no delay), watching via MutationObserver with a bounded fallback timeout when the element is not yet mounted. Closes #110
There was a problem hiding this comment.
VERDICT: approve
Rules Dobby 2 — sign-off. No blocking issues found.
Scope check: the change is confined to the timing workaround. waitForElement replaces the hardcoded setTimeout(500) in retrieveUSKViaYivi, resolving on the same tick when the host element is already present (the common case) and watching via MutationObserver with a bounded 5 s fallback otherwise. element is the CSS selector string yivi-core already receives and that the signing flow passes to document.querySelector, so the readiness check is semantically correct and mirrors the no-delay signing path.
Verified:
- Correctness: promise settles on every path, observer and timer are both cleaned up in
finish(), no leak or hang. Confirmed by two independent checks. - Tests: four-case regression suite added, including a guard that fails if a fixed delay is reintroduced on the ready path. Full suite and typecheck pass.
- Title is conventional (
fix(yivi): ...), body hasCloses #110, no vi.mock hoisting issue, no writing-rule violations.
One process item fixed during sign-off: reviewer @rubenhensen was assigned (PR had none).
Review Dobby 2 reported 0 findings; rule sweep added none. Approving and flipping out of draft.
|
🎉 This PR is included in version 2.3.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #110
What
retrieveUSKViaYiviinsrc/yivi/decrypt-session.tsalways waited a hardcoded 500 mssetTimeoutbefore handing the host element to yivi-core, with the comment "Small delay to ensure DOM element is ready". That fixed delay ran on every decrypt session even when the element was already mounted.This replaces it with
waitForElement, which resolves as soon as the target element is present in the DOM. When the element is already there it resolves on the same tick, so the session starts immediately. When it is not yet mounted, aMutationObserverwatches for it, with a bounded 5 s fallback timeout so a never-appearing element can't hang the session. This mirrors the signing flow (src/signing/yivi.ts), which buildsYiviCorewith no delay at all.Tests
Added a
waitForElementregression suite totests/decrypt-session.test.tscovering:setTimeoutis reintroduced on the ready path — verified against the old code);Full suite (
npm test) andnpm run typecheckpass.