Skip to content

Commit

Permalink
fix(satori): transform inner components
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Nov 1, 2024
1 parent e0d1084 commit ff130d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ export class Session<C extends Context = Context> {
}

async transform(elements: h[]): Promise<h[]> {
return await h.transformAsync(elements, ({ type, attrs, children }, session) => {
return await h.transformAsync(elements, async ({ type, attrs, children }, session) => {
const render = type === 'component' ? attrs.is : this.app.get('component:' + type)
return render?.(attrs, children, session) ?? true
if (!render) return true
children = await render(attrs, children, session)
return this.transform(h.toElementArray(children))
}, this)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/element/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ElementConstructor {
defineProperty(ElementConstructor, 'name', 'Element')
defineProperty(ElementConstructor.prototype, kElement, true)

type RenderFunction = Element.Render<Element.Fragment, any>
type RenderFunction = Element.Render<Element.Fragment, Awaitable<Element.Fragment>>

function Element(type: string | RenderFunction, ...children: Element.Fragment[]): Element
function Element(type: string | RenderFunction, attrs: Dict, ...children: Element.Fragment[]): Element
Expand Down

0 comments on commit ff130d7

Please sign in to comment.