Skip to content
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

ref.onAddListener not triggering for provider.future #2816

Closed
JifScharp opened this issue Aug 15, 2023 · 1 comment · Fixed by #3404
Closed

ref.onAddListener not triggering for provider.future #2816

JifScharp opened this issue Aug 15, 2023 · 1 comment · Fixed by #3404
Assignees
Labels
bug Something isn't working
Milestone

Comments

@JifScharp
Copy link

Describe the bug
I expect ref.watch(provider.future) to trigger the ref.onAddListener. However, it does not appear to be happening. I'm not an expert in Riverpod, so I wasn't sure if watching a future should trigger this, but when debugging I found that listen was still being called?

  @override
  T watch<T>(ProviderListenable<T> listenable) {
    _assertNotOutdated();
    assert(!_debugIsRunningSelector, 'Cannot call ref.watch inside a selector');

    if (listenable is! ProviderBase<T>) {
      final sub = listen<T>(                       <-- was executed
        listenable,
        (prev, value) => _markDependencyChanged(),
        onError: (err, stack) => _markDependencyChanged(),
        onDependencyMayHaveChanged: _markDependencyMayHaveChanged,
      );

      return sub.read(); 
    }

I added ref.watch(provider) without the future, and immediately the callback is triggered.

To Reproduce

  • Create a provider that returns a value
  • Add an onAddListener callback
  • Call the provider using ref.watch(provider.future)
  • onAddListener callback is not called

Expected behavior
onAddListener is called

@rrousselGit
Copy link
Owner

This appears to have been fixed by the recent selectAsync fix. I've added regression tests for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants