Skip to content

Commit 6d6d750

Browse files
authored
Merge branch 'canary' into update/fonts-data-1745540061055
2 parents 863d5bd + c90fc09 commit 6d6d750

File tree

205 files changed

+1714
-1447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+1714
-1447
lines changed

docs/01-app/01-getting-started/01-installation.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export default function Document() {
202202

203203
### Create the `public` folder (optional)
204204

205-
Create a [`public` folder](/docs/app/building-your-application/optimizing/static-assets) at the root of your project to store static assets such as images, fonts, etc. Files inside `public` can then be referenced by your code starting from the base URL (`/`).
205+
Create a [`public` folder](/docs/app/api-reference/file-conventions/public-folder) at the root of your project to store static assets such as images, fonts, etc. Files inside `public` can then be referenced by your code starting from the base URL (`/`).
206206

207207
You can then reference these assets using the root path (`/`). For example, `public/profile.png` can be referenced as `/profile.png`:
208208

docs/01-app/01-getting-started/02-project-structure.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ Top-level folders are used to organize your application's code and static assets
2020
height="525"
2121
/>
2222

23-
| | |
24-
| ------------------------------------------------------------------------ | ---------------------------------- |
25-
| [`app`](/docs/app/building-your-application/routing) | App Router |
26-
| [`pages`](/docs/pages/building-your-application/routing) | Pages Router |
27-
| [`public`](/docs/app/building-your-application/optimizing/static-assets) | Static assets to be served |
28-
| [`src`](/docs/app/api-reference/file-conventions/src-folder) | Optional application source folder |
23+
| | |
24+
| ------------------------------------------------------------------ | ---------------------------------- |
25+
| [`app`](/docs/app/building-your-application/routing) | App Router |
26+
| [`pages`](/docs/pages/building-your-application/routing) | Pages Router |
27+
| [`public`](/docs/app/api-reference/file-conventions/public-folder) | Static assets to be served |
28+
| [`src`](/docs/app/api-reference/file-conventions/src-folder) | Optional application source folder |
2929

3030
### Top-level files
3131

docs/01-app/01-getting-started/05-css.mdx

Lines changed: 6 additions & 294 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,22 @@ title: How to use CSS in your application
33
nav_title: CSS
44
description: Learn about the different ways to add CSS to your application, including CSS Modules, Global CSS, Tailwind CSS, and more.
55
related:
6-
title: API Reference
7-
description: Learn more about the features mentioned in this page by reading the API Reference.
6+
title: Next Steps
7+
description: Learn more about the features mentioned in this page.
88
links:
9-
- app/api-reference/config/next-config-js/sassOptions
10-
- architecture/nextjs-compiler
9+
- app/guides/sass
10+
- app/guides/css-in-js
1111
---
1212

1313
Next.js provides several ways to use CSS in your application, including:
1414

1515
- [CSS Modules](#css-modules)
1616
- [Global CSS](#global-css)
1717
- [Tailwind CSS](#tailwind-css)
18-
- [Sass](#sass)
19-
- [CSS-in-JS](#css-in-js)
18+
- [Sass](/docs/app/guides/sass)
19+
- [CSS-in-JS](/docs/app/guides/css-in-js)
2020
- [External Stylesheets](#external-stylesheets)
2121

22-
This page will guide you through how to use each of these approaches.
23-
2422
## CSS Modules
2523

2624
CSS Modules locally scope CSS by generating unique class names. This allows you to use the same class in different files without worrying about naming collisions.
@@ -185,292 +183,6 @@ export default function Page() {
185183
}
186184
```
187185

188-
## Sass
189-
190-
Next.js integrates with [Sass](https://sass-lang.com/) using both the [`.scss`](https://sass-lang.com/documentation/syntax/#scss) and [`.sass`](https://sass-lang.com/documentation/syntax#the-indented-syntax) extensions and syntax.
191-
192-
You can also use component-level Sass via [CSS Modules](#css-modules) and the `.module.scss`or `.module.sass` extension.
193-
194-
### Installing Sass
195-
196-
To start using Sass, install the `sass` package:
197-
198-
```bash filename="Terminal"
199-
npm install --save-dev sass
200-
```
201-
202-
### Customizing Sass options
203-
204-
If you want to configure your Sass options, use the [`sassOptions`](/docs/app/api-reference/config/next-config-js/sassOptions) option in `next.config.js`.
205-
206-
```ts filename="next.config.ts" switcher
207-
import type { NextConfig } from 'next'
208-
209-
const nextConfig: NextConfig = {
210-
sassOptions: {
211-
additionalData: `$var: red;`,
212-
},
213-
}
214-
215-
export default nextConfig
216-
```
217-
218-
```js filename="next.config.mjs" switcher
219-
/** @type {import('next').NextConfig} */
220-
221-
const nextConfig = {
222-
sassOptions: {
223-
additionalData: `$var: red;`,
224-
},
225-
}
226-
227-
export default nextConfig
228-
```
229-
230-
## CSS-in-JS
231-
232-
> **Warning:** CSS-in-JS libraries which require runtime JavaScript are not currently supported in React Server Components. Using CSS-in-JS with newer React features like Server Components and Streaming requires library authors to support the latest version of React.
233-
234-
The following libraries are supported in **Client Components** in the `app` directory (alphabetical):
235-
236-
- [`ant-design`](https://ant.design/docs/react/use-with-next#using-app-router)
237-
- [`chakra-ui`](https://chakra-ui.com/docs/get-started/frameworks/next-app)
238-
- [`@fluentui/react-components`](https://react.fluentui.dev/?path=/docs/concepts-developer-server-side-rendering-next-js-appdir-setup--page)
239-
- [`kuma-ui`](https://kuma-ui.com)
240-
- [`@mui/material`](https://mui.com/material-ui/guides/next-js-app-router/)
241-
- [`@mui/joy`](https://mui.com/joy-ui/integrations/next-js-app-router/)
242-
- [`pandacss`](https://panda-css.com)
243-
- [`styled-jsx`](#styled-jsx)
244-
- [`styled-components`](#styled-components)
245-
- [`stylex`](https://stylexjs.com)
246-
- [`tamagui`](https://tamagui.dev/docs/guides/next-js#server-components)
247-
- [`tss-react`](https://tss-react.dev/)
248-
- [`vanilla-extract`](https://vanilla-extract.style)
249-
250-
The following are currently working on support:
251-
252-
- [`emotion`](https://github.com/emotion-js/emotion/issues/2928)
253-
254-
If you want to style Server Components, we recommend using [CSS Modules](#css-modules) or other solutions that output CSS files, like [Tailwind CSS](#tailwind-css).
255-
256-
### Configuring CSS-in-JS
257-
258-
To configure CSS-in-JS, you need to:
259-
260-
1. Create a **style registry** to collect all CSS rules in a render.
261-
2. Use the `useServerInsertedHTML` hook to inject rules before any content that might use them.
262-
3. Create a Client Component that wraps your app with the style registry during initial server-side rendering.
263-
264-
#### `styled-jsx`
265-
266-
To configure `styled-jsx` for your application, create a new registry:
267-
268-
```tsx filename="app/registry.tsx" switcher
269-
'use client'
270-
271-
import React, { useState } from 'react'
272-
import { useServerInsertedHTML } from 'next/navigation'
273-
import { StyleRegistry, createStyleRegistry } from 'styled-jsx'
274-
275-
export default function StyledJsxRegistry({
276-
children,
277-
}: {
278-
children: React.ReactNode
279-
}) {
280-
// Only create stylesheet once with lazy initial state
281-
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
282-
const [jsxStyleRegistry] = useState(() => createStyleRegistry())
283-
284-
useServerInsertedHTML(() => {
285-
const styles = jsxStyleRegistry.styles()
286-
jsxStyleRegistry.flush()
287-
return <>{styles}</>
288-
})
289-
290-
return <StyleRegistry registry={jsxStyleRegistry}>{children}</StyleRegistry>
291-
}
292-
```
293-
294-
```jsx filename="app/registry.js" switcher
295-
'use client'
296-
297-
import React, { useState } from 'react'
298-
import { useServerInsertedHTML } from 'next/navigation'
299-
import { StyleRegistry, createStyleRegistry } from 'styled-jsx'
300-
301-
export default function StyledJsxRegistry({ children }) {
302-
// Only create stylesheet once with lazy initial state
303-
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
304-
const [jsxStyleRegistry] = useState(() => createStyleRegistry())
305-
306-
useServerInsertedHTML(() => {
307-
const styles = jsxStyleRegistry.styles()
308-
jsxStyleRegistry.flush()
309-
return <>{styles}</>
310-
})
311-
312-
return <StyleRegistry registry={jsxStyleRegistry}>{children}</StyleRegistry>
313-
}
314-
```
315-
316-
Then, wrap your [root layout](/docs/app/api-reference/file-conventions/layout#root-layouts) with the registry:
317-
318-
```tsx filename="app/layout.tsx" switcher
319-
import StyledJsxRegistry from './registry'
320-
321-
export default function RootLayout({
322-
children,
323-
}: {
324-
children: React.ReactNode
325-
}) {
326-
return (
327-
<html>
328-
<body>
329-
<StyledJsxRegistry>{children}</StyledJsxRegistry>
330-
</body>
331-
</html>
332-
)
333-
}
334-
```
335-
336-
```jsx filename="app/layout.js" switcher
337-
import StyledJsxRegistry from './registry'
338-
339-
export default function RootLayout({ children }) {
340-
return (
341-
<html>
342-
<body>
343-
<StyledJsxRegistry>{children}</StyledJsxRegistry>
344-
</body>
345-
</html>
346-
)
347-
}
348-
```
349-
350-
#### `styled-components`
351-
352-
To use `styled-components`, enable it in `next.config.js`:
353-
354-
```ts filename="next.config.ts" switcher
355-
import type { NextConfig } from 'next'
356-
357-
const nextConfig: NextConfig = {
358-
compiler: {
359-
styledComponents: true,
360-
},
361-
}
362-
363-
export default nextConfig
364-
```
365-
366-
```js filename="next.config.mjs" switcher
367-
/** @type {import('next').NextConfig} */
368-
369-
const nextConfig = {
370-
compiler: {
371-
styledComponents: true,
372-
},
373-
}
374-
375-
export default nextConfig
376-
```
377-
378-
Then, use the `styled-components` API to create a global registry component to collect all CSS style rules generated during a render, and a function to return those rules. Then use the `useServerInsertedHTML` hook to inject the styles collected in the registry into the `<head>` HTML tag in the root layout.
379-
380-
```tsx filename="lib/registry.tsx" switcher
381-
'use client'
382-
383-
import React, { useState } from 'react'
384-
import { useServerInsertedHTML } from 'next/navigation'
385-
import { ServerStyleSheet, StyleSheetManager } from 'styled-components'
386-
387-
export default function StyledComponentsRegistry({
388-
children,
389-
}: {
390-
children: React.ReactNode
391-
}) {
392-
// Only create stylesheet once with lazy initial state
393-
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
394-
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())
395-
396-
useServerInsertedHTML(() => {
397-
const styles = styledComponentsStyleSheet.getStyleElement()
398-
styledComponentsStyleSheet.instance.clearTag()
399-
return <>{styles}</>
400-
})
401-
402-
if (typeof window !== 'undefined') return <>{children}</>
403-
404-
return (
405-
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}>
406-
{children}
407-
</StyleSheetManager>
408-
)
409-
}
410-
```
411-
412-
```jsx filename="lib/registry.js" switcher
413-
'use client'
414-
415-
import React, { useState } from 'react'
416-
import { useServerInsertedHTML } from 'next/navigation'
417-
import { ServerStyleSheet, StyleSheetManager } from 'styled-components'
418-
419-
export default function StyledComponentsRegistry({ children }) {
420-
// Only create stylesheet once with lazy initial state
421-
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
422-
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())
423-
424-
useServerInsertedHTML(() => {
425-
const styles = styledComponentsStyleSheet.getStyleElement()
426-
styledComponentsStyleSheet.instance.clearTag()
427-
return <>{styles}</>
428-
})
429-
430-
if (typeof window !== 'undefined') return <>{children}</>
431-
432-
return (
433-
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}>
434-
{children}
435-
</StyleSheetManager>
436-
)
437-
}
438-
```
439-
440-
Wrap the `children` of the root layout with the style registry component:
441-
442-
```tsx filename="app/layout.tsx" switcher
443-
import StyledComponentsRegistry from './lib/registry'
444-
445-
export default function RootLayout({
446-
children,
447-
}: {
448-
children: React.ReactNode
449-
}) {
450-
return (
451-
<html>
452-
<body>
453-
<StyledComponentsRegistry>{children}</StyledComponentsRegistry>
454-
</body>
455-
</html>
456-
)
457-
}
458-
```
459-
460-
```jsx filename="app/layout.js" switcher
461-
import StyledComponentsRegistry from './lib/registry'
462-
463-
export default function RootLayout({ children }) {
464-
return (
465-
<html>
466-
<body>
467-
<StyledComponentsRegistry>{children}</StyledComponentsRegistry>
468-
</body>
469-
</html>
470-
)
471-
}
472-
```
473-
474186
## External stylesheets
475187

476188
Stylesheets published by external packages can be imported anywhere in the `app` directory, including colocated components:

docs/01-app/01-getting-started/10-metadata-and-og-images.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,5 +302,5 @@ export default async function Image({ params }) {
302302
> **Good to know**:
303303
>
304304
> - Examples are available in the [Vercel OG Playground](https://og-playground.vercel.app/).
305-
> - `ImageResponse` uses [@vercel/og](https://vercel.com/docs/concepts/functions/edge-functions/og-image-generation), [Satori](https://github.com/vercel/satori), and Resvg to convert HTML and CSS into PNG.
305+
> - `ImageResponse` uses [`@vercel/og`](https://vercel.com/docs/og-image-generation), [`satori`](https://github.com/vercel/satori), and `resvg` to convert HTML and CSS into PNG.
306306
> - Only flexbox and a subset of CSS properties are supported. Advanced layouts (e.g. `display: grid`) will not work.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2-
title: CSS-in-JS
2+
title: How to use CSS-in-JS libraries
3+
nav_title: CSS-in-JS
34
description: Use CSS-in-JS libraries with Next.js
45
---
56

docs/01-app/02-guides/migrating/app-router-migration.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,9 +889,9 @@ In the `pages` directory, global stylesheets are restricted to only `pages/_app.
889889
- [CSS Modules](/docs/app/building-your-application/styling/css#css-modules)
890890
- [Tailwind CSS](/docs/app/building-your-application/styling/tailwind-css)
891891
- [Global Styles](/docs/app/building-your-application/styling/css#global-styles)
892-
- [CSS-in-JS](/docs/app/building-your-application/styling/css-in-js)
892+
- [CSS-in-JS](/docs/app/guides/css-in-js)
893893
- [External Stylesheets](/docs/app/building-your-application/styling/css#external-stylesheets)
894-
- [Sass](/docs/app/building-your-application/styling/sass)
894+
- [Sass](/docs/app/guides/sass)
895895

896896
#### Tailwind CSS
897897

0 commit comments

Comments
 (0)