Skip to content

Commit 252078a

Browse files
committed
Spread out unused props based on type
1 parent 39bcc00 commit 252078a

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/internal/emit-wrappers/emit-intrinsic.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,22 @@ export function emitIntrinsicWrappers(ctx: any): {
18971897
}
18981898
}
18991899

1900+
// Extract transient props (starting with $) from the explicit type and add to destructureProps
1901+
// so they get stripped from the rest spread (styled-components transient props should never reach DOM)
1902+
const explicit = d.propsType;
1903+
if (explicit?.type === "TSTypeLiteral" && explicit.members) {
1904+
for (const member of explicit.members as any[]) {
1905+
if (
1906+
member.type === "TSPropertySignature" &&
1907+
member.key?.type === "Identifier" &&
1908+
member.key.name.startsWith("$") &&
1909+
!destructureProps.includes(member.key.name)
1910+
) {
1911+
destructureProps.push(member.key.name);
1912+
}
1913+
}
1914+
}
1915+
19001916
const usedAttrs = getUsedAttrs(d.localName);
19011917
const { hasAny: hasLocalUsage } = getJsxCallsites(d.localName);
19021918
const explicitPropsNames = d.propsType ? getExplicitPropNames(d.propsType) : new Set<string>();

test-cases/transient-props.output.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,8 @@ type PointProps = {
3232
// Pattern 3: Transient prop with dynamic value passed to inlined component
3333
// The prop is declared in type but not used in styles - must be stripped when inlined
3434
function Point(props: PointProps) {
35-
const { children, style, ...rest } = props;
36-
return (
37-
<div {...rest} {...mergedSx(styles.point, undefined, style)}>
38-
{children}
39-
</div>
40-
);
35+
const { children, style, $size } = props;
36+
return <div {...mergedSx(styles.point, undefined, style)}>{children}</div>;
4137
}
4238

4339
// Pattern 4: styled(Component) where base component declares the transient prop

0 commit comments

Comments
 (0)