-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add warning for missing metadataBase in social images (#49180)
We picked `VERCEL_URL` env for `metadataBase` in preview mode, but also picking that on production, this could potentially use the unique build url for social images if you didn't set `metadataBase` We recommend to set the major/preferred domain to `metadataBase` if you're using social images, this PR help warn you in every env if you're missing that [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1683150633962539?thread_ts=1683144147.664059&cid=C03KAR5DCKC)
- Loading branch information
Showing
7 changed files
with
77 additions
and
10 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
8 changes: 8 additions & 0 deletions
8
test/e2e/app-dir/metadata-missing-metadata-base/app/layout.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,8 @@ | ||
export default function Layout({ children }) { | ||
return ( | ||
<html> | ||
<head></head> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
Binary file added
BIN
+1.62 KB
test/e2e/app-dir/metadata-missing-metadata-base/app/opengraph-image.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,9 @@ | ||
import React from 'react' | ||
|
||
export default function Page() { | ||
return <>hello index</> | ||
} | ||
|
||
export const metadata = { | ||
title: 'index page', | ||
} |
31 changes: 31 additions & 0 deletions
31
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import { fetchViaHTTP } from 'next-test-utils' | ||
|
||
describe('app dir - metadata missing metadataBase', () => { | ||
let next: NextInstance | ||
|
||
if ((global as any).isNextDeploy) { | ||
return it('should skip for deploy', () => {}) | ||
} | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
skipStart: true, | ||
files: new FileRef(__dirname), | ||
}) | ||
}) | ||
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, fallbacks to' | ||
) | ||
expect(next.cliOutput).toInclude('"http://localhost:') | ||
expect(next.cliOutput).toInclude( | ||
'. See https://beta.nextjs.org/docs/api-reference/metadata#metadatabase' | ||
) | ||
}) | ||
}) |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/metadata-missing-metadata-base/next.config.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,3 @@ | ||
module.exports = { | ||
experimental: { appDir: true }, | ||
} |