Skip to content

Commit

Permalink
reorder attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Mar 9, 2021
1 parent 80c9522 commit 8707256
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/next/client/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ function generateImgAttrs({
const last = widths.length - 1

return {
src: loader({ src, quality, width: widths[last] }),
sizes: !sizes && kind === 'w' ? '100vw' : sizes,
srcSet: widths
.map(
Expand All @@ -160,6 +159,14 @@ function generateImgAttrs({
}${kind}`
)
.join(', '),

// It's intended to keep `src` the last attribute because React updates
// attributes in order. If we keep `src` the first one, Safari will
// immediately start to fetch `src`, before `sizes` and `srcSet` are even
// updated by React. That causes multiple unnecessary requests if `srcSet`
// and `sizes` are defined.
// This bug cannot be reproduced in Chrome or Firefox.
src: loader({ src, quality, width: widths[last] }),
}
}

Expand Down

0 comments on commit 8707256

Please sign in to comment.