-
Notifications
You must be signed in to change notification settings - Fork 296
fix(runtime): replace silent catches in overlay with console.warn #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { OVERLAY_SCRIPT } from './overlay'; | ||
|
|
||
| interface FakeWindow { | ||
| addEventListener: (type: string, fn: unknown, capture?: boolean) => void; | ||
| parent: { postMessage: (msg: unknown, target: string) => void }; | ||
| __cs_err?: boolean; | ||
| __cs_rej?: boolean; | ||
| } | ||
|
|
||
| function runOverlay(opts: { | ||
| removeThrows?: boolean; | ||
| addThrows?: boolean; | ||
| }): { warn: ReturnType<typeof vi.fn>; tick: () => void } { | ||
| const warn = vi.fn(); | ||
| const fakeConsole = { warn }; | ||
|
|
||
| const fakeDocument = { | ||
| body: {}, | ||
| addEventListener: () => { | ||
| if (opts.addThrows) throw new Error('add failed'); | ||
| }, | ||
| removeEventListener: () => { | ||
| if (opts.removeThrows) throw new Error('remove failed'); | ||
| }, | ||
| }; | ||
|
|
||
| const fakeWindow: FakeWindow = { | ||
| addEventListener: () => {}, | ||
| parent: { postMessage: () => {} }, | ||
| }; | ||
|
|
||
| let intervalFn: (() => void) | null = null; | ||
| const fakeSetInterval = (fn: () => void) => { | ||
| intervalFn = fn; | ||
| return 1; | ||
| }; | ||
|
|
||
| const sandbox = new Function( | ||
| 'window', | ||
| 'document', | ||
| 'console', | ||
| 'setInterval', | ||
| `with (window) { ${OVERLAY_SCRIPT} }`, | ||
| ); | ||
| sandbox(fakeWindow, fakeDocument, fakeConsole, fakeSetInterval); | ||
|
|
||
| return { | ||
| warn, | ||
| tick: () => { | ||
| if (intervalFn) intervalFn(); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| describe('OVERLAY_SCRIPT reattach loop warning throttle', () => { | ||
| it('dedupes repeated reattach failures across many ticks', () => { | ||
| const { warn, tick } = runOverlay({ removeThrows: true, addThrows: true }); | ||
| // Initial reattach already ran inside script; simulate 25 more interval fires (~5s @ 200ms). | ||
| for (let i = 0; i < 25; i++) tick(); | ||
|
|
||
| // 3 install specs * 2 ops (remove+add) = 6 distinct keys at most. | ||
| // The point: it must not scale with tick count. | ||
| expect(warn.mock.calls.length).toBeLessThanOrEqual(6); | ||
| }); | ||
|
|
||
| it('emits at most one warn per unique error key over the whole loop', () => { | ||
| const { warn, tick } = runOverlay({ removeThrows: true }); | ||
| for (let i = 0; i < 25; i++) tick(); | ||
| const keys = new Set(warn.mock.calls.map((c) => String(c[0]))); | ||
| // each warn call should be a unique key | ||
| expect(warn.mock.calls.length).toBe(keys.size); | ||
| // should be ≤ 3 (one per event type), well under the 25-tick spam ceiling | ||
| expect(warn.mock.calls.length).toBeLessThanOrEqual(3); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Minor]
warnOncecurrently swallowsconsole.warnerrors (catch (_) { /* noop */ }), reintroducing a silent fallback. Please let this throw (or surface via existing iframe error channel) so failures are observable with context.Suggested fix: