Repository navigation
Avoid storing outside DOM elements on custom element instances - #4019
Draft
PhilippeCollin wants to merge 2 commits into
Draft
PhilippeCollin wants to merge 2 commits into
PhilippeCollin wants to merge 2 commits into
Conversation
PhilippeCollin
force-pushed
the
fix-stored-outside-elements
branch
from
November 24, 2026 15:30
f938bd0 to
bd590a4
Compare
This branch has not been deployed
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.
PR Summary:
Avoid caching references to outside DOM elements on custom element instances so elements continue working cleanly when other sections or components are dynamically re-rendered.
Why are these changes introduced?
When a section or custom element is replaced dynamically (for example via the Section Rendering API or in the theme editor), other custom elements that remain on the page can hold stale references to detached DOM nodes if they cached document-wide lookups on
thisduring construction.This draft PR shows the changes surfaced by the proposed
theme/no-stored-outside-elementESLint rule in Shopify/theme-tools#1413 across Dawn's custom elements.What approach did you take?
Across Dawn's 36 JS files, the rule reported 13 warnings in 12 files:
assets/product-form.js,assets/cart-notification.jsheader,assets/details-disclosure.js,assets/localization-form.js,assets/main-search.js,assets/predictive-search.js,assets/price-per-item.js): look up the element on demand via a getter instead of caching it once inconstructor().isConnectedcheck (assets/global.jsHeaderDrawer.header,assets/quick-order-list.jsstickyHeaderElement): both are read duringresize/scroll handlers, so they reuse the cached node while it stays connected and re-query if replaced.this.querySelector(...)(assets/cart-notification.jsnotification,assets/cart.jslineItemStatusElement):#cart-notification,#shopping-cart-line-item-status, and#CartDrawer-LineItemStatuslive inside their respective custom elements, so scoping tothisavoids document-wide queries altogether.const(assets/media-gallery.jspreventStickyHeader):this.stickyHeaderwas only read inside that method.assets/cart-disclosure-modal.jsthis.opener):<cart-disclosure-modal>moves itself todocument.body, explicitly observesthis.opener?.isConnectedvia aMutationObserver, and removes itself when its opener disconnects.Visual impact on existing themes
None.