You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React.StrictMode结合createRoot导致GSAP动画异常,求原因解析

CreateRoot结合React.StrictMode时GSAP动画引发页面顶部空白的问题

我是React新手,项目由create-react-app生成,入口代码如下:

const container = document.getElementById("root");
const root = createRoot(container);
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

使用GSAP实现动画时,页面顶部出现讨厌的空白块,排查发现是上述代码导致。我测试了三种情况:

  • 使用ReactDOM.render结合<React.StrictMode>时正常;
  • 使用createRoot.render直接渲染<App />时正常;
  • 使用createRoot.render结合<React.StrictMode>时异常。

补充说明:原本用Context解决了问题,但添加另一个用于动画的<div id='img2'>后问题复现,希望有人解释这些差异的原因。

内容的提问来源于stack exchange,提问作者Trouble Lee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 00:12:37