Skip to content

Commit

Permalink
fix(controller): wrap unknown component function props to prevent inf…
Browse files Browse the repository at this point in the history
…inite loop
  • Loading branch information
BJvdA committed Dec 6, 2022
1 parent 2e55b63 commit 74dfe27
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/react/src/host/controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,18 @@ export function createController(
const value = registry.get(type as any);
if (value == null) {
if (!strictComponents) {
return type as any;
/** Wrap component to wrap function props in arrow functions */
return function ComponentWrapper(props) {
const safeProps = Object.keys(props).reduce((all, key) => {
const current = props[key];
all[key] =
current instanceof Function ? () => current() : current;
return all;
}, {} as typeof props);
const Component = type as any;

return <Component {...safeProps} />;
};
}

throw new Error(`Unknown component: ${type}`);
Expand Down

0 comments on commit 74dfe27

Please sign in to comment.