Skip to content

fix(tag-dropdown): last char dropped bug#945

Merged
icecrasher321 merged 1 commit intostagingfrom
fix/tag-dropdown-chardrop
Aug 12, 2025
Merged

fix(tag-dropdown): last char dropped bug#945
icecrasher321 merged 1 commit intostagingfrom
fix/tag-dropdown-chardrop

Conversation

@icecrasher321
Copy link
Collaborator

Summary

The closing bracket ('>') was triggering an effect to close the tag dropdown, that was racing with the entry of the last character. Could be the cause of the bug. Use live dom tracking in the tag dropdown to prevent this. Also move set cursor before store value setter for extra precaution.

Type of Change

  • Bug fix

Testing

Tested manually typing out variable values.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Aug 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Project Deployment Preview Comments Updated (UTC)
sim 🔄 Building Preview Comment Aug 12, 2025 4:44pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs ⬜️ Skipped Aug 12, 2025 4:44pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR fixes a race condition bug in the tag dropdown functionality where the last character would be dropped when users typed variable values ending with a closing bracket '>'.

The core issue occurred because React's asynchronous state updates created timing problems between the tag dropdown's closure logic and character entry processing. When users typed a closing bracket, it would trigger the checkTagTrigger function to close the dropdown while simultaneously trying to process that final character, resulting in the character being lost.

The fix implements two key strategies across multiple input components (short-input, long-input, code, combobox, and iteration-badges):

  1. State Update Ordering: The cursor position (setCursorPosition) is now updated before the store value (setStoreValue) in all input change handlers. This ensures that dropdown logic operating on cursor position has access to the most current state when making decisions about whether to show or hide the tag dropdown.

  2. Live DOM Tracking: In the tag-dropdown.tsx component, the handleTagSelect function now reads directly from the DOM's active element to get the current cursor position and input value, rather than relying solely on potentially stale React state. This prevents the tag replacement logic from operating on outdated information.

The changes are applied consistently across all input components that interact with the tag dropdown system, including text inputs, textareas, code editors, and comboboxes. The fix maintains backward compatibility by using fallback values when DOM access isn't available, and doesn't alter the fundamental logic flow of these components.

Confidence score: 4/5

  • This PR addresses a specific, well-identified race condition with a targeted solution that doesn't introduce breaking changes
  • The fix is applied consistently across multiple input components, showing thorough consideration of the problem
  • Pay close attention to the tag dropdown interaction logic and ensure manual testing covers various typing speeds and patterns

6 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

Comment on lines +883 to +885
if (typeof (activeEl as any).value === 'string') {
liveValue = (activeEl as any).value
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: The (activeEl as any).value type assertion could be more specific. Consider type guard or explicit HTMLInputElement/HTMLTextAreaElement check

Context Used: Context - Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used to maintain type safety. (link)

@icecrasher321 icecrasher321 merged commit 1a7de84 into staging Aug 12, 2025
4 of 5 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/tag-dropdown-chardrop branch August 15, 2025 17:04
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
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.

1 participant