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: Lodash can clone FileProxy #29718

Merged
merged 7 commits into from
Mar 11, 2021
Merged

fix: Lodash can clone FileProxy #29718

merged 7 commits into from
Mar 11, 2021

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Mar 11, 2021

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

resolve #29646

💡 Background and solution

📝 Changelog

Language Changelog
🇺🇸 English Fix Upload onChange params file can not cloneDeep by lodash.
🇨🇳 Chinese 修复 Upload onChange 参数 file 不能被 lodash cloneDeep 的问题。

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2021

@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2021

Size Change: +787 B (0%)

Total Size: 838 kB

Filename Size Change
./dist/antd-with-locales.min.js 338 kB +403 B (0%)
./dist/antd.min.js 297 kB +384 B (0%)
ℹ️ View Unchanged
Filename Size Change
./dist/antd.compact.min.css 67.2 kB 0 B
./dist/antd.dark.min.css 68.5 kB 0 B
./dist/antd.min.css 67.2 kB 0 B

compressed-size-action

@zombieJ
Copy link
Member Author

zombieJ commented Mar 11, 2021

蛋疼,还有这么一个 issue 需要是 File:
#10293

死循环了,如果是 File cloneDeep 返回的其实是个空对象。如果要填充成 object,那么 beforeUpload 这个是 File 的坑就填不了。蛋疼

@GannonSun
Copy link
Contributor

蛋疼,还有这么一个 issue 需要是 File:
#10293

死循环了,如果是 File cloneDeep 返回的其实是个空对象。如果要填充成 object,那么 beforeUpload 这个是 File 的坑就填不了。蛋疼

所以说现在只有onchange里返回的file和fileList是proxy对象吗??beforeupload还是file对象?确定了吗?我这次从4.5.0升上来遇到了原先onchange事件里file对象用不了的情况了

@zombieJ
Copy link
Member Author

zombieJ commented Mar 11, 2021

你说的 file 对象用不了是什么问题?

@codecov
Copy link

codecov bot commented Mar 11, 2021

Codecov Report

Merging #29718 (eb2709b) into master (52152ed) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master    #29718   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          394       394           
  Lines         7522      7533   +11     
  Branches      2114      2115    +1     
=========================================
+ Hits          7522      7533   +11     
Impacted Files Coverage Δ
components/upload/utils.tsx 100.00% <100.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 52152ed...eb2709b. Read the comment docs.

@zombieJ zombieJ requested a review from afc163 March 11, 2021 09:22
@GannonSun
Copy link
Contributor

你说的 file 对象用不了是什么问题?

https://codesandbox.io/s/dianjishangchuan-antd4131-forked-d7yzt?fontsize=14&hidenavigation=1&theme=dark

这是最新版的,如果我需要用到FileReader.readAsDataURL(),我必须从info.file中先取到originFileObj属性中的File对象才能传入。
我之前项目的antd版本是4.5.2,可以直接将info.file传入,升级之后info.file变成了proxy对象,会报错。
image
上图是旧版本中的图,如图所示,info.file为File对象,升级之后不兼容了

@zombieJ
Copy link
Member Author

zombieJ commented Mar 11, 2021

你的 codesandbox 里 4.5.0 去掉 originFileObj 直接用 info.file 看起来也报错呀?

@zombieJ zombieJ merged commit a4a009c into master Mar 11, 2021
@zombieJ zombieJ deleted the fix-upload branch March 11, 2021 11:29
@GannonSun
Copy link
Contributor

你的 codesandbox 里 4.5.0 去掉 originFileObj 直接用 info.file 看起来也报错呀?

我不知道为什么在codesandbox里切换成4.5.0版本取到的info.file是一个object对象,但是我本地项目里的确是一个File对象,这个我们整个项目的人都验证过了,一直都是这样用的,这次升级导致上传文件的代码都挂了

@zombieJ
Copy link
Member Author

zombieJ commented Mar 11, 2021

是不是有 beforeUpload 返回 false 的?

@GannonSun
Copy link
Contributor

是不是有 beforeUpload 返回 false 的?

是的,我们beforeUpload都是直接return false,这有什么影响吗?

@zombieJ
Copy link
Member Author

zombieJ commented Mar 11, 2021

哎,历史债务。beforeUploadfalse 的时候会额外触发一次 onChange 这个时候返回的是一个真的 File 对象,而不是包裹的对象。

@zombieJ
Copy link
Member Author

zombieJ commented Mar 11, 2021

Chrome 里 FileReader 不支持读取 Proxy(File) 感觉走进了死胡同。要不然搞全模拟成老的行为,Proxy 方案看起来也不太可行。

cc @afc163

@GannonSun
Copy link
Contributor

哎,历史债务。beforeUploadfalse 的时候会额外触发一次 onChange 这个时候返回的是一个真的 File 对象,而不是包裹的对象。

那请问有好的解决方法吗?...

@zombieJ
Copy link
Member Author

zombieJ commented Mar 11, 2021

见上,和 @afc163 讨论一下

@afc163
Copy link
Member

afc163 commented Mar 11, 2021

beforeUpload 为 false 的时候会额外触发一次 onChange 这个时候返回的是一个真的 File 对象,而不是包裹的对象。

这个不一致是不是也被提过 bug。

@afc163
Copy link
Member

afc163 commented Mar 11, 2021

  1. 修 bug 会 break change.
  2. 不修 bug 就一直在。

看上去只能先保留 bug 作为 feature,留 5.0 去处理了。

@GannonSun
Copy link
Contributor

  1. 修 bug 会 break change.
  2. 不修 bug 就一直在。

看上去只能先保留 bug 作为 feature,留 5.0 去处理了。

emmmm那想问一下4.x后续的版本还会是用proxy对象吗?还是说会改为原先的模式?

@zombieJ
Copy link
Member Author

zombieJ commented Mar 11, 2021

改成原先的模式,我会兼容一下给 File 添加一个 originFileObj,这样让新用户都用 originFileObj 处理对象,方便 v5 迁移。

@GannonSun
Copy link
Contributor

改成原先的模式,我会兼容一下给 File 添加一个 originFileObj,这样让新用户都用 originFileObj 处理对象,方便 v5 迁移。

image
image
那还想问问,老版本的话应该怎么办?File中没有originFileObj ,我现在有点纠结不懂应该升级到proxy版本还是保持旧版本,如果保持旧版本,以后升级了还是要改代码添加originFileObj 。如果升级了就要面对proxy对象带来的不确定因素

This was referenced Mar 15, 2021
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.

upload 初始化设置的filelist 在onChange中的filelist的数据格式不统一
4 participants