Back to Biomejs

noQwikUseVisibleTask

src/content/docs/linter/rules/no-qwik-use-visible-task.mdx

latest4.0 KB
Original Source

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

<Tabs> <TabItem label="JSX and TSX" icon="seti:javascript"> ## Summary - Rule available since: `v2.1.4` - Diagnostic Category: [`lint/correctness/noQwikUseVisibleTask`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - 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: - [`qwik`](/linter/domains#qwik) - Sources: - Same as [`qwik/no-use-visible-task`](https://qwik.dev/docs/advanced/eslint/#no-use-visible-task)

How to configure

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

Description

Disallow useVisibleTask$() functions in Qwik components.

Prevents hydration-blocking operations that hurt Qwik's resumability. See Qwik Tasks Documentation for proper alternatives.

Examples

Invalid

js
useVisibleTask$(() => {
  console.log('Component is visible');
});
<pre class="language-text"><code class="language-text">code-block.js:1:1 <a href="https://biomejs.dev/linter/rules/no-qwik-use-visible-task">lint/correctness/noQwikUseVisibleTask</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Avoid </span><span style="color: Tomato;"><strong>useVisibleTask$</strong></span><span style="color: Tomato;"> for non-interactive initialization</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>useVisibleTask$(() =&gt; &#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>2 │ </strong> console.log('Component is visible'); <strong>3 │ </strong>&#125;); <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This hook executes immediately on component mount without user interaction, potentially: </span> <span style="color: lightgreen;">- Hurting performance (blocking hydration) </span> <span style="color: lightgreen;">- Causing layout shifts (CLS) </span> <span style="color: lightgreen;">- Breaking SSR compatibility</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Check the </span><span style="color: lightgreen;"><a href="https://qwik.dev/docs/components/tasks/">Qwik documentation</a></span><span style="color: lightgreen;"> for suitable alternatives.</span> </code></pre>

Valid

js
useTask$(() => {
  console.log('Task executed');
});
</TabItem> </Tabs>