Skip to content

Cleanup AutoDispose logic #4064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 15, 2025
Merged

Cleanup AutoDispose logic #4064

merged 4 commits into from
Apr 15, 2025

Conversation

rrousselGit
Copy link
Owner

@rrousselGit rrousselGit commented Apr 15, 2025

Summary by CodeRabbit

  • New Features
    • Provider families now explicitly declare their auto-dispose behavior via an isAutoDispose property.
    • Generated provider families reflect disposal behavior consistently.
  • Bug Fixes
    • Improved interface implementations for provider elements to ensure accurate auto-dispose handling.
  • Refactor
    • Simplified provider and family class hierarchies by removing redundant subclasses and mixins.
    • Unified management of debug source hashes and auto-dispose flags across providers.
  • Tests
    • Updated test providers and assertions to align with explicit auto-dispose behavior.
  • Documentation
    • Revised code examples and documentation to illustrate the new auto-dispose property on provider families.

Copy link

coderabbitai bot commented Apr 15, 2025

Walkthrough

This update introduces a standardized and explicit handling of the isAutoDispose property across the Riverpod codebase, including core framework, provider families, and generated code. The isAutoDispose flag is now a required parameter in provider and family constructors, and is exposed via an overridden getter in all relevant classes. Numerous provider family classes—both in hand-written and code-generated files—now explicitly override isAutoDispose, returning either true or false to indicate their lifecycle behavior. The update also unifies and simplifies the inheritance and element class hierarchies, removes redundant mixins, and centralizes debug hash handling.

Changes

File(s) / Path(s) Change Summary
.../lib/detail.g.dart, .../lib/search.g.dart, .../integration/build_yaml/lib/dependencies.g.dart, .../integration/build_yaml/lib/main.g.dart, .../test/integration/async.g.dart, .../test/integration/dependencies.g.dart, .../test/integration/dependencies2.g.dart, .../test/integration/stream.g.dart, .../test/integration/sync.g.dart, .../lib/src/templates/family.dart, .../test/assists/convert_class_based_provider_to_functional/convert_class_based_provider_to_functional.g.dart, .../test/assists/convert_functional_provider_to_class_based/convert_functional_provider_to_class_based.g.dart, .../test/lints/avoid_build_context_in_providers.g.dart, .../test/lints/avoid_public_notifier_properties.g.dart, .../test/lints/dependencies.g.dart, .../test/lints/protected_notifier_properties.g.dart, .../test/lints/provider_dependencies/provider_dependencies.g.dart, .../test/lints/provider_parameters.g.dart, website/docs/.../main.g.dart, website/docs/.../family.g.dart, website/docs/.../family_class.g.dart, website/docs/.../family_fn.g.dart, website/docs/.../invalidate_family_example/codegen.g.dart, website/docs/.../family/codegen.g.dart, website/docs/.../family/family.g.dart, website/docs/.../why_riverpod/codegen.g.dart, website/docs/.../family_and_dispose/family_and_dispose.g.dart Added explicit isAutoDispose getter overrides to generated and example provider family classes, marking them as auto-disposable or not.
packages/riverpod/lib/src/core/family.dart, packages/riverpod/lib/src/core/foundation.dart, packages/riverpod/lib/src/core/provider/functional_provider.dart, packages/riverpod/lib/src/core/provider/notifier_provider.dart, packages/riverpod/lib/src/core/provider/provider.dart, packages/riverpod/lib/src/core/override_with_value.dart, packages/riverpod/lib/src/core/scheduler.dart, packages/riverpod/lib/src/providers/async_notifier.dart, packages/riverpod/lib/src/providers/async_notifier/auto_dispose.dart, packages/riverpod/lib/src/providers/async_notifier/auto_dispose_family.dart, packages/riverpod/lib/src/providers/async_notifier/family.dart, packages/riverpod/lib/src/providers/async_notifier/orphan.dart, packages/riverpod/lib/src/providers/future_provider.dart, packages/riverpod/lib/src/providers/legacy/change_notifier_provider.dart, packages/riverpod/lib/src/providers/legacy/state_notifier_provider.dart, packages/riverpod/lib/src/providers/legacy/state_provider.dart, packages/riverpod/lib/src/providers/notifier.dart, packages/riverpod/lib/src/providers/notifier/auto_dispose.dart, packages/riverpod/lib/src/providers/notifier/auto_dispose_family.dart, packages/riverpod/lib/src/providers/notifier/family.dart, packages/riverpod/lib/src/providers/notifier/orphan.dart, packages/riverpod/lib/src/providers/provider.dart, packages/riverpod/lib/src/providers/stream_notifier.dart, packages/riverpod/lib/src/providers/stream_notifier/auto_dispose.dart, packages/riverpod/lib/src/providers/stream_notifier/auto_dispose_family.dart, packages/riverpod/lib/src/providers/stream_notifier/family.dart, packages/riverpod/lib/src/providers/stream_notifier/orphan.dart, packages/riverpod/lib/src/providers/stream_provider.dart Refactored provider and family base classes to require and propagate the isAutoDispose flag, unified debug hash handling, simplified inheritance, and replaced element subclasses with type aliases where possible.
packages/riverpod/lib/src/core/element.dart Consolidated auto-dispose and keep-alive logic into ProviderElementBase, removed AutoDisposeProviderElementMixin, and integrated deprecated maintainState property.
packages/riverpod/lib/src/experiments/providers.dart Removed AutoDisposeProviderElementMixin from experimental providers, added explicit isAutoDispose tracking and getter overrides.
packages/riverpod/lib/src/riverpod_without_legacy.dart Made previously hidden exports (AutoDisposeProviderElementMixin, AutoDisposeNotifierFamilyBase, AutoDisposeFamilyBase) public.
packages/riverpod/test/old/framework/provider_container_test.dart, packages/riverpod_generator/test/hash_test.dart Updated tests to use precise matchers and removed null assertions with debug hash checks.
packages/riverpod/test/src/experiments/provider.dart Added isAutoDispose getter overrides to test providers.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ProviderFamily
    participant ProviderInstance

    User->>ProviderFamily: Request provider instance with argument
    ProviderFamily->>ProviderInstance: Create instance (passes isAutoDispose flag)
    ProviderInstance->>ProviderInstance: Exposes isAutoDispose getter
    User->>ProviderInstance: Reads isAutoDispose property
Loading

Possibly related PRs

  • rrousselGit/riverpod#4037: Refactors and moves the legacy ChangeNotifierProvider implementation, updating base classes and constructors to unify isAutoDispose handling, which aligns with the main PR's focus on explicit isAutoDispose overrides and propagation in provider families.

Poem

Hopping through code, a rabbit declares,
"Dispose when you must, if the flag says it cares!
Now every provider, both family and friend,
Knows when to linger, and when to end.
With isAutoDispose, the rules are quite clear,
Less memory clutter, more Riverpod cheer!
🥕✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4076592 and cc83d5d.

📒 Files selected for processing (1)
  • packages/riverpod_generator/test/auto_dispose_test.dart (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: build (master, packages/flutter_riverpod)
  • GitHub Check: build (master, packages/hooks_riverpod/example)
  • GitHub Check: build (master, packages/riverpod_generator/integration/build_yaml)
  • GitHub Check: build (master, examples/marvel)
  • GitHub Check: build (master, examples/random_number)
  • GitHub Check: build (master, packages/flutter_riverpod/example)
  • GitHub Check: build (stable, packages/hooks_riverpod/example)
  • GitHub Check: build (master, examples/counter)
  • GitHub Check: build (master, examples/stackoverflow)
  • GitHub Check: build (stable, packages/riverpod/example)
  • GitHub Check: build (stable, packages/hooks_riverpod)
  • GitHub Check: build (stable, examples/todos)
  • GitHub Check: build (stable, examples/counter)
  • GitHub Check: riverpod_lint (stable, packages/riverpod_lint_flutter_test)
  • GitHub Check: riverpod_lint (master, packages/riverpod_analyzer_utils)
  • GitHub Check: riverpod_lint (stable, packages/riverpod_analyzer_utils_tests)
  • GitHub Check: riverpod_lint (master, packages/riverpod_analyzer_utils_tests)
  • GitHub Check: riverpod_lint (master, packages/riverpod_lint_flutter_test)
  • GitHub Check: check_generation
🔇 Additional comments (1)
packages/riverpod_generator/test/auto_dispose_test.dart (1)

12-12: Test simplified to directly check the isAutoDispose property

Great simplification! This change makes the test more direct and clearer by checking the isAutoDispose property instead of relying on implementation details like element runtime types. This aligns well with the broader refactoring to standardize auto-dispose handling across the codebase.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rrousselGit rrousselGit merged commit 61beeb2 into master Apr 15, 2025
44 of 45 checks passed
@rrousselGit rrousselGit deleted the autodispose branch April 15, 2025 20:22
@coderabbitai coderabbitai bot mentioned this pull request Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant