-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: resolve custom modes disappearing and creation issues (#5855) #5856
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
Conversation
- Fix race condition in updateCustomMode method by reordering state refresh and cache clearing - Improve error handling and state recovery in refreshMergedState method - Add defensive checks for state consistency in getCustomModes method - Add comprehensive logging for debugging state issues - Ensure proper cache invalidation timing to prevent stale data - Add fallback recovery from global state when file operations fail - Validate merged modes before updating state to filter out invalid entries Fixes #5855
|
@roomote-agent use pr-reviewer mode to check this recent PR #5794, this should give you a base on how to fix this particular issue, we shouldn't allow any of the fields to be saved when empty, I recommend you start from scratch, extend the changes made on PR #5794 and update this PR when you are done |
|
I understand the issue. I will review PR #5794 to understand the validation approach for preventing empty fields from being saved, then start from scratch to extend those changes and fix the custom modes disappearing issue. I will ensure that no fields can be saved when empty and implement proper validation throughout the custom modes functionality. |
- Enhanced CustomModesManager.ts with comprehensive validation for all fields - Added validation for required fields (name, roleDefinition, slug) and optional fields (description, whenToUse, customInstructions) - Implemented checks to prevent empty strings from being saved (should be undefined instead) - Extended local state management pattern from PR #5794 to ALL editable fields in ModesView.tsx - Added local state variables for all fields: localModeName, localModeDescription, localModeRoleDefinition, localModeWhenToUse, localModeCustomInstructions - Implemented onFocus/onChange/onBlur pattern for all editable fields to prevent empty field saves - Users can now visually clear fields during editing but empty values are prevented from being saved - This prevents custom modes from disappearing due to empty field validation issues Fixes custom modes disappearing and creation issues by extending validation pattern from PR #5794
✅ Implementation CompleteI've successfully implemented comprehensive field validation for custom modes to fix the disappearing and creation issues. Here's what was done: 🔧 Backend Validation Enhancement ()
🎨 Frontend Validation Implementation ()
🛡️ Key Benefits
🧪 Testing
The implementation follows the exact approach recommended in your comment - starting from scratch and extending the validation pattern from PR #5794 to ensure no empty fields can be saved throughout the custom modes functionality. |
| setLocalModeRoleDefinition(currentValue) | ||
| }} | ||
| onChange={(e) => { | ||
| const value = |
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.
There’s a repeated pattern for extracting the new value from events: ' (e as unknown as CustomEvent)?.detail?.target?.value || ((e as any).target as HTMLTextAreaElement).value '. Consider extracting this logic to a small helper function to reduce repetition and improve readability.
This comment was generated because it violated a code review rule: irule_tTqpIuNs8DV0QFGj.
|
@roomote-agent the changes to src/core/config/CustomModesManager.ts seem unnecessary, I think PR #5794 did a good job on that file, revert all the changes made to that file, and then run pr-fixer mode on this PR #5856 since there are some review comments that are worth taking a look at and a failing unit test |
|
I understand. I'll revert all changes to src/core/config/CustomModesManager.ts since PR #5794 already handled that file properly, and then run pr-fixer mode to address the review comments and failing unit test. Starting now. |
…ted - PR #5794 already handled this properly
The ModesView component now checks for rules directory on mount, which was causing the test to fail. Updated the test to clear mock calls after mount and properly simulate the focus/change/blur sequence for field editing.
|
✅ PR Fixed Successfully I've addressed both issues you mentioned: 🔄 CustomModesManager.ts Changes Reverted
🧪 Unit Test Fixed
✅ Current Status
The PR now maintains the frontend validation improvements while removing the unnecessary backend changes. The custom modes functionality should work correctly with proper empty field validation. |
|
@roomote-agent address this comment by ellipsi-bot: "There’s a repeated pattern for extracting the new value from events: ' (e as unknown as CustomEvent)?.detail?.target?.value || ((e as any).target as HTMLTextAreaElement).value '. Consider extracting this logic to a small helper function to reduce repetition and improve readability." |
|
👋 I'll address the ellipsi-bot comment about extracting the repeated event value extraction pattern into a helper function. This will improve code readability and reduce repetition. Working on it now! |
… function - Add extractEventValue helper function to reduce code duplication - Replace 5 occurrences of repeated pattern with helper function call - Improves code readability and maintainability Addresses ellipsi-bot feedback about repeated pattern: (e as unknown as CustomEvent)?.detail?.target?.value || ((e as any).target as HTMLTextAreaElement).value
|
✅ Refactoring Complete I've successfully addressed the ellipsi-bot feedback about the repeated event value extraction pattern. Here's what was implemented: 🔧 Changes Made
📍 Locations Updated
🎯 Benefits
The refactoring maintains the exact same functionality while significantly improving code quality. CI checks are currently running to verify the changes. |
|
@roomote-agent address these points: UI state management complexity - The component now manages 7 separate state variables for editing. This could be simplified using a reducer pattern or consolidated state object. The solution should be a simple as possible without overengineering it. |
|
👋 I'll address the UI state management complexity and potential memory leak issues you've mentioned. I'll simplify the 7 separate state variables using a consolidated approach and ensure proper cleanup on component unmount. Working on a simple solution without overengineering it. |
- Consolidate 7 separate state variables into a single editingState object - Add useEffect cleanup to prevent memory leaks on component unmount - Maintain same functionality while simplifying state management - Addresses UI state management complexity and potential memory leak issues
|
✅ State Management Issues Resolved I've successfully addressed both issues you mentioned: 🔧 UI State Management Complexity Fixed
🛡️ Memory Leak Prevention Added
📋 Implementation Details
The solution is simple, clean, and addresses both concerns without overengineering. CI checks are currently running to verify the implementation. |
|
@roomote-agent fix this issue: Issue: Mode name disappears when editing other fields in ModesView.tsxLocation: webview-ui/src/components/modes/ModesView.tsx, lines 782-787 Cause: The mode name input uses editingState.currentEditingModeSlug === visualMode to determine whether to show local state or actual value. When ANY field starts editing, it sets currentEditingModeSlug, causing the name field to display the empty editingState.modeName instead of the actual mode name. Fix needed: The mode name field should check currentEditingField === 'modeName' instead of just checking currentEditingModeSlug, similar to how other fields handle their editing state. |
|
👋 I see the issue! The mode name field is incorrectly using editingState.currentEditingModeSlug === visualMode to determine display state, which causes it to show empty editingState.modeName when ANY field is being edited. I'll fix this by changing it to check currentEditingField === 'modeName' instead, just like the other fields. Working on it now! |
- Fix mode name input field to check currentEditingField === "modeName" instead of just currentEditingModeSlug - Add currentEditingField: "modeName" to onFocus handler to properly track field editing state - This prevents the mode name from showing empty local state when other fields are being edited Fixes the issue where mode name would disappear when editing description, role definition, or other fields in custom modes.
|
✅ Issue Fixed Successfully I've resolved the mode name disappearing issue you reported. Here's what was implemented: 🔧 Root Cause & Solution
📝 Changes Made
✅ Result
The fix has been pushed to the PR branch and CI checks are running. The solution is minimal, targeted, and consistent with the existing codebase patterns. |
daniel-lxs
left a comment
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.
LGTM
This PR fixes the issue where custom modes disappear and cannot be created, as reported in #5855.
Problem
Users reported that custom modes would disappear after creating a second one, and new custom modes could not be created. The issue was caused by race conditions and state synchronization problems in the CustomModesManager.
Root Cause Analysis
The issue was caused by several factors:
updateCustomModemethod where cache clearing happened before state refreshSolution
This PR implements comprehensive fixes:
🔧 Race Condition Fixes
updateCustomMode🛡️ Error Handling & Recovery
refreshMergedStatewith comprehensive error handling✅ Defensive Programming
getCustomModes📊 Enhanced Logging
Testing
Changes Made
src/core/config/CustomModesManager.ts:updateCustomModemethodrefreshMergedStatemethodgetCustomModesmethodFixes #5855
Important
Fixes custom modes disappearing and creation issues by addressing race conditions, enhancing error handling, and updating tests.
updateCustomModeinCustomModesManager.tsby reordering state refresh before cache clearing.refreshMergedStateand adds fallback recovery from global state.getCustomModes.ModesView.tsxto prevent saving empty values.ModesView.spec.tsxto test mode selection, prompt changes, and reset behavior for built-in and custom modes.extractEventValuehelper function inModesView.tsxfor event value extraction.This description was created by
for 73253cf. You can customize this summary. It will automatically update as commits are pushed.