Skip to content

Commit da59cf0

Browse files
authored
Merge pull request #8141 from QwikDev/v2-fix-component-prop-set
fix: allow to modify inline component's children component props
2 parents 89a07ff + e20e531 commit da59cf0

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

.changeset/eager-coats-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik.dev/core': patch
3+
---
4+
5+
fix: allow to modify inline component's children component props

packages/qwik/src/core/shared/jsx/props-proxy.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,17 @@ class PropsProxyHandler implements ProxyHandler<any> {
5454
prop = attr;
5555
}
5656
}
57+
5758
if (this.owner.constProps && prop in this.owner.constProps) {
58-
this.owner.constProps[prop as string] = undefined;
59-
if (!(prop in this.owner.varProps)) {
60-
this.owner.toSort = true;
61-
}
62-
this.owner.varProps[prop as string] = value;
63-
} else {
64-
if (this.owner.varProps === EMPTY_OBJ) {
65-
this.owner.varProps = {};
66-
} else {
67-
if (!(prop in this.owner.varProps)) {
68-
this.owner.toSort = true;
69-
}
70-
}
71-
this.owner.varProps[prop as string] = value;
59+
// delete the prop from the const props first
60+
delete this.owner.constProps[prop as string];
61+
}
62+
if (this.owner.varProps === EMPTY_OBJ) {
63+
this.owner.varProps = {};
64+
} else if (!(prop in this.owner.varProps)) {
65+
this.owner.toSort = true;
7266
}
67+
this.owner.varProps[prop as string] = value;
7368
}
7469
return true;
7570
}

packages/qwik/src/core/tests/inline-component.spec.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
useSignal,
99
useStore,
1010
useVisibleTask$,
11+
type FunctionComponent,
1112
type PublicProps,
1213
} from '@qwik.dev/core';
1314
import { domRender, ssrRenderToDom, trigger } from '@qwik.dev/core/testing';
@@ -691,4 +692,29 @@ describe.each([
691692
</Component>
692693
);
693694
});
695+
696+
it('should allow to modify children component props', async () => {
697+
const Child = component$((props: { name: string }) => {
698+
return <>{props.name}</>;
699+
});
700+
701+
const Parent: FunctionComponent = (props) => {
702+
(props as any).children.props.name = 'World';
703+
return (props as any).children;
704+
};
705+
706+
const { vNode } = await render(
707+
<Parent>
708+
<Child name="Hello" />
709+
</Parent>,
710+
{ debug }
711+
);
712+
expect(vNode).toMatchVDOM(
713+
<InlineComponent>
714+
<Component>
715+
<Fragment>World</Fragment>
716+
</Component>
717+
</InlineComponent>
718+
);
719+
});
694720
});

0 commit comments

Comments
 (0)