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: create image using document method to avoid ReferenceError in SSR #6569

Merged
merged 1 commit into from Apr 13, 2021
Merged

Conversation

duongleh
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Application (the showcase website) / infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #6559

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@zorro-bot
Copy link

zorro-bot bot commented Mar 31, 2021

This preview will be available after the AzureCI is passed.

@codecov
Copy link

codecov bot commented Mar 31, 2021

Codecov Report

Merging #6569 (68a6252) into master (bc0e468) will increase coverage by 0.03%.
The diff coverage is 88.46%.

❗ Current head 68a6252 differs from pull request most recent head 107f0d3. Consider uploading reports for the commit 107f0d3 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6569      +/-   ##
==========================================
+ Coverage   89.88%   89.92%   +0.03%     
==========================================
  Files         481      481              
  Lines       15374    15381       +7     
  Branches     2343     2344       +1     
==========================================
+ Hits        13819    13831      +12     
+ Misses        937      929       -8     
- Partials      618      621       +3     
Impacted Files Coverage Δ
components/select/select.component.ts 87.09% <66.66%> (ø)
components/tree-select/tree-select.component.ts 88.84% <80.00%> (-0.05%) ⬇️
components/date-picker/date-picker.component.ts 93.50% <100.00%> (+0.04%) ⬆️
components/date-picker/picker.component.ts 89.94% <100.00%> (ø)
components/drawer/drawer.component.ts 97.08% <100.00%> (-0.92%) ⬇️
components/image/image.directive.ts 89.39% <100.00%> (+0.16%) ⬆️
components/select/option-group.component.ts 100.00% <100.00%> (ø)
components/select/option-item-group.component.ts 100.00% <100.00%> (ø)
components/select/option-item.component.ts 93.10% <100.00%> (ø)
components/select/option.component.ts 100.00% <100.00%> (ø)
... and 13 more

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 bc0e468...107f0d3. Read the comment docs.

vthinkxie
vthinkxie previously approved these changes Apr 3, 2021
Copy link
Member

@vthinkxie vthinkxie left a comment

Choose a reason for hiding this comment

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

@duongleh
Copy link
Contributor Author

duongleh commented Apr 9, 2021

@hsuanxyz Can you help me with the unit test?

@hsuanxyz
Copy link
Member

hsuanxyz commented Apr 9, 2021

@duong-le I have not found an alternative to the current change, until #1836 · jasmine/jasmine is processed.

so I suggest skipping the previewImage method on the server side (like https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/components/upload/upload-list.component.ts#L171).

@duongleh
Copy link
Contributor Author

duongleh commented Apr 9, 2021

@hsuanxyz I skipped the previewImage method as below but the test case still failed. Do you think I should skip the test case?
image

@hsuanxyz
Copy link
Member

@duong-le try this.

private previewImage(file: File | Blob): Promise<string> {
+  if (!this.platform.isBrowser) {
+   return Promise.resolve('');
+  }
return new Promise(resolve => {
 ...
  this.ngZone.runOutsideAngular(() => {
     ...
+    const img = new Image();
-    const img = this.doc.createElement('img'); 
     ...
  });
 ...
});
}

@duongleh
Copy link
Contributor Author

@hsuanxyz All test cases are now passed, please review once again. Thank you very much.

@duongleh duongleh requested a review from vthinkxie April 12, 2021 17:08
Copy link
Member

@hsuanxyz hsuanxyz left a comment

Choose a reason for hiding this comment

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

LGTM

@hsuanxyz hsuanxyz merged commit d7b9291 into NG-ZORRO:master Apr 13, 2021
@duongleh
Copy link
Contributor Author

@hsuanxyz please release this fix as a minor version. I really need this fix in my app in production.

@hsuanxyz
Copy link
Member

@duong-le https://github.com/NG-ZORRO/ng-zorro-antd-builds/releases/tag/11.4.0%2Bd7b9291dfd
you can use build version.

package.json

  "dependencies": {
+   "ng-zorro-antd": "github:NG-ZORRO/ng-zorro-antd-builds#011764a7b2187fcf9eb05a22a44cf11e7f41b62d"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants