fix: setSource() doesn't invalidate rendered results (v4.0.3) - #10
Merged
Merged
Conversation
Swapping the source while the control was closed left the old source's options
in this.results. _onFocus only re-runs the search when results are empty
(`!self.results.length`), so the next open showed stale options — e.g. a
dependent Country → Region dropdown never refreshed after the country changed.
setSource() now clears results/_total/activeIndex (matching setScope, which
already did), so the next open reflects the new source. The current
selection/value is left untouched. Removes the need for the setScope({}) workaround.
Adds 2 regression tests (47 total): stale-options-on-reopen, and value survival
across a swap.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes a bug where
setSource()on a closed control left the previous source's options rendered, so the next open showed stale data.Root cause:
setSource()updatedopts.sourceand cleared_cache, but never clearedthis.results. The focus path only re-runs the search when results are empty (if (… && !self.results.length)), so with stale results present the re-search was skipped.setScope()already clearedthis.results— the two source-mutating methods were inconsistent.Fix:
setSource()now clearsresults/_total/activeIndex(matchingsetScope()) before re-searching if open. The current selection/value is left untouched — only the available options change.Real-world impact: dependent dropdowns (pick Country →
setSource(provincesForCountry)on a Region select) now refresh correctly. ThesetScope({})workaround consumers used is no longer needed.Changes
dist/liveselect.js—setSource()invalidates rendered statetest/client.test.js— 2 regression tests (stale-options-on-reopen via the focus path; selected value survives a swap) → 47/47 passCHANGELOG.md+package.json— 4.0.3Test plan
npm test→ 47/47 (was 45)Thanks to the reporter for the precise root-cause analysis and suggested fix.
🤖 Generated with Claude Code