Skip to content

Commit

Permalink
fix: Not try to modify lock file (ant-design#29944)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ authored and gepd committed Apr 1, 2021
1 parent 251c527 commit d7ff9e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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}__`;
}
});
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();
});
});
});

0 comments on commit d7ff9e9

Please sign in to comment.