Skip to content

watch onInvalidate callback is triggered many times #5151

@edikdeisling

Description

@edikdeisling

Version

3.2.26

Reproduction link

sfc.vuejs.org/

Steps to reproduce

  1. Click on button multiple times
  2. Watch the console output

What is expected?

Callback that we pass to onInvalidate calls only once. In reproduction repo I expect that abort would be called the same times as fetch

const count = ref(0);

watch(count, (value, oldValue, onInvalidate) => {
  if (value > 2) {
    return;
  }
  
  const controller = new AbortController();
  
  // fetch would be called only 2 times
  console.log('fetch!');
  fetch('/test', { signal: controller.signal });

  onInvalidate(() => {
    // but onInvalidate would be calld every time watch triggers
    console.log('aborted!');
    controller.abort();
  });
});

What is actually happening?

Callback that we pass to onInvalidate is called multiple times

In the screenshot fetch was called 2 times, but abort was called 18 times
image


There is enchancement issue that would fix this behaviour, I think.
#3341

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions