From 879dfb7bcae16361774a56c5be40741666431d62 Mon Sep 17 00:00:00 2001
From: Benny Powers <web@bennypowers.com>
Date: Mon, 17 Jun 2024 17:54:08 +0300
Subject: [PATCH] perf(cta): lazy-load icon dependency

---
 .changeset/few-buckets-cross.md | 4 ++++
 elements/rh-cta/rh-cta.ts       | 9 +++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)
 create mode 100644 .changeset/few-buckets-cross.md

diff --git a/.changeset/few-buckets-cross.md b/.changeset/few-buckets-cross.md
new file mode 100644
index 0000000000..d2f9c9e39f
--- /dev/null
+++ b/.changeset/few-buckets-cross.md
@@ -0,0 +1,4 @@
+---
+"@rhds/elements": patch
+---
+`<rh-cta>`: lazy-load the icon component dependency
diff --git a/elements/rh-cta/rh-cta.ts b/elements/rh-cta/rh-cta.ts
index 84b6aaa83b..58c7937622 100644
--- a/elements/rh-cta/rh-cta.ts
+++ b/elements/rh-cta/rh-cta.ts
@@ -12,8 +12,6 @@ import { colorContextConsumer, type ColorTheme } from '../../lib/context/color/c
 
 import style from './rh-cta.css';
 
-import '@patternfly/elements/pf-icon/pf-icon.js';
-
 export interface CtaData {
   href?: string;
   text?: string;
@@ -147,6 +145,13 @@ export class RhCta extends LitElement {
 
   #logger = new Logger(this);
 
+  protected override async getUpdateComplete(): Promise<boolean> {
+    if (this.icon) {
+      await import('@patternfly/elements/pf-icon/pf-icon.js');
+    }
+    return super.getUpdateComplete();
+  }
+
   get #isDefault(): boolean {
     return !this.hasAttribute('variant');
   }