-
Notifications
You must be signed in to change notification settings - Fork 70
chore: clear pending timers on destroy + clarify reflow/highlight intent #473
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
gnbm
merged 9 commits into
perf/throttle-resize-handler
from
chore/timer-cleanup-hardening
Jun 8, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a9e30b2
chore: clear pending timers on destroy + clarify reflow/highlight int…
gnbm c48f1f0
Improve throttle typings and clean test comment
gnbm 4e44173
Refactor Utils.throttle to use spread args
gnbm 87a3112
Update virtual-select-1.2.0.min.js
gnbm bb242e1
Preserve context in throttle and clarify comment
gnbm 184ea18
Merge branch 'master' into chore/timer-cleanup-hardening
gnbm cb1089b
Merge branch 'perf/throttle-resize-handler' into chore/timer-cleanup-…
gnbm fccccd4
fix(utils): remove broken throttle edit; harden timer-cleanup test
gnbm d635f33
build: sync bundles with committed source (stale highlight comment)
gnbm 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
Some comments aren't visible on the classic Files Changed page.
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,69 @@ | ||
| /** cSpell:ignore vscomp */ | ||
|
|
||
| // Tests for P4: pending setTimeout callbacks were not cleared on destroy(), so they could run | ||
| // against a destroyed instance. Timers now go through setManagedTimeout and are cleared in destroy(). | ||
|
|
||
| describe('Hardening: managed timeouts cleared on destroy (P4)', () => { | ||
| const mountId = 'vs-p4-timers'; | ||
|
|
||
| const mount = (win: Window) => { | ||
| const doc = win.document; | ||
| const existing = doc.getElementById(mountId); | ||
| if (existing) { | ||
| existing.remove(); | ||
| } | ||
| const $ele = doc.createElement('div'); | ||
| $ele.id = mountId; | ||
| doc.body.appendChild($ele); | ||
| // @ts-expect-error - VirtualSelect attached to window by the bundle | ||
| win.VirtualSelect.init({ ele: $ele, options: [{ label: 'A', value: 'a' }, { label: 'B', value: 'b' }] }); | ||
| return $ele.virtualSelect; | ||
| }; | ||
|
|
||
| it('cancels a pending managed timeout when the instance is destroyed', () => { | ||
| cy.visit('get-started'); | ||
| // Use a synthetic clock so the negative assertion (timer must NOT fire) is deterministic. | ||
| // With a real-time cy.wait, CI timer-throttling could delay a still-pending 50ms callback | ||
| // past the wait window, making the test pass even if destroy() failed to clear it. | ||
| cy.clock(); | ||
| cy.window().then((win) => { | ||
| // @ts-expect-error - test marker | ||
| win.__managedTimerFired = false; | ||
| const instance = mount(win); | ||
| instance.setManagedTimeout(() => { | ||
| // @ts-expect-error - test marker | ||
| win.__managedTimerFired = true; | ||
| }, 50); | ||
| instance.destroy(); | ||
| }); | ||
|
|
||
| // Advance well past the 50ms timeout; a cleared timer can never fire, a leaked one would. | ||
| cy.tick(150); | ||
| cy.window().then((win) => { | ||
| // @ts-expect-error - test marker | ||
| expect(win.__managedTimerFired, 'managed timeout must not fire after destroy').to.eq(false); | ||
| }); | ||
| }); | ||
|
|
||
| it('does not throw when destroying right after an option select (no regression)', () => { | ||
| cy.visit('get-started'); | ||
| cy.window().then((win) => mount(win)); | ||
|
|
||
| cy.get(`#${mountId}`).find('.vscomp-toggle-button').click(); | ||
| cy.get(`#${mountId}`).find('.vscomp-option[data-value="a"]').click(); | ||
|
|
||
| cy.window().then((win) => { | ||
| const $ele = win.document.getElementById(mountId); | ||
| // @ts-expect-error - instance back-reference | ||
| $ele.virtualSelect.destroy(); | ||
| }); | ||
|
|
||
| cy.wait(50); | ||
| cy.get('body').should('exist'); | ||
| cy.window().then((win) => { | ||
| const $ele = win.document.getElementById(mountId); | ||
| // @ts-expect-error - instance back-reference | ||
| expect($ele.virtualSelect, 'instance reference cleared on destroy').to.eq(undefined); | ||
| }); | ||
| }); | ||
| }); | ||
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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.
Uh oh!
There was an error while loading. Please reload this page.