Skip to content

Conversation

Overu
Copy link
Collaborator

@Overu Overu commented Sep 26, 2025

Fixed #2089

@Overu Overu requested a review from nighca September 26, 2025 15:39
Copy link

Summary of Changes

Hello @Overu, 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 a critical input issue where characters could be lost when users were typing with an Input Method Editor (IME). By implementing a mechanism to track the IME's composition state, the system now intelligently defers input validation. This ensures a smoother and more reliable typing experience, preventing unintended component updates from interfering with text input during active composition.

Highlights

  • IME Input Fix: Addressed an issue causing character loss during Input Method Editor (IME) composition in form inputs, specifically referenced by issue Input issue in firefox #2089.
  • Composition Tracking: Introduced an isComposing flag, initialized to true, and managed by compositionstart and compositionend events on the NFormItem component to accurately track IME composition status.
  • Validation Control: Modified the handleContentInput function to prevent form validation from triggering while IME composition is active, ensuring stable input and preventing premature component updates.
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

@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 aims to fix an issue with Input Method Editors (IMEs) by preventing validation from running during composition. The approach of using an isComposing flag is sound. However, I've found a critical issue in its implementation: the flag is initialized to true, which will disable input validation for all users not using an IME. My review includes a specific comment with a suggested fix for this issue.

* Debounce is used to reduce validation frequency in normal scenarios.
* Effectively avoids unexpected updates and character loss during rapid IME input.
*/
let isComposing = true

Choose a reason for hiding this comment

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

critical

The isComposing flag is initialized to true. This will prevent validation from running for users who are not using an Input Method Editor (IME), as the compositionend event that sets it to false will never fire for them. This effectively disables validation on input for non-IME users. The flag should be initialized to false.

let isComposing = false

* Debounce is used to reduce validation frequency in normal scenarios.
* Effectively avoids unexpected updates and character loss during rapid IME input.
*/
let isComposing = true
Copy link

Choose a reason for hiding this comment

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

Critical Bug: Incorrect Initial State

Suggested change
let isComposing = true
let isComposing = false

The isComposing flag is initialized to true, which blocks validation for all users until a composition event occurs. This breaks form validation for non-IME users. Should be false by default.

* Debounce is used to reduce validation frequency in normal scenarios.
* Effectively avoids unexpected updates and character loss during rapid IME input.
*/
let isComposing = true
Copy link

Choose a reason for hiding this comment

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

Suggestion: Use Reactive State

Consider using Vue's reactive state for better integration with the reactivity system:

Suggested change
let isComposing = true
const isComposing = ref(false)

Then update the handlers and condition to use .value.

function handleCompositionStart() {
isComposing = true
}
function handleCompositionEnd() {
Copy link

Choose a reason for hiding this comment

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

Security Enhancement: Validate After Composition

Consider triggering validation when composition ends to ensure timely validation:

Suggested change
function handleCompositionEnd() {
function handleCompositionEnd() {
isComposing = false
// Trigger validation after composition ends
if (props.path != null) {
handleContentInput()
}
}

Copy link

niupilot bot commented Sep 26, 2025

Code Review Summary

Overall Assessment: Good solution for the IME input issue with excellent documentation. One critical bug needs fixing.

Critical Issue: The isComposing = true initialization breaks validation for non-IME users. Must change to false.

Positives: Clean implementation, great documentation, maintains performance with debouncing, follows Vue.js best practices.

The fix effectively addresses issue #2089 while maintaining code quality. Please address the initialization bug before merging.

}
function handleCompositionEnd() {
isComposing = false
handleContentInput()
Copy link
Collaborator

Choose a reason for hiding this comment

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

本来 compositionend 事件触发时(或触发后),n-input 会调用 handleContentInput 吗?另外 handleContentChange 不能解决问题的具体原因是啥来着,是我们对它的定位理解有偏差吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

n-inputcompositionend后会调用handleInput,然后handleInput内部会调用到handleContentInput,然后调用到我们的触发表单校验,这个时候如果用户随即开始输入,会发生输入进行中和组件更新,导致吞字发生。handleContentChange只有在失去焦点submit的时候触发。

Copy link
Collaborator

Choose a reason for hiding this comment

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

n-inputcompositionend后会调用handleInput,然后handleInput内部会调用到handleContentInput

那这里的 handleContentInput() 听起来跟 n-input 逻辑重复了,是需要的吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

仔细考虑了一下,是没有必要,因为n-input已经帮我们兼容了浏览器差异

:label="label"
:path="path"
v-bind="nFormItemProps"
@compositionstart="handleCompositionStart"
Copy link
Collaborator

Choose a reason for hiding this comment

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

另外我们真正关心的应该是具体的 input 的 compositionstart 和 compositionend 事件,这里可以在 NFormItem 上监听是单纯地因为事件走常规的 DOM 事件冒泡所以能在这里被监听到,还是 naive-ui 内部特别支持了在 NFormItem 上监听这俩事件?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

是常规的事件冒泡,naive-ui没有特别在NFormItem内部支持这两个事件。

@qiniu-ci
Copy link

This PR has been deployed to the preview environment. You can explore it using the preview URL.

Warning

Please note that deployments in the preview environment are temporary and will be automatically cleaned up after a certain period. Make sure to explore it before it is removed. For any questions, contact the XBuilder team.

@nighca nighca merged commit e1d93e0 into goplus:dev Sep 28, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Input issue in firefox
3 participants