5.6 KiB
5.6 KiB
LLM Event Handlers Refactor Issues
This document lists the issues found in the js/sidebar/llmTab/shared event handler files after the refactor, along with the fixes that should be applied.
Summary
The refactor introduced multiple mismatches between event wiring and handler signatures, as well as a few stale/unwired functions. The following issues were found in these files:
llmEventHandlers.jsllmProviderEvents.jsllmPresetEvents.jsllmHistoryEvents.jsllmVisionEvents.js
Current Status
- ✅ Fixed: paste handler registration and cleanup wiring in
llmEventHandlers.js - ✅ Fixed:
handleModelChangenow receivesvisionSectioninllmProviderEvents.js - ✅ Fixed: preset event handler argument lists now match between
llmEventHandlers.jsandllmPresetEvents.js - ✅ Fixed:
handleSaveToHistoryClicknow receivesupdateConversationList - ✅ Fixed:
resetSettingsBtnis now wired toresetSettingsToDefaults - ✅ Fixed:
state.selectedExtrasinitialization added inllmTemplateEvents.js - ✅ Fixed: dead helper functions and unused DOM queries in
llmEventHandlers.js - ✅ Fixed: vision preview cleanup selector now matches actual DOM structure
1. llmEventHandlers.js
1.1 Paste handler wiring
- Status: ✅ Fixed
- Change:
- Created the paste handler once
- Attached it with
document.addEventListener('paste', handler) - Stored it on
state._pasteHandler - Cleanup remains in
cleanupEventHandlers(state)using the stored handler
1.2 Unused resetSettingsBtn
- Status: ✅ Fixed
- Change:
- Wired
resetSettingsBtntoresetSettingsToDefaults
- Wired
1.3 Unused internal helpers
- Status: ✅ Fixed
- Change:
setupComposeTemplateHandlersandsetupSettingsEventHandlersare now invoked fromsetupEventHandlers().
1.4 History event action wiring
- Status: ✅ Fixed
- Change:
handleSaveToHistoryClicknow receivesupdateConversationListfromsetupEventHandlers
1.5 Unused wrapper and previewGrid variables
- Status: ✅ Fixed
- Change:
- Removed the unused
wrapperparameter fromsetupEventHandlers()inllmEventHandlers.js. - Removed unused preview-related DOM queries
previewGridandimageCount.
- Removed the unused
2. llmProviderEvents.js
2.1 Missing visionSection parameter in handleModelChange
- Status: ✅ Fixed
- Change:
- Added
visionSectionto the function signature inllmProviderEvents.js - Updated the caller in
llmEventHandlers.jsto passvisionSection
- Added
2.2 Potential use of showProviderOptions and updateCapabilityControlledOptions
- Status: ✅ Confirmed
- Note:
setupEventHandlersalready passes both functions correctly.
3. llmPresetEvents.js
3.1 Handler signature mismatch for handlePresetChange
- Status: ✅ Fixed
- Change:
- Updated
handlePresetChangeinllmPresetEvents.jsto accept the actual call-site arguments. - Updated
llmEventHandlers.jsto passloadPresets,showNotification,advancedOptions,inputSection, andapplyPresetToUI.
- Updated
3.2 Handler signature mismatch for handleManagePresetsClick
- Status: ✅ Fixed
- Change:
- Updated
llmEventHandlers.jsto passadvancedOptions,inputSection,loadPresets,applyPresetToUI, andshowNotification.
- Updated
3.3 Handler signature mismatch for handleSavePresetClick
- Status: ✅ Confirmed
- Note:
handleSavePresetClickalready matches its caller.
4. llmHistoryEvents.js
4.1 Undefined updateConversationList usage
- Status: ✅ Fixed
- Change:
handleSaveToHistoryClicknow receivesupdateConversationListas a parameter.llmEventHandlers.jsnow passesupdateConversationListinto the handler.
4.2 Event binding logic in llmEventHandlers.js
- Status: ⚠️ Needs review
- Note:
handleNewConversationClickcurrently does not takeupdateConversationList, but it usesllmUpdateConvListinternally and is likely sufficient.- If a future refactor needs the shared
updateConversationListfunction instead, this can be updated then.
5. llmVisionEvents.js
5.1 Paste handler logic
- Status: ✅ Fixed
- Change:
llmEventHandlers.jsnow attaches the returned handler todocument.addEventListener('paste', handler).- The handler is stored on
state._pasteHandlerfor cleanup.
5.2 handleClearAllImagesClick cleanup
- Status: ✅ Fixed
- Change:
- Updated the handler to use the actual preview DOM structure of
.llm-image-preview-itemand.llm-preview-image.
- Updated the handler to use the actual preview DOM structure of
6. Possible hidden issues
6.1 state.selectedExtras initialization
- Status: ✅ Fixed
- Change:
llmTemplateEvents.handleExtrasChangenow initializesstate.selectedExtras = state.selectedExtras || {}before use.
6.2 saveSettings context and calls
- Some handlers call
saveSettings(state.settings)withthisbinding via.call(null, ...)inllmProviderEvents.js. - This is unusual but not necessarily wrong.
- Fix:
- Confirm
saveSettingsdoes not rely onthis; if it does, remove.call(null, ...)and call directly.
- Confirm
6.3 Code duplication and dead code
- The file
llmEventHandlers copy.jsappears to be a backup/copy and should not be part of normal execution. - Fix:
- Keep it as a backup if desired, but do not modify it as part of the fix.
Remaining items
handleNewConversationClickstill uses its internalllmUpdateConvListpath rather than the sharedupdateConversationListcallback. This is acceptable for now, but it can be standardized later if desired.
Notes
- This document now tracks the issue review and fix status for
js/sidebar/llmTab/shared/*. - The high-priority refactor issues identified earlier have been addressed.