-
Notifications
You must be signed in to change notification settings - Fork 27k
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
fix(next/image): render valid html according to W3C #33825
Changes from 4 commits
e4151df
2fe8dac
0effe96
1aa3e6e
f9967df
d0303d7
4e011b3
b0fac27
88caadb
a8e8a67
2a03501
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Html, Head, Main, NextScript } from 'next/document' | ||
|
||
export default function Document() { | ||
return ( | ||
<Html lang="en"> | ||
<Head /> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</Html> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Head from 'next/head' | ||
import Image from 'next/image' | ||
|
||
const Page = () => { | ||
return ( | ||
<div> | ||
<Head> | ||
<title>Title</title> | ||
<meta name="description" content="Description..." /> | ||
<link rel="icon" type="image/jpeg" href="/test.jpg" /> | ||
</Head> | ||
styfle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<main> | ||
<Image src="/test.jpg" width="400" height="400" alt="basic image" /> | ||
</main> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* eslint-env jest */ | ||
|
||
import cheerio from 'cheerio' | ||
import validateHTML from 'html-validator' | ||
import { | ||
check, | ||
findPort, | ||
|
@@ -1039,6 +1040,26 @@ function runTests(mode) { | |
} | ||
} | ||
}) | ||
|
||
it('should be vaild W3C HTML', async () => { | ||
theoludwig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let browser | ||
try { | ||
browser = await webdriver(appPort, '/valid-html-w3c') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets loop through every page here to ensure all usages of the image component are valid HTML There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will try but that requires a lot of changes to these pages because a lot of them are not valid W3C because of all kinds of errors like duplicated IDs etc. And I feel like it's unrelated to this PR. Testing only with the |
||
await waitFor(1000) | ||
expect(await browser.hasElementByCssSelector('img')).toBeTruthy() | ||
const url = await browser.url() | ||
const result = await validateHTML({ | ||
url, | ||
format: 'json', | ||
isLocal: true, | ||
}) | ||
expect(result.messages).toEqual([]) | ||
} finally { | ||
if (browser) { | ||
await browser.close() | ||
} | ||
} | ||
}) | ||
} | ||
|
||
describe('Image Component Tests', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this isn't using the latest version, 6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, v6 dropped support for Node.js v12 (ref: zrrrzzt/html-validator@c3a11fa), hence failing the test using Node.js v12.
But Next.js support Node.js >= 12.22.0.
But yes instead to use
5
, we could use5.1.18
. 👍