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

fix: component as function call #7061

Merged
merged 1 commit into from
Nov 15, 2024
Merged
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
5 changes: 3 additions & 2 deletions packages/qwik/src/core/shared/component.public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type { QwikIntrinsicElements } from './jsx/types/jsx-qwik-elements';
import { assertQrl } from './qrl/qrl-class';
import { assertNumber } from './error/assert';
import { qTest } from './utils/qdev';
import { Virtual } from './jsx/jsx-runtime';

// TS way to check for any
type IsAny<T> = 0 extends T & 1 ? true : false;
Expand Down Expand Up @@ -139,7 +138,9 @@ export const componentQrl = <PROPS extends Record<any, any>>(
assertNumber(flags, 'The Qwik Component was not invoked correctly');
const hash = qTest ? 'sX' : componentQrl.$hash$.slice(0, 4);
const finalKey = hash + ':' + (key ? key : '');
return _jsxSplit(Virtual, props, null, props.children, flags, finalKey);
const InnerCmp = () => {};
(InnerCmp as any)[SERIALIZABLE_STATE] = [componentQrl];
return _jsxSplit(InnerCmp as any, props, null, props.children, flags, finalKey);
}
(QwikComponent as any)[SERIALIZABLE_STATE] = [componentQrl];
return QwikComponent as any;
Expand Down
69 changes: 67 additions & 2 deletions packages/qwik/src/core/tests/inline-component.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
Fragment as Component,
Fragment,
Fragment as InlineComponent,
Fragment as Projection,
Fragment as Signal,
Slot,
component$,
useSignal,
Expand Down Expand Up @@ -443,7 +445,7 @@ describe.each([
};

const { vNode } = await render(
<ComplexWrapper foo="bar">
<ComplexWrapper foo="aaa">
<div>
bar: <div id="1">Test</div>
</div>
Expand All @@ -454,7 +456,70 @@ describe.each([
<InlineComponent>
<Component>
<div>
bar: <div id="1">Test</div>
<Signal>aaa</Signal>
{': '}
<Projection>
<div>
{'bar: '}
<div id="1">Test</div>
</div>
</Projection>
</div>
</Component>
</InlineComponent>
);
});

it('should render component$ inside inlined wrapper - case 2', async () => {
interface ComplexWrapperProps {
foo: string;
aaa: string;
}

const ComplexWrapper = (
props: PublicProps<ComplexWrapperProps>,
key: string | null,
flags: number
) => {
const cmpFn = component$<ComplexWrapperProps>(({ foo }) => {
const cmpFn2 = component$<ComplexWrapperProps>(({ aaa }) => {
return (
<div>
{aaa}: <Slot />
</div>
);
});
return (
<div>
{foo}: <Slot />
{cmpFn2({ ...props, children: 'Test2' }, key, flags)}
</div>
);
});
return cmpFn(props, key, flags);
};

const { vNode } = await render(
<ComplexWrapper foo="bar" aaa="bbb">
Test
</ComplexWrapper>,
{ debug }
);

expect(vNode).toMatchVDOM(
<InlineComponent>
<Component>
<div>
<Signal>{'bar'}</Signal>
{': '}
<Projection>Test</Projection>
<Component>
<div>
<Signal>{'bbb'}</Signal>
{': '}
<Projection>Test2</Projection>
</div>
</Component>
</div>
</Component>
</InlineComponent>
Expand Down