Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/components/src/components/hds/breadcrumb/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ export default class HdsBreadcrumbItem extends Component<HdsBreadcrumbItemSignat
}
}

async resolveLinkToExternal() {
this.linkToExternal = await hdsResolveLinkToExternal(
this.args.isRouteExternal
);
resolveLinkToExternal() {
this.linkToExternal = hdsResolveLinkToExternal(this.args.isRouteExternal);
}

/**
Expand Down
8 changes: 3 additions & 5 deletions packages/components/src/components/hds/interactive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ export default class HdsInteractive extends Component<HdsInteractiveSignature> {

// we want to avoid resolving the component if it's not needed
if (args.isRouteExternal) {
void this.resolveLinkToExternal();
this.resolveLinkToExternal();
}
}

async resolveLinkToExternal() {
this.linkToExternal = await hdsResolveLinkToExternal(
this.args.isRouteExternal
);
resolveLinkToExternal() {
this.linkToExternal = hdsResolveLinkToExternal(this.args.isRouteExternal);
}
/**
* Determines if a @href value is "external" (it adds target="_blank" rel="noopener noreferrer")
Expand Down
25 changes: 14 additions & 11 deletions packages/components/src/utils/hds-resolve-link-to-external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@

import { LinkTo } from '@ember/routing';
import { assert } from '@ember/debug';
import {
dependencySatisfies,
macroCondition,
importSync,
} from '@embroider/macros';

/**
* Resolves the correct component to use for the `LinkTo`.
*
* @param isRouteExternal - If true, will return the `LinkToExternal` component. If `ember-engines` is not installed, an assertion will be thrown.
* @returns A promise resolving to the correct component to use for the `LinkTo`.
* @returns The correct component to use for the `LinkTo`.
*/
export async function hdsResolveLinkToExternal(
export function hdsResolveLinkToExternal(
isRouteExternal?: boolean
): Promise<typeof LinkTo> {
): typeof LinkTo {
if (isRouteExternal) {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const mod = await import(
// @ts-expect-error: we list this as optional peer dependency
if (macroCondition(dependencySatisfies('ember-engines', '*'))) {
// Use importSync for compile-time conditional import
const module = importSync(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const module = importSync(
const { default: module } = importSync(

'ember-engines/components/link-to-external-component'
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
return mod.default as typeof LinkTo;
} catch {
) as { default: typeof LinkTo };
return module.default;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return module.default;
return module;

} else {
assert(
`@isRouteExternal is only available when using the "ember-engines" addon. Please install it to use this feature.`,
false
Expand Down
Loading