Load frontend web components only when hosts are present#3691
Merged
Conversation
Avoid fetching unused component chunks on every page by scanning for host elements on initial load and after htmx swaps. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Assembler no longer serves that host, so the loader entry only kept a dead import path alive. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Use a linear scan with early continues, drop dead assembler-only registry entries, and avoid an extra promise hop for typing. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Mpdreamz
approved these changes
Jul 22, 2026
Member
Author
|
@copilot resolve the merge conflicts in this pull request |
Contributor
reakaleek
enabled auto-merge (squash)
July 22, 2026 10:29
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.
Why
Ordinary documentation pages were still requesting web-component chunks whose host elements are absent, which wasted first-party transfer and left large amounts of unused JavaScript on the critical path (see #3686).
What
Introduces a host-aware loader that imports each custom-element module only when its tag exists in the document, with deduplicated in-flight/completed loads and retries after failures. The loader runs on initial DOM readiness and again after htmx body swaps so components introduced by same-tab navigation still register.
Verified with unit tests for absent/present/swapped hosts, concurrent dedup, already-registered skips, and retry-after-failure; production build still emits separate component chunks; a host-free page fetched only
main.js, and inserting<version-dropdown>then dispatchinghtmx:loadregistered the element and fetched its chunk.Closes #3686
Made with Cursor