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

fix: destroyOnClose fails with forceRender #232

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

HelloAny
Copy link

ant-design/ant-design#28847

解决destroyOnCloseforceRender都设置为truedestroyOnClose失效

原因:当forceRender设置为true时,判断是否删除子节点的语句失效

方案:为forceRender增加一层缓存,当第一次打开Modal时设置forceRenderfalse

此外,感觉antd文档里关于forceRender部分的描述不是很清晰,个人理解为首次未打开Modal可获取其中的dom
image

觉得可以和dialog的文档稍作同步

@vercel
Copy link

vercel bot commented Jan 15, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/react-component/dialog/ookx04a0g
✅ Preview: https://dialog-git-fork-helloany-fix-destroyonclose.react-component.vercel.app

@codecov
Copy link

codecov bot commented Jan 15, 2021

Codecov Report

Merging #232 (8f7c630) into master (586bfcb) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #232      +/-   ##
==========================================
+ Coverage   98.10%   98.17%   +0.06%     
==========================================
  Files           6        6              
  Lines         158      164       +6     
  Branches       46       47       +1     
==========================================
+ Hits          155      161       +6     
  Misses          2        2              
  Partials        1        1              
Impacted Files Coverage Δ
src/DialogWrap.tsx 95.45% <100.00%> (+1.33%) ⬆️
src/Dialog/Content/index.tsx 95.23% <0.00%> (-0.12%) ⬇️
src/Dialog/index.tsx 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 586bfcb...8f7c630. Read the comment docs.

@@ -14,14 +14,22 @@ import { IDialogPropTypes } from './IDialogPropTypes';

const DialogWrap: React.FC<IDialogPropTypes> = (props: IDialogPropTypes) => {
const { visible, getContainer, forceRender, destroyOnClose = false, afterClose } = props;
const [forceRenderTime, setForceRenderTime] = React.useState<boolean>(forceRender);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forceRenderTime 是啥含义?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该是forceRender的映射,后续进行状态管理

@@ -33,15 +41,16 @@ const DialogWrap: React.FC<IDialogPropTypes> = (props: IDialogPropTypes) => {
}

// Destroy on close will remove wrapped div
if (!forceRender && destroyOnClose && !animatedVisible) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是直接把 !forceRender 去掉就行了?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接去掉会导致forceRender这个属性失效😅

@yoyo837
Copy link
Member

yoyo837 commented Jun 7, 2021

3.x 也有这个问题。😳

@afc163
Copy link
Member

afc163 commented Oct 29, 2022

冲突了

@afc163
Copy link
Member

afc163 commented Nov 6, 2022

ping @HelloAny

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

Successfully merging this pull request may close these issues.

None yet

4 participants