-
Notifications
You must be signed in to change notification settings - Fork 473
2121 - prevent recurring initializeSearchInputs() calls in admin UI #2124
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
5ddc5d5 to
1114be2
Compare
1114be2 to
10ee939
Compare
The initializeSearchInputs() function was being called repeatedly every few seconds on table view tabs, causing performance issues and console log spam. This occurred due to multiple HTMX event listeners firing frequently without proper debouncing or initialization guards. Changes: - Added createMemoizedInit() utility function for generic initialization memoization with closure-based state management (no global variables) - Created memoized versions of initializeSearchInputs with debouncing - Updated DOMContentLoaded event listeners to use memoized versions - Added selective HTMX event handling (only relevant panel swaps) - Removed redundant htmx:load listener - Removed input cloning logic (no longer needed with memoization) - Added resetSearchInputsState() for explicit state cleanup The memoization pattern is reusable for other initialization functions and prevents duplicate initialization while providing explicit reset capability for cleanup scenarios. Signed-off-by: Gabriel Costa <[email protected]>
The memoization pattern allows re-initialization via reset calls on tab switches and HTMX swaps. Since search inputs persist (they're outside HTMX swap targets), this caused duplicate event listeners. Restore the input cloning logic to remove existing listeners before re-adding. Signed-off-by: Mihai Criveti <[email protected]>
…panel) The htmx:afterSwap handler was checking for 'servers-panel' but the actual panel ID in admin.html is 'catalog-panel'. This prevented search re-initialization after pagination or toggle changes in Virtual Servers. Signed-off-by: Mihai Criveti <[email protected]>
10ee939 to
21f576f
Compare
Review Feedback & FixesThanks for the PR! The memoization pattern is well-designed and reusable. During review, I identified two issues that I've fixed in additional commits: 1. Duplicate Event Listeners (Fixed in
|
🐛 Bug-fix PR
📌 Summary
This PR fixes issue 2121, where the
initializeSearchInputs()function was being called repeatedly every few seconds on table view tabs in the Admin UI, causing performance degradation and console log spam. The fix implements a generic memoization pattern with debouncing to prevent duplicate initialisation while maintaining proper search functionality across all tabs.Closes #2121
🔁 Reproduction Steps
🐞 Root Cause
The root cause was in the
DOMContentLoadedevent handler inmcpgateway/static/admin.js:htmx:afterSwap,htmx:load) fired on every content update, not just tab switchesinitializeSearchInputs()were never removed and kept accumulatingThe
initializeSearchInputs()function itself tried to prevent duplicate event listeners by cloning input elements, but this didn't address the root cause of the function being called repeatedly.💡 Fix Description
Implemented a generic memoization pattern with the following key features:
1. Created
createMemoizedInit()Utility Function{ init, debouncedInit, reset }functions2. Applied Memoization to
initializeSearchInputs()initializeSearchInputsMemoized,initializeSearchInputsDebouncedresetSearchInputsState()for explicit state cleanupwindowobject for manual cleanup scenarios3. Updated Event Listeners
initializeSearchInputsMemoized()for immediate initialisation on page loadinitializeSearchInputsDebounced()for HTMX and tab switch eventshtmx:loadlistenerresetSearchInputsState()calls before re-initialisation4. Simplified
initializeSearchInputs()Key Design Points:
🧪 Verification
make lintmake testmake coverage📝 Additional Notes
Future Reusability
This memoization pattern can be applied to other initialisation functions:
Performance Impact