Qwik Cursor Rules: Resumability and Lazy Loading Guide

Qwik cursor rules and best practices for resumability, lazy loading, fine-grained reactivity, QwikCity routing, and performance-focused components to build fast, maintainable frontends.

November 14, 2025
qwikcursor-rulesfrontendresumabilityqwikcity

Overview

Professional cursor rules for Qwik that emphasize resumability, lazy loading, and fine-grained reactivity. These rules help AI assistants generate clean, fast, and maintainable Qwik code with proper server/client boundaries and efficient routing.

Note:

Optimizes resumability, progressive loading, and QwikCity routing with context-aware code generation aligned to modern Qwik best practices.

Rules Configuration

.cursor/rules/qwik.mdc

---
description: Enforces best practices for Qwik development, focusing on resumability, component architecture, and optimization patterns. Provides comprehensive guidelines for writing clean, efficient, and maintainable Qwik applications.
globs: **/*.{tsx,jsx,ts,js}
---

# Qwik Best Practices

You are an expert in Qwik development and related technologies.
You understand Qwik's unique architecture focused on resumability, lazy loading, and fine-grained reactivity.

### Resumability-Aware Development
- Leverage Qwik's resumability model instead of traditional hydration
- Use server and client boundaries with the $ suffix
- Implement efficient lazy loading with component$, useTask$, and useVisibleTask$
- Optimize for progressive enhancement and partial hydration
- Handle serialization boundaries between server and client

### Component Architecture
- Follow Qwik component patterns with component$ for optimal code-splitting
- Implement proper signal management with useSignal and useStore
- Use resource loaders (routeLoader$, useResource$) for data fetching
- Implement proper route handling with QwikCity
- Use proper event handling with $ suffix for optimal bundling

### Optimization Patterns
- Implement proper lazy loading strategies
- Use fine-grained reactivity for optimal performance
- Implement proper server/client boundary management
- Optimize bundle size with proper code splitting
- Use proper prefetching strategies

### State Management
- Use useSignal for simple reactive state
- Implement useStore for complex state objects
- Use createContextId and useContextProvider for global state
- Implement proper state serialization for resumability
- Use proper state initialization patterns

### Routing and Data Fetching
- Use QwikCity for routing and layouts
- Implement routeLoader$ for server-side data fetching
- Use useResource$ for client-side data fetching
- Implement proper error handling and loading states
- Use proper route parameters and navigation

### Testing and Quality
- Write unit tests with proper component mocking
- Implement E2E tests with Playwright
- Use proper test utilities for Qwik components
- Implement proper error boundaries
- Maintain high test coverage for core business logic

### Examples

```tsx
// Proper component definition with resumability
export const Counter = component$(() => {
  const count = useSignal(0);

  useTask$(({ track }) => {
    track(() => count.value);
    console.log('Count changed:', count.value);
  });

  return (
    <div>
      <span>Count: {count.value}</span>
      <button onClick$={() => count.value++}>Increment</button>
    </div>
  );
});

// Proper data fetching with resource loaders
export const useProductData = routeLoader$(async () => {
  const products = await fetchProducts();
  return {
    products,
    categories: await fetchCategories()
  };
});

// Proper client-side resource usage
export const ProductList = component$(() => {
  const products = useResource$(async () => {
    const response = await fetch('/api/products');
    return response.json();
  });

  return (
    <Resource
      value={products}
      onPending={() => <div>Loading...</div>}
      onRejected={(error) => <div>Error: {error.message}</div>}
      onResolved={(data) => (
        <ul>
          {data.map(product => (
            <li key={product.id}>{product.name}</li>
          ))}
        </ul>
      )}
    />
  );
});

Key Features

⏯️

Resumability First

Avoid hydration; resume execution exactly where needed

🧩

Lazy Loading

Load components and tasks on demand to reduce bundle size

📶

Fine-Grained Reactivity

Use signals and stores for precise updates with minimal work

🛣️

QwikCity Routing

Use layouts, route loaders, and prefetch for smooth navigation

🔗

Serialization Boundaries

Keep server/client context clear for predictable behavior

🧪

Testing Ready

Validate resumability, routing, and async resource patterns

Installation

1

Choose Your IDE

Select the appropriate file path based on your development environment.

2

Create the Rules File

Create the cursor rules file in your project:

Create file: .cursor/rules/qwik.mdc

3

Add the Rules Configuration

Copy the rules configuration above into your newly created file.

4

Start Building

Your AI assistant now follows Qwik best practices automatically.

Use Cases

Interactive Applications

Highly interactive UIs with minimal JavaScript and fast startup

E-commerce

Prefetch routes, lazy load non-critical UI, and optimize conversion

Content Sites

Progressive enhancement with fast navigation and clear structure

Design Systems

Reusable components with signals, stores, and controlled reactivity

Best Practices

Architecture

  • Keep server/client boundaries explicit with the $ suffix
  • Prefer lazy loading for components and resource-heavy tasks
  • Use route loaders for predictable data access and caching

Content Strategy

  • Write descriptive alt text for images
  • Keep paragraphs short and use active voice
  • Avoid superlatives; use friendly, authoritative tone