fix(field): sync native input value when toggling input slot#13767
fix(field): sync native input value when toggling input slot#13767code-farmer-i wants to merge 1 commit into
Conversation
Summary of ChangesHello @code-farmer-i, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue in the "Field" component where the native input element would not correctly display its bound value after an "input" slot was dynamically removed. The changes introduce a mechanism to synchronize the native input's value with the component's "modelValue" as soon as the native input element becomes available, ensuring consistent data representation and a smoother user experience when working with dynamic content. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where the native input's value was not synchronized when a custom input slot is dynamically removed. The fix introduces a watch on the inputRef to update the value when the native input element is created. A corresponding test case has been added to verify this behavior. The fix is effective, but it introduces some code redundancy that leads to an unnecessary function call on component mount. I've left a comment with details on how to improve this.
| watch(inputRef, (newVal) => { | ||
| if (newVal) { | ||
| updateValue(getModelValue(), props.formatTrigger); | ||
| nextTick(adjustTextareaSize); | ||
| } | ||
| }); | ||
|
|
||
| onMounted(() => { | ||
| updateValue(getModelValue(), props.formatTrigger); | ||
| nextTick(adjustTextareaSize); |
There was a problem hiding this comment.
This new watch on inputRef and the existing onMounted hook have identical logic. Since a watcher's callback is fired before the onMounted hook during component setup, updateValue will be called twice if the input is present on initial mount. This is redundant and inefficient.
The new watch correctly handles both the initial mount case and the case where the input is dynamically added later. Therefore, the onMounted hook (lines 696-699) is no longer necessary and should be removed.
Fix Field component issue where the native input value can be lost when dynamically toggling the
inputslot with v-if.slots.input, and when the custom slot is removed, syncprops.modelValueinto the newly rendered native input on nextTick.Refs: #13492