Repository navigation
Conversation
- watchEffect() cleanup examples referenced an undefined `newId`
variable; read `id.value` instead.
- The watch() pause/resume example called `watch(() => {})`, which
only logs a warning in 3.5 because a callback is required. Use
`watch(source, callback)` like the other examples in the section.
- The toRefs() type block declared `type ToRef` without its type
parameter.
- useId() with `app.config.idPrefix = 'myApp'` returns 'myApp-0', not
'myApp:0'. The separator changed after 3.5.0.
- The computed debugging example said mutating `count.value` would
call onTrigger, but since 3.5 a computed only tracks its
dependencies while it has a subscriber. Add a watcher to the example.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NQDmA3mwGfL83pbg9WQ6ey
✅ Deploy Preview for vuejs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Problem
I ran the code examples on the reactivity API pages against the latest Vue release (3.5.44). Five of them do not do what the docs say.
watchEffect()side effect cleanup (api/reactivity-core.md, both theonCleanupand theonWatcherCleanupexample). They calldoAsyncWork(newId), butnewIdis not defined inside awatchEffect(). It looks like it was copied from thewatch()example. Running it throwsReferenceError: newId is not defined.watch()pause / resume (api/reactivity-core.md). The example iswatch(() => {})with no callback. In 3.5 that only logs a warning: "watch(fn, options?)signature has been moved to a separate API. UsewatchEffect(fn, options?)instead." It also fails to type-check (Expected 2-3 arguments, but got 1).toRefs()type (api/reactivity-utilities.md). The block declarestype ToRef = T extends Ref ? T : Ref<T>without the<T>parameter, soTis undefined (Cannot find name 'T'). ThetoRef()section on the same page already hastype ToRef<T>.app.config.idPrefix(api/application.md). The example saysuseId()returns'myApp:0'and'myApp:1'. Vue 3.5.0 used:as the separator, but current 3.5 releases use-, so the real values are'myApp-0'and'myApp-1'.guide/extras/reactivity-in-depth.md). The example sayscount.value++should triggeronTrigger. Since 3.5, a computed only tracks its dependencies while it has a subscriber, so in the example as writtenonTriggeris never called. The core tests say the same thing ("computed won't track until it has a subscriber" inpackages/reactivity/__tests__/computed.spec.ts).Proposed Solution
doAsyncWork(id.value)in bothwatchEffect()cleanup examples.watch(source, callback), the same form the "Stopping the watcher" example right above it uses.type ToRef<T> = ....'myApp-0'and'myApp-1'.watchEffect(() => plusOne.value)before the mutation, with a short comment thatonTriggeronly runs while the computed has a subscriber.Additional Information
How I checked each one, with
vue@3.5.44in Node 22 (dev build):watchEffectexample throwsReferenceError: newId is not defined. Withid.value, changingidfrom 1 to 2 callscancel()for id 1 anddataends up as the result for id 2. Same result for theonWatcherCleanupversion.watch(() => {})logs the warning above.watch(source, callback)returns{ stop, pause, resume }, no callback runs while paused, and none runs afterstop().tsc --stricton the old line givesTS2304: Cannot find name 'T'. The new line type-checks.useId()withidPrefix = 'myApp'returnsmyApp-0andmyApp-1, both fromrenderToStringand from a clientcreateApp().mount(). The source inruntime-core/src/helpers/useId.tsjoins with'-'.@vue/runtime-core@3.5.0still used':'.onTrackfires butonTriggernever does. After adding thewatchEffect,count.value++callsonTriggerwithtype: 'set',key: 'value',0 -> 1.I ran Prettier with the repo config on the changed files. It reports the same differences before and after this change, so I added no new ones.