File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1158,6 +1158,17 @@ describe('Upload List', () => {
11581158 unmount ( ) ;
11591159 } ) ;
11601160
1161+ it ( 'should not leave a canvas after generating a GIF preview' , async ( ) => {
1162+ const mockFile = new File ( [ '' ] , 'foo.gif' , {
1163+ type : 'image/gif' ,
1164+ } ) ;
1165+ const canvasCount = document . body . querySelectorAll ( 'canvas' ) . length ;
1166+
1167+ await previewImage ( mockFile ) ;
1168+
1169+ expect ( document . body . querySelectorAll ( 'canvas' ) ) . toHaveLength ( canvasCount ) ;
1170+ } ) ;
1171+
11611172 it ( "upload non image file shouldn't be converted to the base64" , async ( ) => {
11621173 const mockFile = new File ( [ '' ] , 'foo.7z' , {
11631174 type : 'application/x-7z-compressed' ,
Original file line number Diff line number Diff line change @@ -96,6 +96,18 @@ export function previewImage(file: File | Blob): Promise<string> {
9696 resolve ( '' ) ;
9797 return ;
9898 }
99+
100+ if ( file . type . startsWith ( 'image/gif' ) ) {
101+ const reader = new FileReader ( ) ;
102+ reader . onload = ( ) => {
103+ if ( reader . result ) {
104+ resolve ( reader . result as string ) ;
105+ }
106+ } ;
107+ reader . readAsDataURL ( file ) ;
108+ return ;
109+ }
110+
99111 const canvas = document . createElement ( 'canvas' ) ;
100112 canvas . width = MEASURE_SIZE ;
101113 canvas . height = MEASURE_SIZE ;
@@ -134,14 +146,6 @@ export function previewImage(file: File | Blob): Promise<string> {
134146 }
135147 } ;
136148 reader . readAsDataURL ( file ) ;
137- } else if ( file . type . startsWith ( 'image/gif' ) ) {
138- const reader = new FileReader ( ) ;
139- reader . onload = ( ) => {
140- if ( reader . result ) {
141- resolve ( reader . result as string ) ;
142- }
143- } ;
144- reader . readAsDataURL ( file ) ;
145149 } else {
146150 img . src = window . URL . createObjectURL ( file ) ;
147151 }
You can’t perform that action at this time.
0 commit comments