feat: add @primer/view-components/lazy entrypoint with Catalyst lazyDefine#4140
Draft
mattcosta7 with Copilot wants to merge 3 commits into
Draft
feat: add @primer/view-components/lazy entrypoint with Catalyst lazyDefine#4140mattcosta7 with Copilot wants to merge 3 commits into
@primer/view-components/lazy entrypoint with Catalyst lazyDefine#4140mattcosta7 with Copilot wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: a414e0e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…atures, lazy.js input with comment
Copilot
AI
changed the title
[WIP] Add lazy entrypoint for custom elements registration
feat: add Jul 18, 2026
@primer/view-components/lazy entrypoint with Catalyst lazyDefine
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.
Adds an opt-in
@primer/view-components/lazyentrypoint so consumers can code-split Primer JS and only load element chunks on demand — without touching the default eager behavior.What are you trying to accomplish?
Today every custom element registers synchronously at import time via a single bundle. Consumers who only use a few components still pay the cost of all ~30 elements on every page load. This adds a lazy opt-in backed by
@github/catalyst'slazyDefineso elements register only when their tag appears in the DOM.Screenshots
N/A — no visual changes.
Integration
No changes required in production. The default entry is unchanged. Consumers must explicitly opt in to
@primer/view-components/lazy.List the issues that this change affects.
Risk Assessment
Additive only. Default entry untouched. New file, new export, new build output.
What approach did you choose and why?
app/components/primer/lazy.ts— singlelazyDefine({...})call (batch object form) mapping each of the 29 element tag names to a dynamicimport(). Side-effect-only modules (shared_events,utils) and base deps (@github/include-fragment-element,@github/remote-input-element) are imported eagerly since they have no custom element tag. ThelazyDefinecall is guarded withtypeof document !== 'undefined'for SSR safety.The trigger is DOM presence (Catalyst uses a MutationObserver; default strategy is
ready— fires afterDOMContentLoadedwhen the tag is in the DOM, not viewport intersection). NoIntersectionObserverspecial-casing is needed.rollup.config.js— changed from a single object to an array. The second config targetslazy.jswithformat: 'es',output.dir(code-split), andpreserveEntrySignatures: false. The existing IIFE build is untouched. SharedonwarnandterserOptionsextracted to avoid duplication.package.json—./lazysubpath export added before the./*catch-all:component_generator.thor— newregister_in_lazy_tsstep inserts entries intolazy.ts'slazyDefineobject via an// [GENERATOR ANCHOR]comment, keeping eager and lazy in sync for future scaffolded components.test/lib/js_entrypoints_test.rb— drift test: parsesprimer.tsimports andlazy.tsdynamic import paths by regex and asserts the sets are identical. Fails loudly if they diverge.docs/contributors/lazy-entrypoint.md— documents both entrypoints, DOM-presence trigger semantics,data-load-onoverride, and the sync enforcement mechanism.Anything you want to highlight for special attention from reviewers?
if (!customElements.get(tag)) customElements.define(...)) for dedup — no double-define risk.details-menu(→./alpha/dropdown),auto-complete,clipboard-copy,relative-time, andtab-containerare mapped via their wrapper modules, which in turn import the corresponding@github/*packages.Accessibility
No UI changes — no accessibility impact.
Merge checklist