-
-
Notifications
You must be signed in to change notification settings - Fork 236
chore: adjust align logic #580
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分代码存在两个问题:
高危:UI 闪烁 (Flicker)
此实现在浏览器中会导致 UI 闪烁。当弹窗首次打开时(
open
变为true
),ready
此时为false
。offsetStyle
会返回一个将弹窗移出屏幕的样式。然而,cachedOffsetStyleRef.current
仍然保持着组件首次渲染时的值(通常是{ left: 0, top: 0, ... }
)。这导致弹窗在计算出正确位置之前,会在0,0
位置闪现一帧。中危:在渲染函数中产生副作用
在渲染函数中直接修改 ref (
cachedOffsetStyleRef.current = offsetStyle;
) 是一个副作用。React 的函数组件应该设计为纯函数,在渲染期间执行副作用可能会在未来的 React 版本(特别是并发模式下)导致不可预测的行为。为了解决
jsdom
中对齐无意义的问题,同时避免在浏览器中产生闪烁,需要更精细的逻辑。一个可能的思路是仅在弹窗关闭动画期间使用缓存的样式。例如:然后将
styleToUse
应用到div
上。但这可能会让弹窗在jsdom
环境下不可见,与本次修改的初衷相悖。请重新评估此方案,找到一个能同时满足测试环境和生产环境需求的方案,避免引入UI缺陷。