From c9e6b712b77c9ffbb09c7e850b320aa68bd16f25 Mon Sep 17 00:00:00 2001 From: Varixo Date: Wed, 13 Nov 2024 16:48:49 +0100 Subject: [PATCH] fix component as a function call --- .../qwik/src/core/shared/component.public.ts | 5 +- .../src/core/tests/inline-component.spec.tsx | 69 ++++++++++++++++++- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/packages/qwik/src/core/shared/component.public.ts b/packages/qwik/src/core/shared/component.public.ts index a1b6a96538a..d10acd38dcd 100644 --- a/packages/qwik/src/core/shared/component.public.ts +++ b/packages/qwik/src/core/shared/component.public.ts @@ -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 = 0 extends T & 1 ? true : false; @@ -139,7 +138,9 @@ export const componentQrl = >( 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; diff --git a/packages/qwik/src/core/tests/inline-component.spec.tsx b/packages/qwik/src/core/tests/inline-component.spec.tsx index 1289bc16aab..58eb5f2f1bd 100644 --- a/packages/qwik/src/core/tests/inline-component.spec.tsx +++ b/packages/qwik/src/core/tests/inline-component.spec.tsx @@ -2,6 +2,8 @@ import { Fragment as Component, Fragment, Fragment as InlineComponent, + Fragment as Projection, + Fragment as Signal, Slot, component$, useSignal, @@ -443,7 +445,7 @@ describe.each([ }; const { vNode } = await render( - +
bar:
Test
@@ -454,7 +456,70 @@ describe.each([
- bar:
Test
+ aaa + {': '} + +
+ {'bar: '} +
Test
+
+
+
+
+
+ ); + }); + + it('should render component$ inside inlined wrapper - case 2', async () => { + interface ComplexWrapperProps { + foo: string; + aaa: string; + } + + const ComplexWrapper = ( + props: PublicProps, + key: string | null, + flags: number + ) => { + const cmpFn = component$(({ foo }) => { + const cmpFn2 = component$(({ aaa }) => { + return ( +
+ {aaa}: +
+ ); + }); + return ( +
+ {foo}: + {cmpFn2({ ...props, children: 'Test2' }, key, flags)} +
+ ); + }); + return cmpFn(props, key, flags); + }; + + const { vNode } = await render( + + Test + , + { debug } + ); + + expect(vNode).toMatchVDOM( + + +
+ {'bar'} + {': '} + Test + +
+ {'bbb'} + {': '} + Test2 +
+