fix: add keydownHandler and impove performance observers to inspector#160
Merged
fix: add keydownHandler and impove performance observers to inspector#160
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves lifecycle management in inspector.js by explicitly tracking/removing event listeners and PerformanceObserver instances, and simplifying the Performance tab rendering.
Changes:
- Track and clean up the document
keydownhandler via a dedicatedkeydownHandlerreference. - Track created
PerformanceObserverinstances inperformanceObserversand disconnect them during teardown. - Add a
destroy()teardown routine and simplify Performance tab UI rendering by removing several rendering sections.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request enhances the robustness and maintainability of the
inspector.jsmodule by improving event handler management, ensuring proper cleanup of resources, and refactoring some UI rendering logic. The most significant changes include explicit tracking and cleanup of event listeners and performance observers, as well as the removal of several rendering methods related to performance metrics.Event handler and observer management improvements:
keydownHandlerproperty to explicitly track the keyboard event handler, and updatedsetupKeyboardShortcutsto register and store this handler for later removal. [1] [2] [3]performanceObserversarray to track all registeredPerformanceObserverinstances, ensuring they are properly disconnected during cleanup. Each observer is now pushed to this array after creation. [1] [2] [3] [4] [5] [6] [7]Resource cleanup improvements:
destroymethod that removes the keyboard event listener, disconnects all performance observers, closes the inspector if open, and removes all injected DOM elements to prevent memory leaks and unintended side effects.UI rendering logic refactoring:
renderRenderTimeSection,renderDOMComplexitySection,renderWebVitalsSection, andrenderPageTimingsSectionmethods, simplifying the codebase and possibly centralizing or eliminating redundant UI rendering logic. [1] [2]Minor code cleanup: