Remove unnecessary use of DOMContentLoaded#11127
Merged
Conversation
changelog: Internal, Performance, Remove unnecessary use of DOMContentLoaded
mitchellhenke
approved these changes
Aug 21, 2024
Contributor
mitchellhenke
left a comment
There was a problem hiding this comment.
Is it worth adding a lint to prevent adding DOMContentLoaded listeners?
aduth
commented
Aug 21, 2024
aduth
commented
Aug 22, 2024
| function formatSSNFieldAndLimitLength() { | ||
| const inputs = document.querySelectorAll<HTMLInputElement>('input.ssn-toggle[type="password"]'); | ||
|
|
||
| if (inputs) { |
Contributor
Author
There was a problem hiding this comment.
For awareness, I snuck an extra change in to remove this redundant condition. querySelectorAll will always return an array, and an array is always truthy.
See: https://dorey.github.io/JavaScript-Equality-Table/#if-statement
Contributor
Author
Possibly, yeah. Based on what we discovered here with legitimate usage, I might hold off on that until we remove all existing usage. |
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.
🛠 Summary of changes
Updates code which binds events to
DOMContentLoadedto execute immediately.This event is typically used to ensure that all content is present on a page before executing JavaScript, in case the script is loaded earlier than the elements it references. Packs are always loaded as the last content of every page (source), so it's not necessary to wait before referencing these elements.
This also relates to #11096 and #11126, where
deferhas the effect of delayingDOMContentLoadedbeing fired, unlike asynchronous scripts. We can offset this by not relying on theDOMContentLoaded.Reference: https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event
📜 Testing Plan
Verify no regressions in affected code:
Mock device profile on the SSN step of IdVEdit: Reverted in 509ccee