Skip to content

Commit 724fa4c

Browse files
committed
Re-shape getComponent function
1 parent aa79734 commit 724fa4c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

packages/optimizely-cms-sdk/src/render/componentRegistry.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function hasVariants(obj: unknown): obj is ComponentWithVariants<unknown> {
5353
}
5454

5555
/** Returns the default component in an {@linkcode ComponentEntry} */
56-
function getDefaultComponent<C>(entry: ComponentEntry<C>): C {
56+
function getDefaultComponent<C>(entry: ComponentEntry<C>): C | undefined {
5757
if (hasVariants(entry)) {
5858
return entry.default;
5959
} else {
@@ -100,21 +100,23 @@ export class ComponentRegistry<T> {
100100

101101
const entry = this.resolver[contentType];
102102

103-
if (!entry) {
104-
return undefined;
105-
}
106-
107103
if (!options.tag) {
104+
if (!entry) {
105+
return undefined;
106+
}
108107
return getDefaultComponent(entry);
109108
}
110109

111-
// Search for the component `${contentType}:${tag}`
112110
const taggedEntry = this.resolver[`${contentType}:${options.tag}`];
113111

114112
if (taggedEntry) {
115113
return getDefaultComponent(taggedEntry);
116114
}
117115

116+
if (!entry) {
117+
return undefined;
118+
}
119+
118120
return (
119121
// Search for the component with the tag in the component definition
120122
getTagComponent(entry, options.tag) ??

0 commit comments

Comments
 (0)