Css attribute "will-change" make animation performance better. But seem like it'll disable some render in IOS mobile browser under special condition.
The behavior of following code in IOS mobile browser:
- Click "click me", add count to
length
; - Render Component with new
length
; - "value" show wrong
length
, "same value" show rightlength
.
The difference between "value" and "same value" is css code, i think maybe "will-change" trigger IOS mobile browser optimize render html. The correct length
in "value" has been optimized.
So please someone explain this strange issue. Thanks.
import { useState } from "react";
import "./styles.css";
export default function App() {
const [length, setLength] = useState(0);
const onClick = () => setLength(length + 1);
const list = Array.from({ length }).fill("");
const items = list.map(() => {
return <div className="item">placeholder</div>;
});
return (
<div className="container">
{ /* has css "will-change" */ }
<div className="create" onClick={onClick}>
Click me
</div>
{items}
{ /* has css "position: relative", "box-shadow" */ }
<div className="length"> value: {length}</div>
<div> same value: {length} </div>
</div>
);
}
.length {
position: relative;
box-shadow: 0 0 5px red;
}
.create {
will-change: transform;
}
.container {
font-size: 28px;
}
Bug Demo, open with iphone browser