Skip to content
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

Bail out of 404 page when favicon.ico doesn't exist #50795

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,14 @@ export default abstract class Server<ServerOptions extends Options = Options> {
ctx: RequestContext,
err: Error | null
): Promise<ResponsePayload | null> {
// Short-circuit favicon.ico in development to avoid compiling 404 page when the app has no favicon.ico.
// Since favicon.ico is automatically requested by the browser.
if (this.renderOpts.dev && ctx.pathname === '/favicon.ico') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe short-circuit in production is also a good idea. It wastes server to render full html 404 page that browser can't load as icon

return {
type: 'html',
body: new RenderResult(''),
}
}
const { res, query } = ctx
try {
let result: null | FindComponentsResult = null
Expand Down
Binary file added test/e2e/app-dir/hello-world/app/favicon.ico
Binary file not shown.
Empty file.