Skip to content

Commit

Permalink
encodeURI for all srcsets
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master committed Aug 13, 2024
1 parent 9d8b537 commit 9410ba2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/theme/NativeIdealImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function NativeIdealImage(props: NativeIdealImageProps): JSX.Elem
const sources = enabled ? data.formats.slice(0, data.formats.length - 1) : undefined
const lastFormat = enabled ? data.formats[data.formats.length - 1]! : undefined

const sizesAttr = sizes ?? 'auto'
const sizesAttr = sizes ?? enabled ? 'auto' : undefined
const isSingleImage = formats[0]?.srcSet.length === 1
const largestImage = formats[0]?.srcSet[formats[0]?.srcSet.length - 1]

Expand Down Expand Up @@ -50,7 +50,7 @@ export default function NativeIdealImage(props: NativeIdealImageProps): JSX.Elem
<source
srcSet={
isSingleImage
? format.srcSet[0]!.path
? encodeURI(format.srcSet[0]!.path)
: format.srcSet.map((image) => `${encodeURI(image.path)} ${image.width}w`).join(',')
}
type={format.mime}
Expand All @@ -63,7 +63,9 @@ export default function NativeIdealImage(props: NativeIdealImageProps): JSX.Elem
srcSet={
srcSet ?? enabled
? !isSingleImage
? lastFormat!.srcSet.map((image) => `${image.path} ${image.width}w`).join(',')
? lastFormat!.srcSet
.map((image) => `${encodeURI(image.path)} ${image.width}w`)
.join(',')
: undefined
: undefined
}
Expand Down

0 comments on commit 9410ba2

Please sign in to comment.