Skip to content

Commit

Permalink
Remove optimizeFonts (Automatic font optimization) superseded by ne…
Browse files Browse the repository at this point in the history
…xt/font (#69137)

## What?

The `optimizeFonts` optimization has been replaced by `next/font` for
almost 2 years and was already no longer documented. This PR cleans up
the code related to it. It's recommended to use `next/font` as it's
better in every way, ensuring you get preloading of the font but also a
local fallback and better fallbacks.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
  • Loading branch information
timneutkens authored Aug 21, 2024
1 parent 161cd00 commit 3ab6d17
Show file tree
Hide file tree
Showing 63 changed files with 7 additions and 1,796 deletions.
17 changes: 0 additions & 17 deletions packages/next/src/build/flying-shuttle/stitch-builds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
APP_BUILD_MANIFEST,
APP_PATH_ROUTES_MANIFEST,
APP_PATHS_MANIFEST,
AUTOMATIC_FONT_OPTIMIZATION_MANIFEST,
BUILD_MANIFEST,
CLIENT_REFERENCE_MANIFEST,
FUNCTIONS_CONFIG_MANIFEST,
Expand Down Expand Up @@ -366,22 +365,6 @@ export async function stitchBuilds(
)}`
)

// for server/font-manifest.json we just merge the arrays
for (const file of [AUTOMATIC_FONT_OPTIMIZATION_MANIFEST]) {
const [restoreFontManifest, currentFontManifest] = await Promise.all(
[
path.join(shuttleDir, 'server', file),
path.join(distDir, 'server', file),
].map(async (f) => JSON.parse(await fs.promises.readFile(f, 'utf8')))
)
const mergedFontManifest = [...restoreFontManifest, ...currentFontManifest]

await fs.promises.writeFile(
path.join(distDir, 'server', file),
JSON.stringify(mergedFontManifest, null, 2)
)
}

// for server/functions-config-manifest.json we just merge
// the functions field
const [restoreFunctionsConfigManifest, currentFunctionsConfigManifest] =
Expand Down
11 changes: 0 additions & 11 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import {
CLIENT_STATIC_FILES_PATH,
EXPORT_DETAIL,
EXPORT_MARKER,
AUTOMATIC_FONT_OPTIMIZATION_MANIFEST,
IMAGES_MANIFEST,
PAGES_MANIFEST,
PHASE_PRODUCTION_BUILD,
Expand Down Expand Up @@ -2342,12 +2341,6 @@ export default async function build(
]
: []),
REACT_LOADABLE_MANIFEST,
config.optimizeFonts
? path.join(
SERVER_DIRECTORY,
AUTOMATIC_FONT_OPTIMIZATION_MANIFEST
)
: null,
BUILD_ID_FILE,
path.join(SERVER_DIRECTORY, NEXT_FONT_MANIFEST + '.js'),
path.join(SERVER_DIRECTORY, NEXT_FONT_MANIFEST + '.json'),
Expand Down Expand Up @@ -2469,10 +2462,6 @@ export default async function build(
featureName: 'experimental/nextScriptWorkers',
invocationCount: config.experimental.nextScriptWorkers ? 1 : 0,
},
{
featureName: 'optimizeFonts',
invocationCount: config.optimizeFonts ? 1 : 0,
},
{
featureName: 'experimental/ppr',
invocationCount: config.experimental.ppr ? 1 : 0,
Expand Down
15 changes: 0 additions & 15 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1856,20 +1856,6 @@ export default async function getBaseWebpackConfig(
clientRouterFilters,
}),
new ProfilingPlugin({ runWebpackSpan, rootDir: dir }),
config.optimizeFonts &&
!dev &&
isNodeServer &&
(function () {
const { FontStylesheetGatheringPlugin } =
require('./webpack/plugins/font-stylesheet-gathering-plugin') as {
FontStylesheetGatheringPlugin: typeof import('./webpack/plugins/font-stylesheet-gathering-plugin').FontStylesheetGatheringPlugin
}
return new FontStylesheetGatheringPlugin({
adjustFontFallbacks: config.experimental.adjustFontFallbacks,
adjustFontFallbacksWithSizeAdjust:
config.experimental.adjustFontFallbacksWithSizeAdjust,
})
})(),
new WellKnownErrorsPlugin(),
isClient &&
new CopyFilePlugin({
Expand Down Expand Up @@ -2071,7 +2057,6 @@ export default async function getBaseWebpackConfig(
buildActivityPosition: config.devIndicators.buildActivityPosition,
productionBrowserSourceMaps: !!config.productionBrowserSourceMaps,
reactStrictMode: config.reactStrictMode,
optimizeFonts: config.optimizeFonts,
optimizeCss: config.experimental.optimizeCss,
nextScriptWorkers: config.experimental.nextScriptWorkers,
scrollRestoration: config.experimental.scrollRestoration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ export function getDefineEnv({
'process.env.__NEXT_STRICT_MODE_APP':
// When next.config.js does not have reactStrictMode it's enabled by default.
config.reactStrictMode === null ? true : config.reactStrictMode,
'process.env.__NEXT_OPTIMIZE_FONTS': !dev && config.optimizeFonts,
'process.env.__NEXT_OPTIMIZE_CSS':
(config.experimental.optimizeCss && !dev) ?? false,
'process.env.__NEXT_SCRIPT_WORKERS':
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions packages/next/src/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import { loadEnvConfig } from '@next/env'
import { isAPIRoute } from '../lib/is-api-route'
import { getPagePath } from '../server/require'
import type { Span } from '../trace'
import type { FontConfig } from '../server/font-utils'
import type { MiddlewareManifest } from '../build/webpack/plugins/middleware-plugin'
import { isAppRouteRoute } from '../lib/is-app-route-route'
import { isAppPageRoute } from '../lib/is-app-page-route'
Expand Down Expand Up @@ -340,7 +339,6 @@ async function exportAppImpl(
optimizeCss: nextConfig.experimental.optimizeCss,
nextConfigOutput: nextConfig.output,
nextScriptWorkers: nextConfig.experimental.nextScriptWorkers,
optimizeFonts: nextConfig.optimizeFonts as FontConfig,
largePageDataBytes: nextConfig.experimental.largePageDataBytes,
serverActions: nextConfig.experimental.serverActions,
serverComponents: enabledDirectories.app,
Expand Down
10 changes: 2 additions & 8 deletions packages/next/src/export/routes/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,10 @@ export async function exportPagesPage(
}
} else {
/**
* This sets environment variable to be used at the time of static export by head.tsx.
* This sets environment variable to be used at the time of SSR by head.tsx.
* Using this from process.env allows targeting SSR by calling
* `process.env.__NEXT_OPTIMIZE_FONTS`.
* TODO(prateekbh@): Remove this when experimental.optimizeFonts are being cleaned up.
* `process.env.__NEXT_OPTIMIZE_CSS`.
*/
if (renderOpts.optimizeFonts) {
process.env.__NEXT_OPTIMIZE_FONTS = JSON.stringify(
renderOpts.optimizeFonts
)
}
if (renderOpts.optimizeCss) {
process.env.__NEXT_OPTIMIZE_CSS = JSON.stringify(true)
}
Expand Down
Loading

0 comments on commit 3ab6d17

Please sign in to comment.