Skip to content

fix(field): sync native input value when toggling input slot#13767

Open
code-farmer-i wants to merge 1 commit into
youzan:mainfrom
code-farmer-i:fix/field-input-slot-sync
Open

fix(field): sync native input value when toggling input slot#13767
code-farmer-i wants to merge 1 commit into
youzan:mainfrom
code-farmer-i:fix/field-input-slot-sync

Conversation

@code-farmer-i
Copy link
Copy Markdown

@code-farmer-i code-farmer-i commented Jan 28, 2026

Fix Field component issue where the native input value can be lost when dynamically toggling the input slot with v-if.

  • Watch the presence of slots.input, and when the custom slot is removed, sync props.modelValue into the newly rendered native input on nextTick.
  • Add unit test to cover toggling scenario and prevent regressions.

Refs: #13492

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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

  • Dynamic Input Slot Synchronization: Implemented a "watch" effect on the "inputRef" in the "Field" component to ensure that the native input element's value is correctly synchronized with the component's "modelValue" when the input slot is dynamically toggled.
  • Test Coverage: Added a new test case to validate the correct behavior of the "Field" component when its "input" slot is dynamically removed, confirming that the native input element correctly displays the bound value.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +689 to 698
watch(inputRef, (newVal) => {
if (newVal) {
updateValue(getModelValue(), props.formatTrigger);
nextTick(adjustTextareaSize);
}
});

onMounted(() => {
updateValue(getModelValue(), props.formatTrigger);
nextTick(adjustTextareaSize);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant