Skip to content

Commit 136034b

Browse files
authored
feat: add whitelist of image extenstions which can be compressed (#215)
1 parent 715ff55 commit 136034b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/components/Image/Image.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {CSSProperties, MouseEventHandler, useContext, useState, Fragment}
22
import {ProjectSettingsContext} from '../../context/projectSettingsContext';
33
import {BREAKPOINTS} from '../../constants';
44
import {ImageDeviceProps, ImageObjectProps} from '../../models';
5+
import {isCompressible} from '../../utils/imageCompress';
56

67
export interface ImageProps extends Partial<ImageObjectProps>, Partial<ImageDeviceProps> {
78
style?: CSSProperties;
@@ -36,11 +37,10 @@ const Image = (props: ImageProps) => {
3637
return null;
3738
}
3839

39-
// TODO: Temporary solution for .svg images
4040
const disableWebp =
4141
projectSettings.disableCompress ||
4242
disableCompress ||
43-
imageSrc.endsWith('.svg') ||
43+
!isCompressible(imageSrc) ||
4444
imgLoadingError;
4545

4646
return (

src/utils/imageCompress.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export enum AvailableForCompressExtension {
2+
PNG = 'png',
3+
JPG = 'jpg',
4+
JPEG = 'jpeg',
5+
}
6+
7+
export const isCompressible = (fileName: string) =>
8+
Object.keys(AvailableForCompressExtension).some((ext) => fileName.endsWith(`.${ext}`));

0 commit comments

Comments
 (0)