Skip to content

fix(reactivity): allow async watchEffect callbacks#14656

Closed
Misrilal-Sah wants to merge 1 commit intovuejs:mainfrom
Misrilal-Sah:fix-14249-watchEffect-async
Closed

fix(reactivity): allow async watchEffect callbacks#14656
Misrilal-Sah wants to merge 1 commit intovuejs:mainfrom
Misrilal-Sah:fix-14249-watchEffect-async

Conversation

@Misrilal-Sah
Copy link
Copy Markdown

@Misrilal-Sah Misrilal-Sah commented Mar 31, 2026

Issue link
[https://github.com//issues/14249

Description
This PR updates WatchEffect typing to allow async callbacks by accepting Promise in addition to void.

Why
watchEffect is documented and commonly used with async functions, but the previous type signature rejected this pattern and caused lint/type friction.

Changes
Updated WatchEffect type to support async callbacks.
Added dts regression coverage to ensure async watchEffect callbacks are accepted.

Summary by CodeRabbit

  • New Features

    • watchEffect now supports async callbacks in addition to synchronous ones.
  • Tests

    • Added type test coverage for async watchEffect callbacks with cleanup support.

Copilot AI review requested due to automatic review settings March 31, 2026 05:51
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c34adcb8-c94b-4f0c-9a5c-5ecf48923be8

📥 Commits

Reviewing files that changed from the base of the PR and between fa23116 and af938c7.

📒 Files selected for processing (2)
  • packages-private/dts-test/watch.test-d.ts
  • packages/reactivity/src/watch.ts

📝 Walkthrough

Walkthrough

This PR widens the WatchEffect type definition to permit async callbacks returning Promise<void> alongside synchronous callbacks, with an accompanying type test validating async watchEffect usage with cleanup functions.

Changes

Cohort / File(s) Summary
Type Definition Widening
packages/reactivity/src/watch.ts
Updated WatchEffect type to allow void | Promise<void> return type, enabling async callback support.
Type Test Addition
packages-private/dts-test/watch.test-d.ts
Added test case for async watchEffect callback with onCleanup parameter invocation.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

Suggested labels

ready to merge

Poem

🐰 Async effects now bloom so bright,
With promises held in watchful sight,
Cleanup functions dance in the async glow,
A type that flexes where effects flow! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(reactivity): allow async watchEffect callbacks' clearly and concisely describes the main change: enabling async callback support in watchEffect by updating its type signature.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates Vue reactivity typings so watchEffect callbacks can be async (i.e., return a Promise<void>), matching documented/common usage and avoiding TS/ESLint “void-return expected” friction.

Changes:

  • Broaden WatchEffect return type from void to void | Promise<void>.
  • Add a DTS regression test ensuring async watchEffect callbacks type-check.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/reactivity/src/watch.ts Expands WatchEffect type to allow Promise<void> return.
packages-private/dts-test/watch.test-d.ts Adds DTS coverage for async watchEffect usage (#14249).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@edison1105
Copy link
Copy Markdown
Member

duplicate of #14251

@edison1105 edison1105 closed this Mar 31, 2026
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.

3 participants