-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Provide default metadataBase for local and vercel deployment #47568
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
273bd28
Provide default metadataBase for local and vercel deployment
huozhi 3ef437a
use empty metadata for test case
huozhi 6dbe72d
error when missing metadataBase in prod
huozhi 2edb6dd
rm comment
huozhi 4e7ae69
fix lint
huozhi 05c0380
remove useless cond
huozhi 35eeb1f
Merge branch 'canary' into metadata/default-metabase
huozhi 64c84fd
rm comments
huozhi 52f0eb5
Merge branch 'canary' into metadata/default-metabase
huozhi d2d152e
Merge branch 'canary' into metadata/default-metabase
huozhi ba4c507
Merge branch 'canary' into metadata/default-metabase
kodiakhq[bot] b4fcf18
Merge branch 'canary' into metadata/default-metabase
huozhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
12 changes: 12 additions & 0 deletions
12
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,12 @@ | ||
export default function Layout({ children }) { | ||
return ( | ||
<html> | ||
<head></head> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} | ||
|
||
export const metadata = { | ||
title: 'Next.js App', | ||
} |
23 changes: 23 additions & 0 deletions
23
test/e2e/app-dir/metadata-missing-metadata-base/app/opengraph-image.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,23 @@ | ||
import { ImageResponse } from '@vercel/og' | ||
|
||
export const alt = 'Open Graph' | ||
|
||
export default function og() { | ||
return new ImageResponse( | ||
( | ||
<div | ||
style={{ | ||
width: '100%', | ||
height: '100%', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
fontSize: 128, | ||
background: 'lavender', | ||
}} | ||
> | ||
Open Graph | ||
</div> | ||
) | ||
) | ||
} |
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', | ||
} |
67 changes: 67 additions & 0 deletions
67
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,67 @@ | ||
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 | ||
// const logs = [] | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
skipStart: true, | ||
dependencies: { | ||
'@vercel/og': 'latest', | ||
}, | ||
files: new FileRef(__dirname), | ||
}) | ||
// next.on('stderr', (log) => { | ||
// logs.push(log) | ||
// }) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
if (globalThis.isNextDev) { | ||
it('should warning in development', async () => { | ||
await next.start() | ||
await fetchViaHTTP(next.url, '/') | ||
expect(next.cliOutput).toInclude( | ||
'metadata.metadataBase is not set and fallbacks to "http://localhost:' | ||
) | ||
expect(next.cliOutput).toInclude( | ||
'please specify it in root layout to resolve absolute urls.' | ||
) | ||
}) | ||
} else { | ||
it('should error in production', async () => { | ||
await expect(next.start()).rejects.toThrow('next build failed') | ||
expect(next.cliOutput).toInclude( | ||
'metadata.metadataBase needs to be provided for resolving absolute URL: /opengraph-image?' | ||
) | ||
}) | ||
} | ||
}) | ||
|
||
// createNextDescribe( | ||
// 'app dir - metadata missing metadataBase', | ||
// { | ||
// files: __dirname, | ||
// dependencies: { | ||
// '@vercel/og': '0.4.1', | ||
// }, | ||
// }, | ||
// ({ next, isNextDev, isNextStart }) => { | ||
|
||
// if (isNextDev) { | ||
// console.log('logs', logs) | ||
// expect( | ||
// logs.some((log) => | ||
// /metadata\.metadataBase is not set and fallbacks to "http:\/\/localhost:\d+", please specify it in root layout to resolve absolute urls/.test( | ||
// log | ||
// ) | ||
// ) | ||
// ).toBe(true) | ||
// } else if (isNextStart) { | ||
|
||
// } | ||
// } | ||
// ) | ||
huozhi marked this conversation as resolved.
Show resolved
Hide resolved
|
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 }, | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Note that
VERCEL_URL
will not be the domain visited but will be the unique url. Are you sure you want to expose this by default? It could allow someone to use a pinned version of your application instead of the intended domain that is always latest.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, especially when you're developing a og card, or tweaking around other metadata assets, you want to see if that preview url is working based on your changes instead of always requesting the prod major version