Skip to content

Commit f9f53a6

Browse files
authored
feat(next): add support for custom props on the html element (#11738)
This PR adds support for passing additional props to the HTML element of Next.js `RootLayout`. #### Context In our setup, we use several custom Chakra UI components. This change enables us to add a custom font `className` to the HTML element, following the official Chakra UI documentation: [Using custom fonts in Chakra UI with Next.js](https://v2.chakra-ui.com/getting-started/nextjs-app-guide#using-custom-font) #### Example Usage With this update, we can now pass a `className` for custom fonts like this: ```tsx import { Rubik } from 'next/font/google' const rubik = Rubik({ subsets: ['latin'], variable: '--font-rubik', }) const Layout = ({ children }: Args) => { return ( <RootLayout htmlProps={{ className: rubik.variable }}> {children} </RootLayout> ); } ```
1 parent 90a08c4 commit f9f53a6

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

packages/next/src/layouts/Root/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ export const RootLayout = async ({
2525
config: configPromise,
2626
importMap,
2727
serverFunction,
28+
htmlProps = {},
2829
}: {
2930
readonly children: React.ReactNode
3031
readonly config: Promise<SanitizedConfig>
3132
readonly importMap: ImportMap
3233
readonly serverFunction: ServerFunctionClient
34+
readonly htmlProps?: React.HtmlHTMLAttributes<HTMLHtmlElement>
3335
}) => {
3436
checkDependencies()
3537

@@ -105,6 +107,7 @@ export const RootLayout = async ({
105107
dir={dir}
106108
lang={languageCode}
107109
suppressHydrationWarning={config?.admin?.suppressHydrationWarning ?? false}
110+
{...htmlProps}
108111
>
109112
<head>
110113
<style>{`@layer payload-default, payload;`}</style>

0 commit comments

Comments
 (0)