Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛[BUG] demo内初次渲染时获取html元素宽高为0 #76

Open
mengxinssfd opened this issue Jul 1, 2023 · 0 comments
Open

🐛[BUG] demo内初次渲染时获取html元素宽高为0 #76

mengxinssfd opened this issue Jul 1, 2023 · 0 comments

Comments

@mengxinssfd
Copy link
Contributor

🐛 bug 描述

demo内初次渲染时获取html元素宽高为0

📷 复现步骤

dumi使用该主题,然后添加demo代码,并在初次渲染时获取html元素Rect,获取的都是无效Rect,目前需要延时才能正常获取。

在移除该主题后是正常的。

🏞 期望结果

初次渲染时获取html元素正常的Rect。

💻 复现代码

dumi demo 代码

import React, { useEffect, useRef } from 'react';

const App: React.FC = () => {
  const ref = useRef<HTMLDivElement>(null);
  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    // 使用dumi-theme-antd-style主题时获取的都是0,去掉主题后是正常的
    console.log(el.getBoundingClientRect());
    // 延时获取的是正常的
    setTimeout(() => console.log(el.getBoundingClientRect()), 1000);
  }, []);
  return <div ref={ref}>test</div>;
};

export default App;

© 版本信息

  • dumi-theme-antd-style 版本: [e.g. 1.0.0]
  • 浏览器环境
  • 开发环境 [e.g. mac OS]

🚑 其他信息

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant