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
Watermark container size changes, resulting in incomplete display or disappearance of watermarks #48660
Open
765477020
wants to merge
8
commits into
ant-design:master
Choose a base branch
from
765477020:master
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Watermark container size changes, resulting in incomplete display or disappearance of watermarks #48660
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3e4d50b
fix:The watermark display is incomplete or disappears
f1dd642
Merge branch 'master' into master
765477020 a06d047
Merge branch 'ant-design:master' into master
765477020 74f611b
fix:The watermark display is incomplete or disappears
b642fd4
Merge branch 'master' of https://github.com/765477020/ant-design
59b0665
Merge branch 'ant-design:master' into master
765477020 d65582f
fix:The watermark display is incomplete or disappears
afc9818
Merge branch 'master' into master
765477020 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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.
感觉搞复杂了,如果只是需要更新视图的话,直接用
forceUpdate
就可以了吧: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.
用时间戳做
key
的初始值感觉不是很好的解法,初始值还不如直接写 0 好了,另外new Date().getTime()
可以简写为Date.now()
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.
我曾经尝试过使用useForceUpdate(useReducer)方法来触发视图更新,但是没有解决这个问题
但是我采用了您
key
初始值为0的建议**解决思路:**父元素旧的dom替换成新的dom,如果不换成新的dom浏览器控制台设置的属性将不会消失(如果您有更好的解决思路可以提出)
**解决方案:**将父元素div的key进行更新,react的diff算法检测到前后key不一致,会调用ReactElement方法来生成新的fiberNode,最终产生一个新的真实dom
为什么useReducer方法无法解决这个问题
useReducer只是触发视图的更新,父元素的key或type没有发生改变,react会复用这个老的真实dom,导致浏览器控制台设置的CSS属性依旧存在