Skip to content

Commit

Permalink
fix: filter out empty srcset, fix #2863 (#2888)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Apr 16, 2021
1 parent e472d29 commit 0d4f803
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function htmlInlineScriptProxyPlugin(): Plugin {
export const assetAttrsConfig: Record<string, string[]> = {
link: ['href'],
video: ['src', 'poster'],
source: ['src'],
source: ['src', 'srcset'],
img: ['src', 'srcset'],
image: ['xlink:href', 'href'],
use: ['xlink:href', 'href']
Expand Down
17 changes: 10 additions & 7 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,16 @@ export async function processSrcSet(
srcs: string,
replacer: (arg: ImageCandidate) => Promise<string>
): Promise<string> {
const imageCandidates: ImageCandidate[] = srcs.split(',').map((s) => {
const [url, descriptor] = s
.replace(escapedSpaceCharacters, ' ')
.trim()
.split(' ', 2)
return { url, descriptor }
})
const imageCandidates: ImageCandidate[] = srcs
.split(',')
.map((s) => {
const [url, descriptor] = s
.replace(escapedSpaceCharacters, ' ')
.trim()
.split(' ', 2)
return { url, descriptor }
})
.filter(({ url }) => !!url)

const ret = await Promise.all(
imageCandidates.map(async ({ url, descriptor }) => {
Expand Down

0 comments on commit 0d4f803

Please sign in to comment.