Riverpod vs Juice
1. Family snapshot
Versions read (2026-09-16): riverpod 3.4.3 (pub.dev, 2026-09-04; CHANGELOG top ## 3.4.3 - 2026-09-04), riverpod_generator 4.0.9, riverpod_lint 3.1.9, riverpod_devtools 1.1.2 (third-party, github.com/yutsuki3/riverpod_devtools). Docs: https://riverpod.dev/docs/whats_new, /docs/concepts2/{providers,family,auto_dispose,retry,mutations,offline,observers,overrides}, /docs/how_to/{select,testing,cancel,pull_to_refresh}. Source: github.com/rrousselGit/riverpod/packages/riverpod/lib/src/core/{element,scheduler,ref,async_value,mutations,persist,provider_container,modifiers/select}.dart. Juice: /Users/kevinehmka/dev/juice (juice 1.7.2).
Philosophy. Riverpod models state as a graph of memoized functions (“providers”): a body calls ref.watch(other), the container records the edge, upstream change re-runs the body and re-notifies downstream. Caching, disposal, retry, persistence and side-effect status all hang off that node. Remi’s stated aims: compile-safety over BuildContext lookup, declarative caching, and 3.x’s simplification (one Ref, one Notifier, legacy providers to legacy.dart). Juice is the opposite topology — no auto-tracked graph, one bloc per domain, one use case per event, explicit named groups — so the honest question per mechanism is whether its value survives translation into events/use cases/groups/seams.
2. Mechanism catalog
ref.watch dependency graph + scheduled rebuilds
- What it does: a provider or widget declares data dependencies by reading; upstream change re-executes it.
- How it works:
ProviderElementkeepssubscriptions(what I watch) anddependents(who watches me);ref.watchislisten()whose callback calls_invalidateSelf(asReload: true). Invalidation sets_mustRecomputeStateand hands the element toProviderScheduler.scheduleProviderRefresh, which batches into one task — end of frame under a Flutter vsync,Timer(Duration.zero)otherwise. After rebuild,updateShouldNotify(previous != nextfor every provider in 3.x) gates notification. 3.x also mints a newRefper rebuild, pauses the element’s subscriptions during the rebuild, and pauses a provider when all its listeners are paused (TickerMode-invisible widgets). - Juice today:
lacks(by design). Cross-bloc reaction is explicit —StateRelay/StatusRelay/EventSubscription(use_case_builders/src/{state_relay,event_subscription}.dart) lease the source bloc and turn its stream into an event; widgets subscribe by group intersection (ui/src/widget_support.dart::denyRebuild). - Gap value: Low. The graph’s value (never forgetting a consumer) is delivered by groups + relays with a name on every edge.
- Adoption sketch: not the graph — the frame batching. Juice rebuilds per emission (
StatusEmitter._emit→ stream →JuiceAsyncBuilder→ValueNotifier), so a multi-emit use case (AGENTS gotcha 4) rebuilds N times in one frame. A builder-level “one rebuild per frame” coalescer: core, M. - Doctrine fit: graph conflicts (relays not listeners); frame coalescing fits (rendering detail, no knob).
select / selectAsync
- What it does: rebuild only when a projection of the value changes.
- How it works:
provider.select(fn)returns a_ProviderSelector(ProviderListenable); on each upstream notification it re-runsfn, wraps a throwing selector as$Result.error, and notifies only iflastSelectedValue.value != newSelectedValue.value(the==operator; the selected value must be immutable).selectAsyncdoes the same overAsyncValueand returns aFuture. The how_to opens with “benchmark first”. - Juice today:
has-under-another-name (JuiceSelector / JuiceSelectorWith / bloc.select())—state_selector.dart, identical semantics (==or customequals). ROADMAP “teed up #2” already positions it: groups canonical, select a leaf optimisation, gated on a measured storm. - Gap value: Low. Adoption sketch: nothing new. Doctrine fit: fits (already resolved).
autoDispose + keepAlive links, onCancel/onResume
- What it does: state dies when unused; per-instance opt-out; time-boxed caches.
- How it works:
mayNeedDispose()schedules disposal when!isActive && (links == null || links.isEmpty); last listener removed →onCancel→ wait one frame (await null) → dispose if still unused.ref.keepAlive()pushes aKeepAliveLinkonto_keepAliveLinks;close()removes it and re-callsmayNeedDispose()when the list empties — henceTimer(duration, link.close)is the canonical “cache for 5 minutes”. A rebuild clears links. Weak listeners (weak: true) don’t count towardisActive. Codegen defaults to autoDispose;@Riverpod(keepAlive: true)opts out;prefer_keep_alive_annotationflags a fire-and-forget first-statementkeepAlive(). - Juice today:
has-under-another-name (BlocLifecycle.leased + BlocLease)—bloc_scope.dart::_releaseLeasecloses whenleaseCount <= 0, immediately, pluspermanent/feature(FeatureScope + CleanupBarrier) which Riverpod lacks.partial: no linger window — a leased bloc closes on the last release, so back-navigation rebuilds cold and a route transition can dispose/re-create in one frame. - Gap value: Med for navigation-heavy apps.
- Adoption sketch:
BlocScope.register(..., lifecycle: .leased, linger: Duration): last release starts a timer, a newlease()inside the window cancels it, logslease_linger/lease_linger_expired; throws iflingeris given with a non-leased lifecycle. Core, S. - Doctrine fit: needs a knob (
linger) — one purpose, on the existing registration, not a new mode.
AsyncValue (isRefreshing/isReloading, copyWithPrevious, guard, progress)
- What it does: one sealed value carrying data/loading/error simultaneously, so the UI can show stale data under a spinner or an error over data.
- How it works:
AsyncData/AsyncLoading/AsyncErrorshare private_value/_error/_loadingslots. On rebuild the element callscopyWithPrevious(previous, isRefresh:): manualinvalidate/refreshkeeps the old value (isRefreshing = _hasState && isLoading && this is! AsyncLoading); aref.watch-driven rebuild re-tags itDataSource.reload(isReloading = … && this is AsyncLoading).unwrapPrevious()strips history;guard(fn, [test])converts a throwing future to data/error and rethrows whattestrejects; 3.x addsprogress(0–1) and seals the class for exhaustiveswitch. - Juice today:
has-under-another-name (StreamStatus + EntityStatuses). Every status carriesstateandoldState(stream_status.dart), soWaitingStatusnever loses data;FailureStatuscarrieserror/errorStackTracebeside state. Per-row:EntityStatuses.statusOf(k).when(idle|waiting|failure)withguardEntityas theguardanalogue.partial: noprogress; first-load vs refresh is inferred from state (items.isEmpty), not carried. - Gap value: Low–Med (
progressis real for juice_llm model acquire and juice_media upload). - Adoption sketch:
emitWaiting(progress: double?)→WaitingStatus.progress. Core, S. - Doctrine fit: fits.
Families
- What it does: one definition, one cache entry per argument.
- How it works: arguments join the provider identity via
==/hashCode(“Parameters passed need to have a consistent==/hashCode”;provider_parameterslint enforces it). Codegen turns any parameter list (named, optional, generics in 3.x) into a family; docs advise autoDispose on families to stop per-argument leaks. - Juice today:
has-under-another-name (BlocScope scope key + dynamic groups)—BlocId(T, scope)keys instances;FooGroups.item(id)/FormsGroups.field('email')give per-key rebuilds;EntityStatuses<K>per-key status.partial: no equality lint on scope keys. - Gap value: Low. Adoption sketch:
juice_scope_key_equalitylint (key type overrides==or is primitive/enum). juice_lint, S. Doctrine fit: fits.
Dependency overrides for hermetic tests
- What it does: replace any provider’s body per container/scope.
- How it works:
ProviderContainer(overrides: [p.overrideWith | overrideWithValue | overrideWithBuild]); aProviderPointerManagermaps provider→override in O(1) (orphanPointers/familyPointers); child containers fork the parent’s pointers so an overridden provider mounts in the overriding scope.ProviderContainer.test()addsaddTearDown(dispose);tester.container()reaches it in widget tests;container.listenkeeps autoDispose providers alive. - Juice today:
has-under-another-name (seam injection + BlocScope.reset)— fakes enter via config (FooConfig(source: FakeSource())), tests are headless;BlocScope.reset()is@visibleForTesting(bloc_scope.dart:521).partial: no “override only the read” and no scoped override in a widget tree. - Gap value: Low. Adoption sketch: none needed; a
BlocTester.withScopehelper pairing register+reset inaddTearDownwould be S ergonomics. Doctrine fit: fits.
ProviderObserver
- How it works: a list on the container concatenated with the parent’s; the element invokes
didAddProvider/didUpdateProvider/didDisposeProvider/providerDidFailplus 3.xmutationStart/Success/Error/Resetwith aProviderObserverContext. Third-party DevTools registers as an observer. - Juice today:
has (JuiceLogger taxonomy + DevtoolsJuiceLogger)— every emission/execution/lifecycle passes throughJuiceLoggerConfig.loggerwith typedcontext['type']and pairedexecutionIdspans withelapsedMicros; strictly richer. - Gap value: none.
Automatic retry (3.x)
- What it does: a provider whose build throws is re-run on backoff until success or disposal.
- How it works:
ProviderContainer.defaultRetry(retryCount, error, {maxRetries: 10, minDelay: 200ms, maxDelay: 6400ms})returnsnullforProviderException(an upstream’s rethrown error) and anyError, else200ms * 2^ncapped; the element runs_pendingRetryTimer = Timer(duration, () { _retryCount++; invalidateSelf(asReload: false, manual: false); }). Overridable onProviderScope(retry:)or per provider. Documented consequence:await ref.watch(p.future)swallows intermediate failures until retries are exhausted. - Juice today:
has (RetryableUseCaseBuilder + BackoffStrategy)— wraps a use case, interceptsemitFailure, appliesFixed/ExponentialBackoff(jitter, cap), honoursretryOnand cancellation during backoff, emits the final failure; transport retry injuice_network’s idempotency-awareRetryInterceptor. Opt-in per event, not default-on. - Gap value: none. Default-on retry is the silent fallback Juice forbids (spinner hides failures for up to ~13 s).
- Doctrine fit: Juice’s shape is the better fit; do not copy the default.
Offline persistence (3.x, experimental)
- What it does: cache a Notifier’s state to disk and restore it on next build.
- How it works:
Storage<KeyT, EncodedT>hasread/write/delete;PersistedDatawraps value +destroyKey+expireAt. Insidebuild(),persist(storageFuture, key:, encode:, decode:, options: StorageOptions(cacheTime: 2 days default | unsafe_forever, destroyKey:))reads once, deletes on destroy-key mismatch or expiry, setsstate, then listens to itself and writes every change.await persist(...).future; return state.value ?? []makes it cache-first. Official backendriverpod_sqflite(JsonSqFliteStorage,@JsonPersist());Storage.inMemory()for tests; duplicate keys assert. - Juice today:
partial. Substrate exists (juice_storagewith TTLhiveWrite(ttl:)/prefsWrite(ttl:)), but every package hand-rolls its own seam:ThemePersistence,LocalePersistence,SyncStore,AuthProvidersession restore,juice_networkCacheManager. No generic “hydrate this field on init, write it on emit” helper (grep -r persist packages/juice/libhits doc comments only). - Gap value: Med — every new package re-implements load/save + seam + fake; destroy-key migrations are ad hoc.
- Adoption sketch:
StatePersistence<T>seam in core (load/save/clear) +hydrate(field:, apply:, encode:, decode:, ttl:, destroyKey:)onJuiceBlocthat runs one built-in sequentialHydrateEventat init and writes after eachemitUpdatetouching the field. DefaultStorageStatePersistenceinjuice_storage(Hive + TTL + destroyKey),InMemoryStatePersistencefake injuice/testing. Decode failure →emitFailure+ clear the key, never keep stale silently. M. - Doctrine fit: fits (seam + default + fake;
ttlanddestroyKeyeach one purpose; fail loud on decode).
Mutations (3.x, experimental)
- What it does: report pending/error/success of a side effect to the UI without polluting domain state.
- How it works:
final addTodo = Mutation<Todo>()is a top-levelProviderListenable<MutationState>;addTodo.run(ref, (tsx) async { … tsx.get(p.notifier) … })flipsMutationPending → MutationSuccess(value) | MutationError(error, stack); providers read throughtsx.getstay alive for the run. UI:switch (ref.watch(addTodo)) { MutationIdle() … }. Keyed variantsaddTodo(id)give per-item status; state auto-resets to idle when unlistened,reset(ref)manually; observers get mutation callbacks. Marked “may change in a breaking way without a major version bump”. - Juice today:
has-under-another-name (StreamStatus per event + EntityStatuses per key). The event is the mutation:emitWaiting/emitFailure/emitUpdateare its states,status.eventnames which event pulsed,EntityStatuses+guardEntityis the keyed variant with guaranteed cleanup.partial: no success value on the pulse (sendAndWait/sendForResultreturn it to the caller), and a widget asks “is SubmitEvent pending” viastatus is WaitingStatus && status.event is SubmitEvent. - Gap value: Low–Med (one ergonomic read).
- Adoption sketch:
status.isWaitingFor<TEvent>()/status.failureFor<TEvent>()extensions. Core, S. - Doctrine fit: fits (no second status holder; the event stays the unit).
Codegen (@riverpod)
- How it works:
riverpod_generator4.x emits*.g.dartwithxProvider(name configurable inbuild.yaml),_$Xbases for notifiers, generics in 3.x;@Riverpod(keepAlive:, retry:); “entirely optional”. - Juice today:
lacks, deliberately — nobuild_runnerin the family; the canonical five-file shape (AGENTS §2) plus the shipped AI skill bundle (ROADMAP item 6) is the generator. - Gap value: Low. Adoption sketch: none (at most a template script, S). Doctrine fit: the build_runner tax conflicts with “demonstrate in full”; skip.
riverpod_lint + custom_lint
- What it does: 16 rules and 6 assists (wrap with Consumer/ProviderScope, convert widget kinds, functional↔class provider).
- How it works: AST visitors over
custom_lint_builder. Generator-only rules enforce the generated shape (functional_ref,notifier_extends,notifier_build,provider_dependencies,scoped_providers_should_specify_dependencies,avoid_build_context_in_providers,unsupported_provider_value,prefer_keep_alive_annotation,only_use_keep_alive_inside_keep_alive); general rules enforce runtime safety (provider_parameters,avoid_ref_inside_state_dispose,avoid_public_notifier_properties,protected_notifier_properties,async_value_nullable_pattern,missing_provider_scope). README claims “quick fixes”; which rules have them is unverified. - Juice today:
has (juice_lint 0.1.0)—juice_generic_event,juice_mutable_state_field,juice_behavior_in_state,expect_lintfixtures, wired into all five example apps (ROADMAP docket #5); no assists,publish_to: none. - Gap value: Med. AGENTS documents more enforceable gotchas than rules: the
_unsetsentinel for nullablecopyWith,bloc.statesnapshot across anawaitin aconcurrentuse case (“the #1 latent bug”),BlocScope.leaseoutsideinitState, and a builder with no explicitconcurrency(the family just finished making every builder explicit). - Adoption sketch:
juice_explicit_concurrency,juice_stale_state_across_await,juice_nullable_copywith_sentinel,juice_lease_in_build; one assist “wrap in StatelessJuiceWidget”. M. - Doctrine fit: fits — doctrine made mechanical.
DevTools story
- What it does: core ships hooks (
core/devtool.dart,debugTrackProviderCreationjump-to-source); the panel is third-partyriverpod_devtools1.1.2: state inspector with invalidate/refresh from the panel, event log with value diffs, dependency graph from static AST analysis (RiverpodDevToolsRegistry.loadFromJson), per-provider update-rate sparklines, load duration, dispose→re-create churn badges, and an optional MCP server. - Juice today:
has (juice_observability 0.4.0 + extension): Timeline (executions with ms, emissions with groups), Blocs (emission count, last groups, state summary), Problems — live-verified 2026-09-15.partial: no state diff, no rate/churn stats, no send-event-from-panel, no MCP. - Gap value: Med — diffs and group fan-out are the two views that explain a rebuild storm in Juice terms.
- Adoption sketch: per-emission state diff (needs a
diagnostics/toJsonseam onBlocState), a “groups fired × widgets subscribed” view (needs awidget_subscribedtelemetry entry fromJuiceWidgetState/_BlocLeaseHolder), per-bloc emission-rate sparkline.juice_observability+ extension, M. MCP later, L. - Doctrine fit: fits.
Cancellation on dispose / debounce
- How it works:
ref.onDispose(client.close)aborts the request on navigate-away; debounce isawait Future.delayed(500ms); if (didDispose) throw. - Juice today:
has (CancellableEvent + TimeoutSupport, sendCancellable, emitCancel/CancelingStatus);close()must cancel its own work (gotcha 8);restartableis teed up as ROADMAP #3 with emission-fencing. - Gap value: Low. Doctrine fit: fits.
3. Not worth adopting
- Auto-tracked dependency graph — explicit relays/groups are the point; auto edges hide intent.
- Default-on automatic retry — hides failures for up to ~13 s; violates fail-loud. Keep
RetryableUseCaseBuilderopt-in. AsyncValuerefresh/reload flags — only meaningful with a graph;WaitingStatus+ untouched state already preserves data.@riverpodcodegen — build_runner tax against a five-file hand shape the skill bundle teaches.- Top-level
Mutationobjects — the event already is the mutation; a second holder is a parallel path. ProviderObserver— JuiceLogger taxonomy is a superset.- Widget-tree scoped overrides — seams +
BlocScopescope keys cover it without a container hierarchy. weaklisteners / pause-on-invisible — no listener graph to weaken;JuiceAsyncBuilder.pauseexists if needed.
4. Top 5 recommendations
1. Generic state hydration (StatePersistence seam + hydrate) — core + juice_storage, M. Four packages hand-roll load-on-init/save-on-change and each new one will too. Riverpod’s persist() is the right shape to port — key, encode/decode, TTL, destroy-key migration, restore-then-continue — in Juice terms: a seam with a shipped storage default and an in-memory fake, one built-in sequential hydrate event, writes hooked after emits touching the field, decode failures loud. Gate: migrate juice_theme and juice_i18n onto it and delete their bespoke persistence classes; if the diff does not net-delete code, the abstraction is wrong.
2. Four more juice_lint rules (+ one assist) — juice_lint, M. Riverpod puts its runtime contract in the analyzer; Juice’s equivalents are prose. juice_explicit_concurrency codifies the migration just completed, juice_stale_state_across_await targets the documented #1 latent bug, the sentinel and lease rules cover gotcha 6 and the BlocLease contract. Gate: plant each sentinel in notes_app and prove the rule trips (the docket #5 method); publish only after one rule catches something real in Amoli.
3. Leased-bloc linger window — core, S. _releaseLease closes synchronously on the last release, so back-navigation to a leased detail bloc rebuilds cold and a route transition can dispose/re-create in one frame. One duration on the existing register, loud logs on start/expire/reclaim. Gate: a measured case in Amoli (a leased screen re-entered within seconds); no consumer, no knob.
4. DevTools: state diff + group fan-out + emission rate — juice_observability, M. riverpod_devtools explains rebuilds with diffs, churn badges and a graph; Juice can explain them better because every edge is a named group, but the panel shows only last groups and a toString. Gate: build it when the select measurement (teed-up #2) is actually attempted, so the panel meets a real storm.
5. WaitingStatus.progress + typed per-event status reads — core, S. emitWaiting(progress:) for juice_llm downloads and juice_media uploads; status.isWaitingFor<SubmitEvent>() so widgets stop pattern-matching status.event. Gate: juice_llm model acquire is the consumer for progress; the per-event read ships only if an example app’s submit button needs it.
5. Things Juice does better than Riverpod
- Every rebuild edge has a name.
groups.intersection(widget.groups)means a rebuild is explainable by reading two constants; Riverpod needs static analysis plus a DevTools graph to answer “why did this rebuild”. - Concurrency is a declared property of the event (
EventConcurrency.sequential/droppable/concurrent,event_dispatcher.dart), audited explicit across the family. Riverpod has no per-operation concurrency model — aNotifiermethod that awaits is exactly the read-before-await race, and the docs’ answer isref.mountedchecks. - Lifecycles are semantic, not cache eviction:
permanent / feature (FeatureScope + CleanupBarrier with timeout) / leasedvs one autoDispose-with-links; Riverpod has no “this flow ended, tear down its five providers together and await their cleanup”. - Retry is opt-in, visible, cancellable (
retryOn,onRetry, cancel during backoff, final failure emitted); Riverpod’s default hides failures fromawait .futurefor ten attempts. - Telemetry is a superset of the observer: paired execution spans with
executionId/elapsedMicros, emissions with groups,state_emission_skipped, rendered in a shipped first-party extension; Riverpod’s first-party story is hooks only. - Per-item status has guaranteed cleanup (
guardEntityin atry/catch, no stuck spinner); keyed mutations reset only when unlistened. - Testing is headless and stream-asserting (
BlocTester.expectStatusSequence, emittedgroupsToRebuildassertable) with hermeticity from named seams and shipped fakes. - Leak detection is built in (
LeakDetectorwith creation/lease stack traces,FeatureScope.debugCheckLeaks); Riverpod relies on autoDispose defaults and a lint.