diff --git a/examples/ssr/app.template.html b/examples/ssr/app.template.html index 38174c9..d546a8c 100644 --- a/examples/ssr/app.template.html +++ b/examples/ssr/app.template.html @@ -1,6 +1,7 @@ + Hello {{ head }} diff --git a/src/render.ts b/src/render.ts index abc338b..a132253 100644 --- a/src/render.ts +++ b/src/render.ts @@ -12,7 +12,8 @@ import type { MetaRendered, MetaTagConfigKey, SlotScopeProperties, - TODO + TODO, + ExcludesFalsy } from './types' const cachedElements: { @@ -77,6 +78,7 @@ export function renderGroup ( return renderTag(context, key, data[childKey], config as MetaConfigSectionTag, groupConfig) }) + .filter(Boolean as any as ExcludesFalsy) .flat() } @@ -86,7 +88,7 @@ export function renderTag ( data: TODO, config: MetaConfigSectionTag = {}, groupConfig?: MetaGroupConfig -): MetaRendered | MetaRenderedNode { +): MetaRendered | MetaRenderedNode | void { // console.info('renderTag', key, data, config, groupConfig) const contentAttributes = ['content', 'json', 'rawContent'] @@ -97,6 +99,7 @@ export function renderTag ( .map((child) => { return renderTag(context, key, child, config, groupConfig) }) + .filter(Boolean as any as ExcludesFalsy) .flat() } @@ -118,7 +121,7 @@ export function renderTag ( return data.map(({ vnode }) => vnode) } - return data.vnode + return data && data.vnode }) } else { let i = 0 @@ -194,6 +197,11 @@ export function renderTag ( ? `${groupConfig.tagNamespace}:${tag}` : tag + if (finalTag === 'title' && !context.isSSR) { + document.title = content + return + } + // console.info('FINAL TAG', finalTag) // console.log(' ATTRIBUTES', attributes) // console.log(' CONTENT', content) diff --git a/src/types/index.ts b/src/types/index.ts index 27eb4cb..2615834 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,6 +6,9 @@ export * from './config' export type Modify = Omit & R; +export type Truthy = T extends undefined | void | null | false | 0 | '' ? never : T +export type ExcludesFalsy = (x: T) => x is Truthy + export type TODO = any /**