-
Notifications
You must be signed in to change notification settings - Fork 27.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polish unsupported metadata warning with doc link (#58750)
* Add docs link to the warning, add codemod link to viewport docs section * Only log the warning once after the metadata resolving process, this will avoid multiple duplicated logs showing for one page. Closes NEXT-1723
- Loading branch information
Showing
4 changed files
with
68 additions
and
32 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
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/metadata-missing-metadata-base/app/unsupported-metadata/page.js
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,7 @@ | ||
export default function Page() { | ||
return 'unsupported metadata' | ||
} | ||
|
||
export const metadata = { | ||
themeColor: 'light', | ||
} |
71 changes: 41 additions & 30 deletions
71
test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts
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 |
---|---|---|
@@ -1,34 +1,45 @@ | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { fetchViaHTTP, findPort } from 'next-test-utils' | ||
import { createNextDescribe } from 'e2e-utils' | ||
import { fetchViaHTTP } from 'next-test-utils' | ||
|
||
describe('app dir - metadata missing metadataBase', () => { | ||
let next: NextInstance | ||
let port: number | ||
createNextDescribe( | ||
'app dir - metadata missing metadataBase', | ||
{ | ||
files: __dirname, | ||
skipDeployment: true, | ||
}, | ||
({ next, isNextStart }) => { | ||
// If it's start mode, we get the whole logs since they're from build process. | ||
// If it's dev mode, we get the logs after request | ||
function getCliOutput(logStartPosition: number) { | ||
return isNextStart | ||
? next.cliOutput | ||
: next.cliOutput.slice(logStartPosition) | ||
} | ||
|
||
if ((global as any).isNextDeploy) { | ||
return it('should skip for deploy', () => {}) | ||
} | ||
|
||
beforeAll(async () => { | ||
port = await findPort() | ||
next = await createNext({ | ||
skipStart: true, | ||
files: new FileRef(__dirname), | ||
forcedPort: port + '', | ||
it('should fallback to localhost if metadataBase is missing for absolute urls resolving', async () => { | ||
const logStartPosition = next.cliOutput.length | ||
await fetchViaHTTP(next.url, '/') | ||
// | ||
const output = getCliOutput(logStartPosition) | ||
expect(output).toInclude( | ||
'metadata.metadataBase is not set for resolving social open graph or twitter images,' | ||
) | ||
expect(output).toMatch(/using "http:\/\/localhost:\d+/) | ||
expect(output).toInclude( | ||
'. See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase' | ||
) | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('should fallback to localhost if metadataBase is missing for absolute urls resolving', async () => { | ||
await next.start() | ||
await fetchViaHTTP(next.url, '/') | ||
expect(next.cliOutput).toInclude( | ||
'metadata.metadataBase is not set for resolving social open graph or twitter images, using' | ||
) | ||
expect(next.cliOutput).toInclude(`"http://localhost:${port}`) | ||
expect(next.cliOutput).toInclude( | ||
'. See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase' | ||
) | ||
}) | ||
}) | ||
it('should warn for unsupported metadata properties', async () => { | ||
const logStartPosition = next.cliOutput.length | ||
await fetchViaHTTP(next.url, '/unsupported-metadata') | ||
const output = getCliOutput(logStartPosition) | ||
expect(output).toInclude( | ||
'Unsupported metadata themeColor is configured in metadata export in /unsupported-metadata. Please move it to viewport' | ||
) | ||
expect(output).toInclude( | ||
'Read more: https://nextjs.org/docs/app/api-reference/functions/generate-viewport' | ||
) | ||
}) | ||
} | ||
) |