fix(frontend): fix no data on second click#1379
fix(frontend): fix no data on second click#1379hbz114514 wants to merge 1 commit intoUNIkeEN:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where clicking to change the mod loader a second time would display "no data" or a white screen in the modal. The fix wraps the ChangeModLoaderModal component with conditional rendering based on isChangeModLoaderModalOpen, forcing the component to unmount and remount each time the modal is opened. This ensures that stale state from previous modal sessions is cleared.
Changes:
- Conditional rendering added to ChangeModLoaderModal to force component remount on each open
| {isChangeModLoaderModalOpen && ( | ||
| <ChangeModLoaderModal | ||
| isOpen={isChangeModLoaderModalOpen} | ||
| onClose={onChangeModLoaderModalClose} | ||
| defaultSelectedType={targetLoaderType} | ||
| /> | ||
| )} |
There was a problem hiding this comment.
While conditional rendering fixes the "no data" issue by forcing component remount, this is a workaround rather than addressing the root cause. The proper fix would be to update the useEffect in ChangeModLoaderModal (line 56-65 of src/components/modals/change-mod-loader-modal.tsx) to include modalProps.isOpen in its dependency array, similar to how AddPlayerModal handles state reset. This would reset the modal state when it opens without the overhead of unmounting/remounting the entire component.
Example from AddPlayerModal:
useEffect(() => {
setPlayername("");
setPassword("");
// ... reset other state
}, [modalProps.isOpen]);
The current conditional rendering approach works but has trade-offs: it causes the component to be completely recreated on each open, which may have minor performance implications.
| {isChangeModLoaderModalOpen && ( | |
| <ChangeModLoaderModal | |
| isOpen={isChangeModLoaderModalOpen} | |
| onClose={onChangeModLoaderModalClose} | |
| defaultSelectedType={targetLoaderType} | |
| /> | |
| )} | |
| <ChangeModLoaderModal | |
| isOpen={isChangeModLoaderModalOpen} | |
| onClose={onChangeModLoaderModalClose} | |
| defaultSelectedType={targetLoaderType} | |
| /> |
Checklist
This PR is a ..
Related Issues
fix #1285
Description
修改了从实例的模组页面修改modloader时,第二次点击显示“无数据”的问题
Additional Context