Skip to content

useQwikValidLexicalScope

¥Summary

¥How to configure

biome.json
{
"linter": {
"rules": {
"nursery": {
"useQwikValidLexicalScope": "error"
}
}
}
}

¥Description

禁止在 Qwik 美元 ($) 作用域中使用不可序列化的表达式。

¥Disallow unserializable expressions in Qwik dollar ($) scopes.

确保 Qwik 组件中捕获的所有值都可以正确序列化以实现可恢复性。请参阅 Qwik 优化器词法范围 获取正确的使用模式。

¥Ensures all captured values in Qwik components can be properly serialized for resumability. See Qwik Optimizer: Lexical Scope for proper usage patterns.

¥Examples

¥Invalid

// Arrow function assigned without wrapping it in $(...)
const handleClick = () => {
console.log("clicked");
};
code-block.js:2:21 lint/nursery/useQwikValidLexicalScope ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Non-serializable expression must be wrapped with $(…)

1 │ // Arrow function assigned without wrapping it in $(…)
> 2 │ const handleClick = () => {
^^^^^^^
> 3 │ console.log(“clicked”);
> 4 │ };
^
5 │

Qwik requires serializable closures for:
- Resumability (pausing/resuming execution)
- Code splitting (lazy loading components)
- Optimized rehydration (client-side continuation)

Wrap the expression with $(…) to make it serializable. Learn more: Qwik documentation.

¥Valid

const handleClick = $(() => {
// Valid: only using serializable variables or props
console.log("clicked");
});

¥Related links