diff --git a/packages/sonnet-core/src/core/factory.ts b/packages/sonnet-core/src/core/factory.ts index ba32131..9b888d4 100644 --- a/packages/sonnet-core/src/core/factory.ts +++ b/packages/sonnet-core/src/core/factory.ts @@ -11,25 +11,25 @@ interface Component { script?: () => void; } -const EMPTY_HEAD = 'head(){return""}' -const EMPTY_SCRIPT = 'script(){}' +const EMPTY_HEAD = 'head(){return""}'; +const EMPTY_SCRIPT = 'script(){}'; export function $component(component: Component) { return (args?: T) => { const instance = new component(args); if (isBrowser()) { // head tags - if (component.head?.toString() !== EMPTY_HEAD) { + if (component.head && component.head.toString() !== EMPTY_HEAD) { event.once('head', component.head as () => SonnetHead); } - if (instance.head?.toString() !== EMPTY_HEAD) { + if (instance.head && instance.head.toString() !== EMPTY_HEAD) { event.on('head', instance.head.bind(instance)); } // scripts - if (component.script?.toString() !== EMPTY_SCRIPT) { + if (component.script && component.script.toString() !== EMPTY_SCRIPT) { event.once('script', component.script); } - if (instance.script?.toString() !== EMPTY_SCRIPT) { + if (instance.script && instance.script.toString() !== EMPTY_SCRIPT) { event.on('script', instance.script.bind(instance)); } }