-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(use-input): sync the inputValue with domRef.current.value when hovering the input #3481
Conversation
🦋 Changeset detectedLatest commit: f6afb96 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@jijiseong is attempting to deploy a commit to the NextUI Inc Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes introduce a new Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant InputComponent
participant useInput
participant useHover
participant DOMRef
User ->> InputComponent: Hover/Click
InputComponent ->> useInput: Trigger onHoverStart/onClick
useInput ->> useHover: Handle Hover/Click
useHover ->> DOMRef: Fetch current value
DOMRef -->> useHover: Current value
useHover -->> useInput: Set value based on ref
useInput -->> InputComponent: Update input value
InputComponent -->> User: Display updated value
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (1)
- packages/components/input/src/use-input.ts (1 hunks)
Additional comments not posted (1)
packages/components/input/src/use-input.ts (1)
208-214
: Ensure synchronization of input value on hoverThe addition of the
onHoverStart
callback within theuseHover
hook is a targeted solution to the synchronization issue described. By setting the input value directly from the DOM when hovering starts, it ensures that any changes made directly to the DOM are reflected in the component's state.However, this approach might introduce performance implications if
setInputValue
triggers more re-renders than necessary. It's also important to ensure that this behavior does not interfere with other interactions or expected behaviors, especially with form libraries likereact-hook-form
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (1)
- .changeset/angry-icons-jump.md (1 hunks)
Additional comments not posted (2)
.changeset/angry-icons-jump.md (2)
2-2
: Versioning is correctly labeled as a patch.The changes described are a bug fix, which correctly warrants a patch version increment according to semantic versioning.
5-5
: Clear and concise description of the changes.The description succinctly explains the bug fix, making it clear what the patch addresses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please include the test as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (1)
- packages/components/input/tests/input.test.tsx (1 hunks)
Additional context used
Biome
packages/components/input/__tests__/input.test.tsx
[error] 189-189: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (2)
- .changeset/angry-icons-jump.md (1 hunks)
- packages/components/input/tests/input.test.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- .changeset/angry-icons-jump.md
- packages/components/input/tests/input.test.tsx
@jijiseong is it ready for re-review? |
yes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about finding a way to sync the ref value to inputValue
instead just handling the hover case only? I remember I've seen another issue also caused by this reason.
Thankyou for your feedback. I tried to find another way, but I think it is the best way, I'll look for another way, If you tell me another issue. |
I guess a couple of things to check for are, if the ref value is set, instead of mouse hovering you either 1) have the parent component re-render, and see if the component re-renders correctly, or 2) tab into the component or finger-click into it on those touch-screen tablets because they don't trigger the hover event. |
@jijiseong you may take a look at #2966. Even it's assigned, but i don't think he's working on it. I think if we fix the sync issue, then the hover issue will be resolved as well. |
I don't reproduce this issue. |
@jijiseong I'll review hover approach then. |
Thankyou I also handled the case for tabbing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (2)
- packages/components/input/tests/input.test.tsx (2 hunks)
- packages/components/input/src/use-input.ts (3 hunks)
Files skipped from review as they are similar to previous changes (2)
- packages/components/input/tests/input.test.tsx
- packages/components/input/src/use-input.ts
I am ready to re-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (2)
- .changeset/angry-icons-jump.md (1 hunks)
- packages/components/input/tests/input.test.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- .changeset/angry-icons-jump.md
- packages/components/input/tests/input.test.tsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (1)
- packages/components/input/tests/input.test.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/components/input/tests/input.test.tsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (2)
packages/components/input/__tests__/input.test.tsx (2)
184-206
: Improve test case readability and maintainability.Consider using assertions instead of throwing errors for better readability and maintainability.
- if (!ref.current) { - throw new Error("ref is null"); - } + expect(ref.current).not.toBeNull();
209-230
: Improve test case readability and maintainability.Consider using assertions instead of throwing errors for better readability and maintainability.
- if (!ref.current) { - throw new Error("ref is null"); - } + expect(ref.current).not.toBeNull();
@jijiseong @wingkwong I think we should be looking at this fix from a preventative rather than a reactive perspective; that is, we should implement a fix that keeps the state synced instead of trying to figure out which cases will result in desync and trying to patch that up. In this particular case, the issue is that the ref assignment results in the ref value becoming out of sync with the internal state. What we need to do is make sure that the synchronization happens at the time the ref value assignment happens. This would involve intercepting the ref value setter (via Imperative Handle) and calling the setInputValue function within it in order to keep the state synced. Here is a quick implementation of this approach:
The above code makes sure that as soon as the ref value assignment occurs, the setter is intercepted and a call to setInputValue occurs which will sync the state with the ref value immediately. There's no edge cases to consider such as hover, tabbing, etc... because it's synced right away. |
I went ahead and put in a pull-request with the fix I mentioned above: #3533 |
@AnthonyPaulO Thanks. I also prefer that. I'll take a look at your solution tonight. |
Closing this PR. Will handle by #3533 |
Closes #3024
Closes #3436
📝 Description
Problem
inputValue
)isHovered
is updated, so re-render occurs.<Input/>
uses theinputValue
that is not updated to new value.Solve
when hover start,
setInputValues(domRef.current.value)
⛳️ Current behavior (updates)
2024-07-16.7.37.30.mov
🚀 New behavior
2024-07-16.6.45.31.mov
💣 Is this a breaking change (Yes/No):
📝 Additional Information
Summary by CodeRabbit
New Features
Tests
Input
component when used with React Hook Form.