Skip to content

fix: destroyOnClose fails with forceRender - #232

Open
HelloAny wants to merge 2 commits into
react-component:masterfrom
HelloAny:fix-destroyOnClose
Open

fix: destroyOnClose fails with forceRender#232
HelloAny wants to merge 2 commits into
react-component:masterfrom
HelloAny:fix-destroyOnClose

Conversation

@HelloAny

Copy link
Copy Markdown

ant-design/ant-design#28847

解决destroyOnCloseforceRender都设置为truedestroyOnClose失效

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

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

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

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

@vercel

vercelBot commented Jan 15, 2021

Copy link
Copy Markdown

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

codecovBot commented Jan 15, 2021

Copy link
Copy Markdown

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 FilesCoverage Δ
src/DialogWrap.tsx95.45% <100.00%> (+1.33%)⬆️
src/Dialog/Content/index.tsx95.23% <0.00%> (-0.12%)⬇️
src/Dialog/index.tsx100.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.

Comment threadsrc/DialogWrap.tsx

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

forceRenderTime 是啥含义?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

Comment threadsrc/DialogWrap.tsx
}

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
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
Copy Markdown
Member

3.x 也有这个问题。😳

@afc163

Copy link
Copy Markdown
Member

冲突了

@afc163

Copy link
Copy Markdown
Member

ping @HelloAny

Sign up for freeto 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.

4 participants

@HelloAny@yoyo837@afc163@zombieJ