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: Not try to modify lock file #29944

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
const timestamp = Date.now();

(fileList || []).forEach((file, index) => {
if (!file.uid) {
if (!file.uid && !Object.isFrozen(file)) {
file.uid = `__AUTO__${timestamp}_${index}__`;
Copy link
Contributor

@yoyo837 yoyo837 Mar 30, 2021

Choose a reason for hiding this comment

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

是不是加个warning好一些?提示尝试初始化uid失败,因为啥啥啥的。

}
});
Expand Down Expand Up @@ -254,7 +254,7 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
currentFile = { ...file, status: 'removed' };
mergedFileList?.forEach(item => {
const matchKey = currentFile.uid !== undefined ? 'uid' : 'name';
if (item[matchKey] === currentFile[matchKey]) {
if (item[matchKey] === currentFile[matchKey] && !Object.isFrozen(item)) {
item.status = 'removed';
}
});
Expand Down
23 changes: 23 additions & 0 deletions components/upload/__tests__/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,4 +799,27 @@ describe('Upload', () => {
expect(key in clone).toBeTruthy();
});
});

it('not break on freeze object', async () => {
const fileList = [
{
fileName: 'Test.png',
name: 'SupportIS App - potwierdzenie.png',
thumbUrl: null,
downloadUrl: 'https://localhost:5001/api/files/ff2917ce-e4b9-4542-84da-31cdbe7c273f',
status: 'done',
},
];

const frozenFileList = fileList.map(file => Object.freeze(file));

const wrapper = mount(<Upload fileList={frozenFileList} />);
const rmBtn = wrapper.find('.ant-upload-list-item-card-actions-btn').last();
rmBtn.simulate('click');

// Wait for Upload async remove
await act(async () => {
await sleep();
});
});
});