Unverified Commit 3552445e authored by Joseph's avatar Joseph Committed by GitHub

Docs/polyfills fix pages only (#82462)

Follow up for: https://github.com/vercel/next.js/issues/74730
parent 4eb46d8e
...@@ -43,19 +43,37 @@ In addition, to reduce bundle size, Next.js will only load these polyfills for b ...@@ -43,19 +43,37 @@ In addition, to reduce bundle size, Next.js will only load these polyfills for b
If your own code or any external npm dependencies require features not supported by your target browsers (such as IE 11), you need to add polyfills yourself. If your own code or any external npm dependencies require features not supported by your target browsers (such as IE 11), you need to add polyfills yourself.
<PagesOnly> #### In App Router
In this case, you should add a top-level import for the **specific polyfill** you need in your [Custom `<App>`](/docs/pages/building-your-application/routing/custom-app) or the individual component.
</PagesOnly>
<AppOnly>
To include polyfills, you can import them into the [`instrumentation-client.js` file](/docs/app/api-reference/file-conventions/instrumentation-client). To include polyfills, you can import them into the [`instrumentation-client.js` file](/docs/app/api-reference/file-conventions/instrumentation-client).
```ts filename="instrumentation-client.ts" ```ts filename="instrumentation-client.ts"
import './polyfills' import './polyfills'
``` ```
</AppOnly> #### In Pages Router
In this case, you should add a top-level import for the **specific polyfill** you need in your [Custom `<App>`](/docs/pages/building-your-application/routing/custom-app) or the individual component.
```tsx filename="pages/_app.tsx" switcher
import './polyfills'
import type { AppProps } from 'next/app'
export default function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
```
```jsx filename="pages/_app.jsx" switcher
import './polyfills'
export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
```
#### Conditionally loading polyfills
The best approach is to isolate unsupported features to specific UI sections and conditionally load the polyfill if needed. The best approach is to isolate unsupported features to specific UI sections and conditionally load the polyfill if needed.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment