Skip to content

Commit

Permalink
fix: template slots not passing through ExternalComponents (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
prevwong authored May 15, 2023
1 parent 6f81ace commit de97826
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/violet-tips-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rekajs/types': patch
'@rekajs/core': patch
---

Fix template slots not passing through ExternalComponents
9 changes: 9 additions & 0 deletions packages/core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,21 @@ export class ComponentViewEvaluator {
this.rekaComponentPropsComputation = null;
this.rekaComponentStateComputation = null;

const children = this.template.children.flatMap((child) =>
this.evaluator.computeTemplate(child, {
...this.ctx,
path: [...this.ctx.path, child.id],
owner: this.ctx.owner,
})
);

return [
t.externalComponentView({
frame: this.evaluator.frame.id,
component,
key: this.key,
template: this.template,
children: children || [],
props: Object.keys(this.template.props).reduce(
(accum, key) => ({
...accum,
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/generated/types.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,13 @@ type ExternalComponentViewParameters = {
frame: string;
owner?: ComponentView | null;
component: ExternalComponent;
children?: View[];
props: Record<string, string | number | boolean | Function>;
};

export class ExternalComponentView extends ComponentView {
declare component: ExternalComponent;
declare children: View[];
declare props: Record<string, string | number | boolean | Function>;
constructor(value: ExternalComponentViewParameters) {
super('ExternalComponentView', value);
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/types.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ Schema.define('ExternalComponentView', {
extends: 'ComponentView',
fields: (t) => ({
component: t.node('ExternalComponent'),
children: t.defaultValue(t.array(t.node('View')), []),
props: t.map(t.union(t.string, t.number, t.boolean, t.func)),
}),
});
Expand Down
7 changes: 6 additions & 1 deletion site/components/frame/Renderer/Renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ const RenderExternalComponentView = observer(
}, [onConnect, props.view]);

return React.cloneElement(
props.view.component.render({ ...props.view.props }),
props.view.component.render({
...props.view.props,
children: props.view.children.map((child) => (
<InternalRenderer key={child.id} view={child} />
)),
}),
{
ref: domRef,
}
Expand Down

0 comments on commit de97826

Please sign in to comment.