forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix html validation for Image component (vercel#18903)
This PR fixes two bugs causing HTML validators to complain. - Error: Bad value data:image/svg+xml;charset=utf-8, for attribute src on element img: Illegal character in scheme data: < is not allowed. - Fixed by using base64 for svg during `layout=intrinsic` to avoid angle brackets - Error: Element img is missing required attribute src. - Fixed by using base64 transparent gif for `loading=lazy` placeholder Fixes vercel#18850
- Loading branch information
Showing
3 changed files
with
27 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Isomorphic base64 that works on the server and client | ||
*/ | ||
export function toBase64(str: string) { | ||
if (typeof window === 'undefined') { | ||
return Buffer.from(str).toString('base64') | ||
} else { | ||
return window.btoa(str) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters