Agent skill

Riverpod Infinite Rebuild Loop

by divinevideo in divinevideo/divine-mobile

Debug and fix infinite widget rebuild loops in Flutter apps using Riverpod state management.

MPL-2.0Auto-check passedMobile

Install Riverpod Infinite Rebuild Loop

skills CLI
$ npx skills add divinevideo/divine-mobile --skill riverpod-infinite-rebuild-loop -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install divinevideo/divine-mobile riverpod-infinite-rebuild-loop --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/divinevideo/divine-mobile.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/riverpod-infinite-rebuild-loop .claude/skills/riverpod-infinite-rebuild-loop && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
riverpod-infinite-rebuild-loop
GitHub stars
266
Token cost
~1.8k tokens
SKILL.md length
313 words
Files
1
Skills in repo
103
Repo updated
First seen
Licence
MPL-2.0

At a glance

Debug and fix infinite widget rebuild loops in Flutter apps using Riverpod state management.

  • Works in 5 steps: Audit ref.watch() Usage → Convert Unnecessary Watches → Remove Watch + Listener Redundancy → …
  • Logs show RAPID REBUILD warnings
  • SKILL.md covers Problem, Context / Trigger Conditions, Root Cause Analysis and Solution, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Riverpod Infinite Rebuild Loop is an agent skill from divinevideo/divine-mobile. Debug and fix infinite widget rebuild loops in Flutter apps using Riverpod state management. Use when: (1) Logs show "RAPID REBUILD" warnings or 50+ rebuilds in seconds, (2) UI becomes unresponsive or shows same content repeatedly, (3) Bug only affects slower devices or poor network conditions, (4) Provider watching creates circular dependencies with router/URL state. Covers ref.watch() overuse, watch+listener redundancy, and transitive dependency chains.

Its SKILL.md is about 1.8k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Mobile, covering Cross-platform mobile apps and State management. It works with Flutter. The licence is MPL-2.0.

When your agent uses it

  • Logs show RAPID REBUILD warnings
  • 50+ rebuilds in seconds
  • UI becomes unresponsive
  • Shows same content repeatedly

Example prompts

  • “RAPID REBUILD”
  • “/riverpod-infinite-rebuild-loop”

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Audit ref.watch() Usage
  2. Convert Unnecessary Watches
  3. Remove Watch + Listener Redundancy
  4. Break URL Update Loops
  5. Batch Initial Load

What it can do on your machine

Read from SKILL.md and the folder at commit c3d6f7e. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are dart).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • riverpod.dev
    • docs.flutter.dev

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Riverpod Infinite Rebuild Loop loads about 1.8k tokens when it runs. Until then it costs about 123 tokens; SKILL.md has 313 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~123
When it runs · the whole SKILL.md, loaded when a task matches
~1.8k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from divinevideo/divine-mobile at commit c3d6f7e, republished under its MPL-2.0 licence (© divinevideo). 313 words, ~1,823 tokens.

Download SKILL.mdSave it as .claude/skills/riverpod-infinite-rebuild-loop/SKILL.md (or your agent's skills folder).
name
riverpod-infinite-rebuild-loop
description
Debug and fix infinite widget rebuild loops in Flutter apps using Riverpod state management. Use when: (1) Logs show "RAPID REBUILD" warnings or 50+ rebuilds in seconds, (2) UI becomes unresponsive or shows same content repeatedly, (3) Bug only affects slower devices or poor network conditions, (4) Provider watching creates circular dependencies with router/URL state. Covers ref.watch() overuse, watch+listener redundancy, and transitive dependency chains.
author
Claude Code
version
1.0.0
date
2026-02-02

Riverpod Infinite Rebuild Loop

Problem

Flutter widgets using Riverpod enter an infinite rebuild loop, causing:

  • 50+ widget rebuilds in seconds
  • UI becomes unresponsive
  • Same content rendered repeatedly
  • Bug manifests primarily on slower devices or poor network connections

Context / Trigger Conditions

Symptoms in logs:

⚠️ RAPID REBUILD #54! Only 15ms since last build
⚠️ RAPID REBUILD DETECTED! Only 6ms since last build

User-reported symptoms:

  • "Endless scroll loop" - same video/content keeps appearing
  • "App freezes" or becomes unresponsive
  • "Works on my phone but not on older devices"

Trigger scenarios:

  1. Multiple async providers completing at staggered times
  2. Provider that watches route/URL state AND updates URL in build
  3. Using ref.watch() AND adding manual listeners to same provider
  4. Transitive watches: Widget watches A, A watches B, Widget also watches B

Root Cause Analysis

Pattern 1: URL Update Feedback Loop
dart
// BAD: Creates infinite loop
Widget build(BuildContext context) {
  final pageContext = ref.watch(pageContextProvider);  // Watches URL
  final videos = ref.watch(videosProvider);

  // Detect video moved position and "silently" update URL
  if (currentVideoIndex != urlIndex) {
    context.go('/home/$currentVideoIndex');  // URL change triggers rebuild!
  }
}

Loop: Videos reorder → URL updated → pageContextProvider emits → rebuild → videos may reorder again → repeat

Pattern 2: Watch + Listener Redundancy
dart
// BAD: Double-subscribing causes double rebuilds
final cache = ref.watch(cacheProvider);  // Watch triggers rebuild
cache.addListener(onCacheChanged);        // Listener ALSO triggers action
Pattern 3: Transitive Watch Dependencies
dart
// BAD: Double-watching same source
Widget build() {
  ref.watch(pageContextProvider);           // Watch #1
  ref.watch(derivedProvider);               // derivedProvider ALSO watches pageContextProvider!
}
Pattern 4: Staggered Async Provider Loading
dart
// PROBLEMATIC on slow devices: Each watch triggers rebuild when provider completes
final a = ref.watch(asyncProviderA);  // Completes at T=100ms → rebuild
final b = ref.watch(asyncProviderB);  // Completes at T=200ms → rebuild
final c = ref.watch(asyncProviderC);  // Completes at T=350ms → rebuild
final d = ref.watch(asyncProviderD);  // Completes at T=500ms → rebuild
// On fast devices: all complete ~simultaneously, 1-2 rebuilds
// On slow devices: staggered completion, 4+ rebuilds

Solution

Step 1: Audit ref.watch() Usage

For each ref.watch() in build methods, ask:

  • Does this provider change frequently?
  • Do I need to REBUILD when it changes, or just REACT?
  • Am I also manually listening to this provider?

Riverpod Methods:

MethodBehavior
ref.watch()Subscribe + REBUILD on change
ref.read()Read once, NO rebuild
ref.listen()Subscribe + callback, NO rebuild
Step 2: Convert Unnecessary Watches
dart
// BEFORE: Rebuilds on every change
final videoService = ref.watch(videoServiceProvider);

// AFTER: Read once, use listener for reactions
final videoService = ref.read(videoServiceProvider);
ref.listen(videoServiceProvider, (prev, next) {
  // React to changes without rebuilding
  if (next.hasNewVideos) refreshUI();
});
Step 3: Remove Watch + Listener Redundancy
dart
// BEFORE: Double-subscription
final cache = ref.watch(cacheProvider);
cache.addListener(onCacheChanged);

// AFTER: Choose one approach
// Option A: Just watch (if rebuild is needed)
final cache = ref.watch(cacheProvider);

// Option B: Read + listen (if rebuild not needed)
final cache = ref.read(cacheProvider);
ref.listen(cacheProvider, (_, __) => onCacheChanged());
Step 4: Break URL Update Loops
dart
// BEFORE: URL update in build causes loop
if (currentVideoIndex != urlIndex) {
  context.go('/home/$currentVideoIndex');
}

// AFTER: Don't update URL on content reorder
// Just track position with PageController, not URL
// OR use content ID in URL instead of index: /home/video/abc123
Step 5: Batch Initial Load
dart
// BEFORE: Watch each async provider (N rebuilds on slow devices)
final a = ref.watch(asyncA);
final b = ref.watch(asyncB);

// AFTER: Create combined provider that waits for all
@riverpod
Future<CombinedState> combinedState(Ref ref) async {
  final a = await ref.watch(asyncA.future);
  final b = await ref.watch(asyncB.future);
  return CombinedState(a, b);
}
// Widget watches only the combined provider (1 rebuild)

Verification

After fixes:

  1. Run app on slow device or use network throttling
  2. Check logs for rebuild warnings - should see ≤5 rebuilds on startup
  3. Scroll/navigate and verify UI remains responsive
  4. No "RAPID REBUILD" warnings in logs

Example: Full Fix

Before (problematic):

dart
class _HomeScreenState extends ConsumerState<HomeScreen> {
  @override
  Widget build(BuildContext context) {
    final pageContext = ref.watch(pageContextProvider);
    final videos = ref.watch(videosProvider);  // Also watches pageContextProvider internally!

    // URL update loop
    if (videos.currentIndex != pageContext.index) {
      WidgetsBinding.instance.addPostFrameCallback((_) {
        context.go('/home/${videos.currentIndex}');
      });
    }

    return PageView(...);
  }
}

After (fixed):

dart
class _HomeScreenState extends ConsumerState<HomeScreen> {
  @override
  Widget build(BuildContext context) {
    // Only watch videos, read page context
    final pageContext = ref.read(pageContextProvider).requireValue;
    final videos = ref.watch(videosProvider);

    // Don't update URL on reorder - track with PageController only
    // URL only changes on explicit user navigation

    return PageView(...);
  }
}

Notes

  • This bug is timing-dependent - may not reproduce on fast devices
  • Test on physical devices with network throttling to catch issues
  • Add rebuild detection logging during development:
    dart
    static int _buildCount = 0;
    static DateTime? _lastBuild;
    
    @override
    Widget build(BuildContext context) {
      final now = DateTime.now();
      if (_lastBuild != null && now.difference(_lastBuild!).inMilliseconds < 100) {
        Log.warning('RAPID REBUILD #${++_buildCount}!');
      }
      _lastBuild = now;
      // ...
    }

References

© divinevideo, MPL-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/riverpod-infinite-rebuild-loop of divinevideo/divine-mobile.

Open the folder on GitHubat commit c3d6f7e

Compare with similar skills

Riverpod Infinite Rebuild Loop next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Riverpod Infinite Rebuild Loop compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Riverpod Infinite Rebuild Loop this skilldivinevideo/divine-mobile266—~1.8kAutomated safety check: PassMPL-2.0
Cue AnimationsMilad-Akarie/cue1191 repos~6.6kAutomated safety check: PassMIT
Flutter Riverpod State Managementandrewyng/context-hub14k—~1.1kAutomated safety check: PassMIT
BlocVeryGoodOpenSource/vgv-ai-flutter-plugin170—~2kAutomated safety check: PassMIT
Flutter Dart Code Reviewaffaan-m/ECC276k2 repos~5.8kAutomated safety check: NotesMIT
Signals for Flutterrodydavis/signals.dart819—~1.9kAutomated safety check: PassApache-2.0

Similar skills

  • Cue Animations

    Milad-Akarie/cue

    Flutter animation using the Cue package. An agent skill from Milad-Akarie/cue.

    119 GitHub starsUsed in 1 repo~6.6k tokens
    MobileAuto-check passed
  • Guides Flutter state management with Riverpod: choosing provider types, wiring ConsumerWidgets, handling async state and lifecycle, and overriding providers in tests.

    14k GitHub stars~1.1k tokensUpdated 4 mo ago
    MobileAuto-check passed
  • Bloc

    VeryGoodOpenSource/vgv-ai-flutter-plugin

    Best practices for Bloc state management in Flutter/Dart, covering Cubit versus Bloc, event and state naming, sealed classes with Equatable, the Page/View split with BlocProvider, BlocBuilder…

    170 GitHub stars~2k tokensUpdated 4 days ago
    MobileAuto-check passed
  • Library-agnostic Flutter/Dart code review checklist covering widget best practices, state management patterns (BLoC, Riverpod, Provider, GetX, MobX, Signals), Dart idioms, performance…

    276k GitHub starsUsed in 2 repos~5.8k tokens
    MobileAuto-check: notes
  • Signals for Flutter

    rodydavis/signals.dart

    Reference for the signals_flutter package: reactive signals, computed values, effects, async signals and collection signals bound to Flutter widgets.

    819 GitHub stars~1.9k tokensUpdated 26 days ago
    MobileAuto-check passed
  • Mobile Development

    rohitg00/awesome-claude-code-toolkit

    Mobile development patterns for React Native and Flutter including navigation, state management, and responsive design

    2.7k GitHub stars~1.5k tokensUpdated 5 mo ago
    MobileAuto-check passed

More from divinevideo/divine-mobile

All 103 skills in this repo
  • Fix ArgoCD ExternalSecret deployment failing with "namespace X is not permitted in project Y".

    266 GitHub stars~931 tokensUpdated today
    Auto-check passed
  • Art Direct

    divinevideo/divine-mobile

    Art direction for any content — reads text, PDF, Word, HTML, PPT, then proposes 2-3 creative directions with photography style, mood, and visual language.

    266 GitHub stars~4.8k tokensUpdated today
    Auto-check passed
  • Async Await Null Race Condition

    divinevideo/divine-mobile

    Fix "Null check operator used on a null value" errors when an object is set to null during an async await.

    266 GitHub stars~881 tokensUpdated today
    Auto-check passed
  • AWS V4 Signing Custom Headers Gcs

    divinevideo/divine-mobile

    Add custom metadata headers (x-amz-meta-) to AWS v4 signed requests for GCS S3-compatible API.

    266 GitHub stars~1k tokensUpdated today
    Auto-check passed
  • Bash Herestring Newline Secrets

    divinevideo/divine-mobile

    Fix password/secret authentication failures caused by trailing newlines when creating Google Cloud secrets (or similar) with bash here-strings.

    266 GitHub stars~791 tokensUpdated today
    Auto-check passed
  • Fix silent video/media processing failures caused by URL extraction code that filters on file extensions (.mp4, .webm, .webp).

    266 GitHub stars~1.1k tokensUpdated today
    Auto-check passed

Works with

Questions about Riverpod Infinite Rebuild Loop

What does Riverpod Infinite Rebuild Loop do?

Debug and fix infinite widget rebuild loops in Flutter apps using Riverpod state management. Riverpod Infinite Rebuild Loop is an agent skill from divinevideo/divine-mobile. Debug and fix infinite widget rebuild loops in Flutter apps using Riverpod state management.

When should I use Riverpod Infinite Rebuild Loop?

Riverpod Infinite Rebuild Loop fits situations like: logs show RAPID REBUILD warnings; 50+ rebuilds in seconds; UI becomes unresponsive; shows same content repeatedly.

How do I install Riverpod Infinite Rebuild Loop in Claude Code?

Run `npx skills add divinevideo/divine-mobile --skill riverpod-infinite-rebuild-loop -a claude-code`. Or copy the skill folder (.agents/skills/riverpod-infinite-rebuild-loop in divinevideo/divine-mobile) into .claude/skills/riverpod-infinite-rebuild-loop in your project. Claude Code loads it when a task matches its description.

How do I install Riverpod Infinite Rebuild Loop in Codex?

Run `npx skills add divinevideo/divine-mobile --skill riverpod-infinite-rebuild-loop -a codex`. Or copy the skill folder (.agents/skills/riverpod-infinite-rebuild-loop in divinevideo/divine-mobile) into .agents/skills/riverpod-infinite-rebuild-loop in your project. Codex loads it when a task matches its description.

Can I use Riverpod Infinite Rebuild Loop in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add divinevideo/divine-mobile --skill riverpod-infinite-rebuild-loop -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/riverpod-infinite-rebuild-loop, .gemini/skills/riverpod-infinite-rebuild-loop, .github/skills/riverpod-infinite-rebuild-loop and .opencode/skills/riverpod-infinite-rebuild-loop in your project.

What does Riverpod Infinite Rebuild Loop need to run?

SKILL.md names no scripts, command-line tools or credentials: Riverpod Infinite Rebuild Loop is instructions for the agent only.

Does Riverpod Infinite Rebuild Loop access the network?

SKILL.md names 2 domains. As links in the text: riverpod.dev and docs.flutter.dev. This is read from the text; nothing was executed.

Is Riverpod Infinite Rebuild Loop safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Riverpod Infinite Rebuild Loop use?

Riverpod Infinite Rebuild Loop is published under the MPL-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Riverpod Infinite Rebuild Loop use?

About 1.8k tokens (SKILL.md is roughly 7.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Riverpod Infinite Rebuild Loop?

Skills that share tags, products or a category with Riverpod Infinite Rebuild Loop: Cue Animations (Milad-Akarie/cue, 119 stars), Flutter Riverpod State Management (andrewyng/context-hub, 14k stars), Bloc (VeryGoodOpenSource/vgv-ai-flutter-plugin, 170 stars) and Flutter Dart Code Review (affaan-m/ECC, 276k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Riverpod Infinite Rebuild Loop?

divinevideo (a GitHub organization) maintains it in divinevideo/divine-mobile, which has 266 GitHub stars. The repository holds 103 skills in this directory. The repository was last updated on October 10, 2026.

Source: divinevideo/divine-mobile on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.