Unverified Commit 4264408b authored by LongYinan's avatar LongYinan Committed by GitHub

Fix emotion shouldForwardProp options breaks component selectors (#39390)

fixes https://github.com/vercel/next.js/issues/38291



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent b30ae643
...@@ -62,7 +62,9 @@ export const Pink = styled(Basic)({ ...@@ -62,7 +62,9 @@ export const Pink = styled(Basic)({
color: 'hotpink', color: 'hotpink',
}) })
export const BasicExtended = styled(Basic)`` export const BasicExtended = styled(Basic, {
shouldForwardProp: (propertyName: string) => !propertyName.startsWith('$'),
})``
export const ComponentSelectorsExtended = styled.div` export const ComponentSelectorsExtended = styled.div`
${BasicExtended} { ${BasicExtended} {
......
...@@ -480,13 +480,28 @@ impl<C: Comments> Fold for EmotionTransformer<C> { ...@@ -480,13 +480,28 @@ impl<C: Comments> Fold for EmotionTransformer<C> {
if let Some(cm) = self.create_sourcemap(expr.span.lo()) { if let Some(cm) = self.create_sourcemap(expr.span.lo()) {
expr.args.push(cm.as_arg()); expr.args.push(cm.as_arg());
} }
c.args.push( if let Some(ExprOrSpread { expr, .. }) = c.args.get_mut(1) {
Expr::Object(ObjectLit { if let Expr::Object(ObjectLit { props, .. }) = expr.as_mut()
span: DUMMY_SP, {
props: args_props, props.extend(args_props);
}) } else {
.as_arg(), c.args.push(
); Expr::Object(ObjectLit {
span: DUMMY_SP,
props: args_props,
})
.as_arg(),
);
}
} else {
c.args.push(
Expr::Object(ObjectLit {
span: DUMMY_SP,
props: args_props,
})
.as_arg(),
);
}
} }
} }
} }
...@@ -592,14 +607,27 @@ impl<C: Comments> Fold for EmotionTransformer<C> { ...@@ -592,14 +607,27 @@ impl<C: Comments> Fold for EmotionTransformer<C> {
}), }),
))); )));
} }
if let Some(ExprOrSpread { expr, .. }) = callee.args.get_mut(1) {
callee.args.push( if let Expr::Object(ObjectLit { props, .. }) = expr.as_mut() {
Expr::Object(ObjectLit { props.extend(object_props);
span: DUMMY_SP, } else {
props: object_props, callee.args.push(
}) Expr::Object(ObjectLit {
.as_arg(), span: DUMMY_SP,
); props: object_props,
})
.as_arg(),
);
}
} else {
callee.args.push(
Expr::Object(ObjectLit {
span: DUMMY_SP,
props: object_props,
})
.as_arg(),
);
}
return Expr::Call(CallExpr { return Expr::Call(CallExpr {
span: DUMMY_SP, span: DUMMY_SP,
callee: callee.as_callee(), callee: callee.as_callee(),
......
...@@ -28,6 +28,12 @@ const DivContainer2 = styled.div` ...@@ -28,6 +28,12 @@ const DivContainer2 = styled.div`
background: red; background: red;
` `
const ContainerWithOptions = styled('div', {
shouldForwardProp: (propertyName: string) => !propertyName.startsWith('$'),
})`
color: hotpink;
`
const SpanContainer = styled('span')({ const SpanContainer = styled('span')({
background: 'yellow', background: 'yellow',
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment