Unverified Commit cdb0c474 authored by Steven's avatar Steven Committed by GitHub

Improve `next/image` error message when `src` prop is missing (#38847)

Currently, when a user forgets the `src` prop on an image, an error is thrown. However that error doesn't include any of the the user's code in the stack trace, so its nearly impossible to figure out which image is the culprit if there are multiple images on the page.

Since this error only throws on demand when a page is visited during `next dev`, we can instead delay the error so it no longer prints on the server but prints on mount instead. At that point, we'll have the `<img>` element via ref and can print it to the web console with the stack trace.

- Fixes #23742 
parent 672bdaee
This diff is collapsed.
This diff is collapsed.
......@@ -386,10 +386,13 @@ function runTests(mode) {
it('should show missing src error', async () => {
const browser = await webdriver(appPort, '/docs/missing-src')
expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toContain(
'Image is missing required "src" property. Make sure you pass "src" in props to the `next/image` component. Received: {"width":200}'
)
expect(await hasRedbox(browser)).toBe(false)
await check(async () => {
return (await browser.log('browser'))
.map((log) => log.message)
.join('\n')
}, /Image is missing required "src" property/gm)
})
it('should show invalid src error', async () => {
......
......@@ -746,10 +746,13 @@ function runTests(mode) {
it('should show missing src error', async () => {
const browser = await webdriver(appPort, '/missing-src')
expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toContain(
'Image is missing required "src" property. Make sure you pass "src" in props to the `next/image` component. Received: {"width":200}'
)
expect(await hasRedbox(browser)).toBe(false)
await check(async () => {
return (await browser.log('browser'))
.map((log) => log.message)
.join('\n')
}, /Image is missing required "src" property/gm)
})
it('should show invalid src error', async () => {
......
......@@ -130,10 +130,13 @@ function runTests(mode) {
it('should show missing src error', async () => {
const browser = await webdriver(appPort, '/docs/missing-src')
expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toContain(
'Image is missing required "src" property. Make sure you pass "src" in props to the `next/image` component. Received: {"width":200}'
)
expect(await hasRedbox(browser)).toBe(false)
await check(async () => {
return (await browser.log('browser'))
.map((log) => log.message)
.join('\n')
}, /Image is missing required "src" property/gm)
})
it('should show invalid src error', async () => {
......
......@@ -605,10 +605,13 @@ function runTests(mode) {
it('should show missing src error', async () => {
const browser = await webdriver(appPort, '/missing-src')
expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toContain(
'Image is missing required "src" property. Make sure you pass "src" in props to the `next/image` component. Received: {"width":200}'
)
expect(await hasRedbox(browser)).toBe(false)
await check(async () => {
return (await browser.log('browser'))
.map((log) => log.message)
.join('\n')
}, /Image is missing required "src" property/gm)
})
it('should show invalid src error', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment