Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: call components with .call to allow libs to provide class components with static .call methods #1260

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/solid/src/reactive/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ export function devComponent<T>(Comp: (props: T) => JSX.Element, props: T) {
() =>
untrack(() => {
Object.assign(Comp, { [$DEVCOMP]: true });
return Comp(props);
return Comp.call(Comp, props);
}),
undefined,
true
Expand Down
19 changes: 7 additions & 12 deletions packages/solid/src/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ export type FlowComponent<P = {}, C = JSX.Element> = Component<FlowProps<P, C>>;
/** @deprecated: use `ParentProps` instead */
export type PropsWithChildren<P = {}> = ParentProps<P>;

export type ValidComponent =
| keyof JSX.IntrinsicElements
| Component<any>
| (string & {});
export type ValidComponent = keyof JSX.IntrinsicElements | Component<any> | (string & {});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just formatting applied by prettier


/**
* Takes the props of the passed component and returns its type
Expand All @@ -77,13 +74,11 @@ export type ValidComponent =
* ComponentProps<typeof Portal> // { mount?: Node; useShadow?: boolean; children: JSX.Element }
* ComponentProps<'div'> // JSX.HTMLAttributes<HTMLDivElement>
*/
export type ComponentProps<T extends ValidComponent> =
T extends Component<infer P>
? P
:
T extends keyof JSX.IntrinsicElements
? JSX.IntrinsicElements[T]
: Record<string, unknown>;
export type ComponentProps<T extends ValidComponent> = T extends Component<infer P>
? P
: T extends keyof JSX.IntrinsicElements
? JSX.IntrinsicElements[T]
: Record<string, unknown>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just formatting applied by prettier


/**
* Type of `props.ref`, for use in `Component` or `props` typing.
Expand All @@ -99,7 +94,7 @@ export function createComponent<T>(Comp: Component<T>, props: T): JSX.Element {
setHydrateContext(nextHydrateContext());
const r = "_SOLID_DEV_"
? devComponent(Comp, props || ({} as T))
: untrack(() => Comp(props || ({} as T)));
: untrack(() => Comp.call(Comp, props || ({} as T)));
setHydrateContext(c);
return r;
}
Expand Down