fix(jsx/dom): apply select value after children are rendered#4847
Merged
fix(jsx/dom): apply select value after children are rendered#4847
Conversation
When options and value were set simultaneously on a select element, the value was applied before option children existed in the DOM, causing selectedIndex to fall back to 0. Defer select value assignment to after children rendering, similar to Preact's approach. This ensures options exist in the DOM before value matching, while other props like `multiple` are still applied before children.
For multiple selects with no matching option, selectedIndex was incorrectly forced to 0. Only reset selectedIndex for single selects, preserving the browser's default -1 for unmatched multiple selects.
Avoid DOM property access in the hot render loop by checking the JSX node's tag property directly.
Bundle size check
Compiler Diagnostics (tsc)
Compiler Diagnostics (typescript-go)
Reported by octocov |
HTTP Performance Benchmark
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4847 +/- ##
=======================================
Coverage 92.84% 92.85%
=======================================
Files 177 177
Lines 11643 11653 +10
Branches 3469 3473 +4
=======================================
+ Hits 10810 10820 +10
Misses 832 832
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
Author
|
Hi @yusukebe, |
Member
|
Nice to solve the difficult problem! Thanks. |
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.
fixes #4837
What's included in this fix
select[value]not being correctly applied when child options are specifiedselect[multiple]incorrectly selecting the first option when it should remain unselected (not directly related to [jsx/dom] Select input value not applied when options and value are set simultaneously #4837, but included in this PR as a select-related fix)Related Preact issues
preactjs/preact#446
preactjs/preact#761
The author should do the following, if applicable
bun run format:fix && bun run lint:fixto format the code