Hello there,
We currently have a decorator that essentially just calls @customElement
behind the scene and adds some default dependencies/options to it:
import { type Constructable, type Key } from '@aurelia/kernel';
import { type PartialCustomElementDefinition } from '@aurelia/runtime-html';
import { customElement, shadowCSS } from '@aurelia/runtime-html';
export function xElement(
name: string,
opts: Omit<PartialCustomElementDefinition, 'name' | 'shadowOptions' | 'dependencies'> & { style?: string },
dependencies: Key[] = []
) {
const { style, ...rest } = opts;
if (style) {
dependencies.push(shadowCSS(style));
}
return <T extends Constructable>(Type: T, context: ClassDecoratorContext) =>
customElement({ ...rest, name, shadowOptions: { mode: 'open' }, dependencies })(Type, context);
}
For some reason though, I encounter an issue like this:
// my-app.ts
import { ComponentA } from "./component-a";
import template from "./my-app.html";
import { xElement } from "./x-element";
@xElement("my-app", { template }, [ComponentA]) //<------------
export class MyApp {}
<!-- my-app.html -->
<div>my app</div>
<!-- this does not render at all -->
<!-- even if ComponentA is already added as a dependency -->
<!-- in the associated controller -->
<component-a></component-a>
But when I change the name of the custom decorator into customElement
, everything works:
// my-app.ts
import { ComponentA } from "./component-a";
import template from "./my-app.html";
import { xElement as customElement} from "./x-element"; //<-------------
@customElement("my-app", { template }, [ComponentA]) //<------------
export class MyApp {}
<!-- my-app.html -->
<div>my app</div>
<!-- Now this component is rendered -->
<component-a></component-a>
Honestly I’m good with this solution but I’m just wondering why the name of the decorator has to be customElement
.
I am currently using Aurelia V2, with Vite and Typescript.
Thank you.