Unverified Commit 282c1c9d authored by Maia Teegarden's avatar Maia Teegarden Committed by GitHub

Fix creation of styled jsx ids (#30124)

Ids of dynamic styles now match ids in dynamic class names (`_JSXStyle.dynamic()`) when there are mixed styles (global/static).

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] 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
parent d87955e8
......@@ -485,6 +485,7 @@ impl StyledJSXTransformer {
&style_info,
css,
self.style_import_name.as_ref().unwrap(),
self.static_class_name.as_ref(),
))
}
JSXStyle::External(style) => Ok(make_external_styled_jsx_el(
......@@ -533,6 +534,7 @@ impl StyledJSXTransformer {
&style,
css,
&self.style_import_name.as_ref().unwrap(),
self.static_class_name.as_ref(),
)))),
}))),
PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
......
......@@ -215,7 +215,12 @@ pub fn make_local_styled_jsx_el(
style_info: &LocalStyle,
css_expr: Expr,
style_import_name: &str,
static_class_name: Option<&String>,
) -> JSXElement {
let hash_input = match (&style_info.is_dynamic, &static_class_name) {
(true, Some(class_name)) => format!("{}{}", style_info.hash, class_name),
_ => style_info.hash.clone(),
};
let mut attrs = vec![JSXAttrOrSpread::JSXAttr(JSXAttr {
name: JSXAttrName::Ident(Ident {
sym: "id".into(),
......@@ -224,7 +229,7 @@ pub fn make_local_styled_jsx_el(
}),
value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer {
expr: JSXExpr::Expr(Box::new(string_literal_expr(
hash_string(&style_info.hash).as_str(),
hash_string(&hash_input).as_str(),
))),
span: DUMMY_SP,
})),
......
......@@ -67,7 +67,7 @@ export const Test4 = ({ color })=><div className={`jsx-${styles.__hash}` + " js
<_JSXStyle id={"ceba8c9ce34e3d0c"}>{"p.jsx-ceba8c9ce34e3d0c {display:inline-block}"}</_JSXStyle>
<_JSXStyle id={"5cadd6714ea141b4"} dynamic={[
<_JSXStyle id={"8f336bc49da94d3f"} dynamic={[
color
]}>{`p.__jsx-style-dynamic-selector {color:${color}}`}</_JSXStyle>
......@@ -105,7 +105,7 @@ export const Test6 = ({ color })=><div className={"jsx-ceba8c9ce34e3d0c " + _JS
<_JSXStyle id={"ceba8c9ce34e3d0c"}>{"p.jsx-ceba8c9ce34e3d0c {display:inline-block}"}</_JSXStyle>
<_JSXStyle id={"5cadd6714ea141b4"} dynamic={[
<_JSXStyle id={"8f336bc49da94d3f"} dynamic={[
color
]}>{`p.__jsx-style-dynamic-selector {color:${color}}`}</_JSXStyle>
......
......@@ -66,11 +66,11 @@ display:${obj.display}}`}</_JSXStyle>
<_JSXStyle id={"5cadd6714ea141b4"}>{`p.jsx-843124768056a74c {color:${color}}`}</_JSXStyle>
<_JSXStyle id={"6b2c0e0cad82feb7"} dynamic={[
<_JSXStyle id={"785cf5e120672da8"} dynamic={[
darken(color)
]}>{`p.__jsx-style-dynamic-selector {color:${darken(color)}}`}</_JSXStyle>
<_JSXStyle id={"6468493b508fe311"} dynamic={[
<_JSXStyle id={"108a316873f1c6fc"} dynamic={[
darken(color) + 2
]}>{`p.__jsx-style-dynamic-selector {color:${darken(color) + 2}}`}</_JSXStyle>
......@@ -87,7 +87,7 @@ div.jsx-843124768056a74c {background:${color}}`}</_JSXStyle>
<_JSXStyle id={"50cfd39d2a258beb"} dynamic={[
<_JSXStyle id={"a124d516c2c0707d"} dynamic={[
display ? "block" : "none"
]}>{`span.__jsx-style-dynamic-selector {display:${display ? "block" : "none"}}`}</_JSXStyle>
......
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