Fix TextInput value preservation when parent re-renders without ValueChanged callback#59
Merged
LittleLittleCloud merged 5 commits intomainfrom Nov 10, 2025
Merged
Conversation
…tely Co-authored-by: LittleLittleCloud <16876986+LittleLittleCloud@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix two-way binding for TextInput component
Fix TextInput value preservation when parent re-renders without ValueChanged callback
Oct 24, 2025
TeseySTD
requested changes
Nov 9, 2025
Member
|
@copilot Field |
Co-authored-by: TeseySTD <150385054+TeseySTD@users.noreply.github.com>
Contributor
Author
Removed the |
TeseySTD
approved these changes
Nov 9, 2025
LittleLittleCloud
approved these changes
Nov 10, 2025
LittleLittleCloud
approved these changes
Nov 10, 2025
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.
Fix TextInput two-way binding issue
_lastSetValuefield per code review feedbackSummary
Fixed the TextInput component to properly preserve user input when the parent component re-renders without updating the Value parameter. This resolves the issue where user input was being reset during UI refreshes.
Root Cause
The
OnParametersSet()method was comparing the incomingValueparameter against_lastSetValue, which gets updated by both:HandleInputAsync)OnParametersSet)This caused user input to be incorrectly reset when the component re-rendered with the same parent value.
Solution
Introduced
_lastIncomingValuefield to track values received from the parent via theValueparameter. NowOnParametersSet()only updates the internal value when theValueparameter actually changes from the parent, preserving user input across re-renders.The original
_lastSetValuefield was removed as it became redundant after the fix.Changes Made
src/RazorConsole.Core/Components/TextInput.razor_lastIncomingValuefield to track incoming parent values_lastSetValuefield (4 assignments removed)OnParametersSet()to compare against_lastIncomingValueTesting
✅ All 88 existing tests pass on both .NET 8.0 and .NET 9.0
✅ Code formatted according to project standards
✅ Backward compatible with components using
@bind-Valueor explicitValueChangedcallbacksHow It Works Now
Scenario 1: Two-way binding with
@bind-ValueScenario 2: One-way binding with just
Value(the bug scenario)ValueparameterScenario 3: Parent updates value
Original prompt
Valueproperty ofTextInputis not two-way binding #57💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.