Back to Biomejs

noNextAsyncClientComponent

src/content/docs/linter/rules/no-next-async-client-component.mdx

latest5.4 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v2.2.0` - Diagnostic Category: [`lint/correctness/noNextAsyncClientComponent`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - This rule belongs to the following domains: - [`next`](/linter/domains#next) - Sources: - Same as [`@next/next/no-async-client-component`](https://nextjs.org/docs/messages/no-async-client-component)

How to configure

json
{
	"linter": {
		"rules": {
			"correctness": {
				"noNextAsyncClientComponent": "error"
			}
		}
	}
}

Description

Prevent client components from being async functions.

This rule prevents the use of async functions for client components in Next.js applications. Client components marked with "use client" directive should not be async as this can cause hydration mismatches, break component rendering lifecycle, and lead to unexpected behavior with React's concurrent features.

Examples

Invalid

jsx
"use client";

export default async function MyComponent() {
  return <div>Hello</div>;
}
<pre class="language-text"><code class="language-text">code-block.jsx:3:16 <a href="https://biomejs.dev/linter/rules/no-next-async-client-component">lint/correctness/noNextAsyncClientComponent</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">The component </span><span style="color: Tomato;"><strong>MyComponent</strong></span><span style="color: Tomato;"> is an async client component, which is not allowed.</span> <strong>1 │ </strong>&quot;use client&quot;; <strong>2 │ </strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong>export default async function MyComponent() &#123; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>4 │ </strong> return &lt;div&gt;Hello&lt;/div&gt;; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>5 │ </strong>&#125; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong> <strong>6 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Client components with &quot;use client&quot; directive should not be async functions as this can cause hydration mismatches and break React's rendering lifecycle.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Consider using useEffect for async operations inside the component, or remove the &quot;use client&quot; directive if this should be a server component.</span> </code></pre>

Valid

jsx
"use client";

export default function MyComponent() {
  return <div>Hello</div>;
}
jsx
// No "use client" directive - server component can be async
export default async function ServerComponent() {
  const data = await fetch('/api/data');
  return <div>{data}</div>;
}
</TabItem> </Tabs>