Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle blob urls in image component #27975

Merged
merged 6 commits into from Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/client/image.tsx
Expand Up @@ -343,7 +343,7 @@ export default function Image({

let isLazy =
!priority && (loading === 'lazy' || typeof loading === 'undefined')
if (src.startsWith('data:')) {
if (src.startsWith('data:') || src.startsWith('blob:')) {
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
unoptimized = true
isLazy = false
Expand Down
26 changes: 26 additions & 0 deletions test/integration/image-component/default/pages/blob.js
@@ -0,0 +1,26 @@
import React, { useEffect, useState } from 'react'
import Image from 'next/image'

const Page = () => {
const [src, setSrc] = useState()

useEffect(() => {
fetch('/test.jpg')
.then((res) => {
return res.blob()
})
.then((blob) => {
const url = URL.createObjectURL(blob)
setSrc(url)
})
}, [])

return (
<div>
<p>Blob URL</p>
{src ? <Image id="blob-image" src={src} width="10" height="10" /> : null}
</div>
)
}

export default Page
20 changes: 20 additions & 0 deletions test/integration/image-component/default/test/index.test.js
Expand Up @@ -229,6 +229,26 @@ function runTests(mode) {
}
})

it('should work with image with blob src', async () => {
let browser
try {
browser = await webdriver(appPort, '/blob')

await check(
() => browser.eval(`document.getElementById("blob-image").src`),
/^blob:/
)
await check(
() => browser.eval(`document.getElementById("blob-image").srcset`),
''
)
} finally {
if (browser) {
await browser.close()
}
}
})

it('should work when using flexbox', async () => {
let browser
try {
Expand Down