Unverified Commit 4a5fc41b authored by Maia Teegarden's avatar Maia Teegarden Committed by GitHub

Fix dynamic style issue (#29163)

* Fix dynamic style issue

* Update affected tests

* Build next-swc binaries

* Remove clone

* Build next-swc binaries
parent adf7fa67
...@@ -29,12 +29,12 @@ pub fn compute_class_names( ...@@ -29,12 +29,12 @@ pub fn compute_class_names(
let mut dynamic_styles = vec![]; let mut dynamic_styles = vec![];
let mut external_styles = vec![]; let mut external_styles = vec![];
for style_info in styles { for style_info in styles {
match &style_info { match style_info {
JSXStyle::Local(style_info) => { JSXStyle::Local(style_info) => {
if !style_info.is_dynamic { if !style_info.is_dynamic {
static_hashes.push(style_info.hash.clone()); static_hashes.push(style_info.hash.clone());
} else { } else {
dynamic_styles.push(style_info.clone()); dynamic_styles.push(style_info);
} }
} }
JSXStyle::External(external) => { JSXStyle::External(external) => {
...@@ -82,43 +82,49 @@ pub fn compute_class_names( ...@@ -82,43 +82,49 @@ pub fn compute_class_names(
span: DUMMY_SP, span: DUMMY_SP,
computed: false, computed: false,
}))), }))),
args: dynamic_styles args: vec![ExprOrSpread {
.iter() expr: Box::new(Expr::Array(ArrayLit {
.map(|style_info| { elems: dynamic_styles
let hash_input = match &static_class_name { .iter()
Some(class_name) => format!("{}{}", style_info.hash, class_name), .map(|style_info| {
None => style_info.hash.clone(), let hash_input = match &static_class_name {
}; Some(class_name) => format!("{}{}", style_info.hash, class_name),
ExprOrSpread { None => style_info.hash.clone(),
expr: Box::new(Expr::Array(ArrayLit { };
elems: vec![ Some(ExprOrSpread {
Some(ExprOrSpread { expr: Box::new(Expr::Array(ArrayLit {
expr: Box::new(string_literal_expr(&hash_string(&hash_input))), elems: vec![
spread: None, Some(ExprOrSpread {
}), expr: Box::new(string_literal_expr(&hash_string(&hash_input))),
Some(ExprOrSpread { spread: None,
expr: Box::new(Expr::Array(ArrayLit { }),
elems: style_info Some(ExprOrSpread {
.expressions expr: Box::new(Expr::Array(ArrayLit {
.iter() elems: style_info
.map(|expression| { .expressions
Some(ExprOrSpread { .iter()
expr: expression.clone(), .map(|expression| {
spread: None, Some(ExprOrSpread {
}) expr: expression.clone(),
}) spread: None,
.collect(), })
span: DUMMY_SP, })
})), .collect(),
spread: None, span: DUMMY_SP,
}), })),
], spread: None,
span: DUMMY_SP, }),
})), ],
spread: None, span: DUMMY_SP,
} })),
}) spread: None,
.collect(), })
})
.collect(),
span: DUMMY_SP,
})),
spread: None,
}],
span: DUMMY_SP, span: DUMMY_SP,
type_args: None, type_args: None,
})), })),
......
...@@ -14,15 +14,19 @@ export const Test2 = ()=><div className={"jsx-81a68341e430a972 " + `jsx-${styles ...@@ -14,15 +14,19 @@ export const Test2 = ()=><div className={"jsx-81a68341e430a972 " + `jsx-${styles
</div> </div>
; ;
export const Test3 = ({ color })=><div className={`jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([ export const Test3 = ({ color })=><div className={`jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([
"26b457d3bc475235",
[ [
color "26b457d3bc475235",
[
color
]
] ]
])}> ])}>
<p className={`jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([ <p className={`jsx-${styles.__hash}` + " " + _JSXStyle.dynamic([
"26b457d3bc475235",
[ [
color "26b457d3bc475235",
[
color
]
] ]
])}>external and dynamic</p> ])}>external and dynamic</p>
<_JSXStyle id={"26b457d3bc475235"} dynamic={[ <_JSXStyle id={"26b457d3bc475235"} dynamic={[
...@@ -32,15 +36,19 @@ export const Test3 = ({ color })=><div className={`jsx-${styles.__hash}` + " " ...@@ -32,15 +36,19 @@ export const Test3 = ({ color })=><div className={`jsx-${styles.__hash}` + " "
</div> </div>
; ;
export const Test4 = ({ color })=><div className={`jsx-${styles.__hash}` + " jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([ export const Test4 = ({ color })=><div className={`jsx-${styles.__hash}` + " jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([
"e6cca97eb9ca1a15",
[ [
color "e6cca97eb9ca1a15",
[
color
]
] ]
])}> ])}>
<p className={`jsx-${styles.__hash}` + " jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([ <p className={`jsx-${styles.__hash}` + " jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([
"e6cca97eb9ca1a15",
[ [
color "e6cca97eb9ca1a15",
[
color
]
] ]
])}>external, static and dynamic</p> ])}>external, static and dynamic</p>
<_JSXStyle id={"ceba8c9ce34e3d0c"}>{"p.jsx-ceba8c9ce34e3d0c {display:inline-block}"}</_JSXStyle> <_JSXStyle id={"ceba8c9ce34e3d0c"}>{"p.jsx-ceba8c9ce34e3d0c {display:inline-block}"}</_JSXStyle>
...@@ -57,15 +65,19 @@ export const Test5 = ()=><div className={"jsx-df0159ebd3f9fb6f"}> ...@@ -57,15 +65,19 @@ export const Test5 = ()=><div className={"jsx-df0159ebd3f9fb6f"}>
</div> </div>
; ;
export const Test6 = ({ color })=><div className={"jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([ export const Test6 = ({ color })=><div className={"jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([
"a55f0611581d64ca",
[ [
color "a55f0611581d64ca",
[
color
]
] ]
])}> ])}>
<p className={"jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([ <p className={"jsx-ceba8c9ce34e3d0c " + _JSXStyle.dynamic([
"a55f0611581d64ca",
[ [
color "a55f0611581d64ca",
[
color
]
] ]
])}>static and dynamic</p> ])}>static and dynamic</p>
<_JSXStyle id={"ceba8c9ce34e3d0c"}>{"p.jsx-ceba8c9ce34e3d0c {display:inline-block}"}</_JSXStyle> <_JSXStyle id={"ceba8c9ce34e3d0c"}>{"p.jsx-ceba8c9ce34e3d0c {display:inline-block}"}</_JSXStyle>
...@@ -75,15 +87,19 @@ export const Test6 = ({ color })=><div className={"jsx-ceba8c9ce34e3d0c " + _JS ...@@ -75,15 +87,19 @@ export const Test6 = ({ color })=><div className={"jsx-ceba8c9ce34e3d0c " + _JS
</div> </div>
; ;
export const Test7 = ({ color })=><div className={_JSXStyle.dynamic([ export const Test7 = ({ color })=><div className={_JSXStyle.dynamic([
"4adc07771eb3723",
[ [
color "4adc07771eb3723",
[
color
]
] ]
])}> ])}>
<p className={_JSXStyle.dynamic([ <p className={_JSXStyle.dynamic([
"4adc07771eb3723",
[ [
color "4adc07771eb3723",
[
color
]
] ]
])}>dynamic only</p> ])}>dynamic only</p>
<_JSXStyle id={"4adc07771eb3723"} dynamic={[ <_JSXStyle id={"4adc07771eb3723"} dynamic={[
...@@ -97,15 +113,19 @@ export const Test8 = ({ color })=>{ ...@@ -97,15 +113,19 @@ export const Test8 = ({ color })=>{
color color
}; };
return <div className={_JSXStyle.dynamic([ return <div className={_JSXStyle.dynamic([
"a552a4a765a9ca4e",
[ [
innerProps.color "a552a4a765a9ca4e",
[
innerProps.color
]
] ]
])}> ])}>
<p className={_JSXStyle.dynamic([ <p className={_JSXStyle.dynamic([
"a552a4a765a9ca4e",
[ [
innerProps.color "a552a4a765a9ca4e",
[
innerProps.color
]
] ]
])}>dynamic with scoped compound variable</p> ])}>dynamic with scoped compound variable</p>
<_JSXStyle id={"a552a4a765a9ca4e"} dynamic={[ <_JSXStyle id={"a552a4a765a9ca4e"} dynamic={[
...@@ -119,15 +139,19 @@ export const Test9 = ({ color })=>{ ...@@ -119,15 +139,19 @@ export const Test9 = ({ color })=>{
color color
}; };
return <div className={_JSXStyle.dynamic([ return <div className={_JSXStyle.dynamic([
"7ef39e3312c80ead",
[ [
innerProps.color "7ef39e3312c80ead",
[
innerProps.color
]
] ]
])}> ])}>
<p className={_JSXStyle.dynamic([ <p className={_JSXStyle.dynamic([
"7ef39e3312c80ead",
[ [
innerProps.color "7ef39e3312c80ead",
[
innerProps.color
]
] ]
])}>dynamic with compound variable</p> ])}>dynamic with compound variable</p>
<_JSXStyle id={"7ef39e3312c80ead"} dynamic={[ <_JSXStyle id={"7ef39e3312c80ead"} dynamic={[
...@@ -145,9 +169,11 @@ export const Test11 = ({ color })=>{ ...@@ -145,9 +169,11 @@ export const Test11 = ({ color })=>{
const items = Array.from({ const items = Array.from({
length: 5 length: 5
}).map((item, i)=><li key={i} className={_JSXStyle.dynamic([ }).map((item, i)=><li key={i} className={_JSXStyle.dynamic([
"ebe03db0369a2939",
[ [
color "ebe03db0369a2939",
[
color
]
] ]
]) + " " + "item"}> ]) + " " + "item"}>
<_JSXStyle id={"ebe03db0369a2939"} dynamic={[ <_JSXStyle id={"ebe03db0369a2939"} dynamic={[
......
...@@ -10,35 +10,43 @@ const obj = { ...@@ -10,35 +10,43 @@ const obj = {
display: "block" display: "block"
}; };
export default (({ display })=><div className={"jsx-802e359ee0ab20c4 " + _JSXStyle.dynamic([ export default (({ display })=><div className={"jsx-802e359ee0ab20c4 " + _JSXStyle.dynamic([
"76aa3eae4e21e4ca",
[ [
display ? "block" : "none" "76aa3eae4e21e4ca",
] [
], [ display ? "block" : "none"
"5ba905f763f40220", ]
],
[ [
darken(color) + 2 "5ba905f763f40220",
] [
], [ darken(color) + 2
"c4bb394aae9bd00b", ]
],
[ [
darken(color) "c4bb394aae9bd00b",
[
darken(color)
]
] ]
])}> ])}>
<p className={"jsx-802e359ee0ab20c4 " + _JSXStyle.dynamic([ <p className={"jsx-802e359ee0ab20c4 " + _JSXStyle.dynamic([
"76aa3eae4e21e4ca",
[ [
display ? "block" : "none" "76aa3eae4e21e4ca",
] [
], [ display ? "block" : "none"
"5ba905f763f40220", ]
],
[ [
darken(color) + 2 "5ba905f763f40220",
] [
], [ darken(color) + 2
"c4bb394aae9bd00b", ]
],
[ [
darken(color) "c4bb394aae9bd00b",
[
darken(color)
]
] ]
])}>test</p> ])}>test</p>
<_JSXStyle id={"f3d3af42197b4734"}>{`p.${color}.jsx-802e359ee0ab20c4 {color:${otherColor}; <_JSXStyle id={"f3d3af42197b4734"}>{`p.${color}.jsx-802e359ee0ab20c4 {color:${otherColor};
......
...@@ -16,9 +16,11 @@ foo.__hash = "e46da79e05d23fff"; ...@@ -16,9 +16,11 @@ foo.__hash = "e46da79e05d23fff";
]}>{`div.__jsx-style-dynamic-selector {color:${colors.green.light}} ]}>{`div.__jsx-style-dynamic-selector {color:${colors.green.light}}
a.__jsx-style-dynamic-selector {color:red}`}</_JSXStyle>, a.__jsx-style-dynamic-selector {color:red}`}</_JSXStyle>,
className: _JSXStyle.dynamic([ className: _JSXStyle.dynamic([
"12e2c41a8d37fe78",
[ [
colors.green.light "12e2c41a8d37fe78",
[
colors.green.light
]
] ]
]) ])
}); });
...@@ -28,9 +30,11 @@ const b = { ...@@ -28,9 +30,11 @@ const b = {
]}>{`div.__jsx-style-dynamic-selector {color:${colors.green.light}} ]}>{`div.__jsx-style-dynamic-selector {color:${colors.green.light}}
a.__jsx-style-dynamic-selector {color:red}`}</_JSXStyle>, a.__jsx-style-dynamic-selector {color:red}`}</_JSXStyle>,
className: _JSXStyle.dynamic([ className: _JSXStyle.dynamic([
"d5617758481f82cd",
[ [
colors.green.light "d5617758481f82cd",
[
colors.green.light
]
] ]
]) ])
}; };
...@@ -41,9 +45,11 @@ const dynamic = (colors)=>{ ...@@ -41,9 +45,11 @@ const dynamic = (colors)=>{
]}>{`div.__jsx-style-dynamic-selector {color:${colors.green.light}} ]}>{`div.__jsx-style-dynamic-selector {color:${colors.green.light}}
a.__jsx-style-dynamic-selector {color:red}`}</_JSXStyle>, a.__jsx-style-dynamic-selector {color:red}`}</_JSXStyle>,
className: _JSXStyle.dynamic([ className: _JSXStyle.dynamic([
"a7ac579c753e9d90",
[ [
colors.green.light "a7ac579c753e9d90",
[
colors.green.light
]
] ]
]) ])
}; };
......
import _JSXStyle from "styled-jsx/style"; import _JSXStyle from "styled-jsx/style";
export default function Home({ fontFamily }) { export default function Home({ fontFamily }) {
return <div className={_JSXStyle.dynamic([ return <div className={_JSXStyle.dynamic([
"2566fdd7bc25c35",
[ [
fontFamily "2566fdd7bc25c35",
[
fontFamily
]
] ]
])}> ])}>
<_JSXStyle id={"2566fdd7bc25c35"} dynamic={[ <_JSXStyle id={"2566fdd7bc25c35"} dynamic={[
......
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