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] useEffect 中执行函数存在时序问题 #2108

Open
zivyangll opened this issue Apr 6, 2021 · 5 comments · May be fixed by raxjs/babel-plugin-minify-dead-code-elimination-while-loop-fixed#1
Assignees
Labels

Comments

@zivyangll
Copy link

下面代码会 return 后会执行 alert(1)。

  useEffect(() => {
    if (1) return;
    const timer = setInterval(() => {
      alert(1)
      clearInterval(timer);
    }, 1000);
  }, [])
  • Device: MacBook Pro
  • OS: MacOS
  • Browser: Chrome
  • Rax Version: ^1.1.0
@zivyangll zivyangll added the Bug label Apr 6, 2021
@SoloJiang SoloJiang self-assigned this Apr 12, 2021
@fengzilong
Copy link
Contributor

fengzilong commented Oct 13, 2021

https://github.com/raxjs/rax-app/blob/3eebae97cc680f64485e88c9d2565a37aebe013b/packages/rax-babel-config/src/index.js#L65

直接原因是 babel-plugin-minify-dead-code-elimination-while-loop-fixed 这个 babel 插件引起的,if (1) return; 被移除掉了,但是后面的 const timer = ... 没有移除

复现地址:Babel REPL

babel issue 地址:babel/minify#1020

@fengzilong
Copy link
Contributor

@SoloJiang
Copy link
Collaborator

这个 babel 插件未来应该可以干掉了

@SoloJiang
Copy link
Collaborator

这个 pr 提到 raxjs 下对应的仓库吧

@fengzilong
Copy link
Contributor

fengzilong commented May 15, 2022

这个 pr 提到 raxjs 下对应的仓库吧

raxjs/babel-plugin-minify-dead-code-elimination-while-loop-fixed#1
done~

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