Inconsistent component ref when using `defineExpose`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 54.4k
- Forks
- 9.2k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 140
Description
Vue version
3.3.4
Link to minimal reproduction
Steps to reproduce
The exposed vue instance when adding a ref to a Vue component in Script Setup differs if you have defined exposes with defineExpose().
Create two components, which take a single prop, identical except that one has a defineExpose.
Import these components in a parent component, and set a ref on them. Then log that ref's value.myProp (in a watcher, or onmounted).
What is expected?
The two logs log the same value.
What is actually happening?
If you do not have a defineExpose in your component, a parent component can access the props sent to that component via myRef.value.myProp, but as soon as you define exposes in the component, myRef.value.myProp returns undefined.
System Info
No response
Any additional comments?
The documentation for defineExpose (https://vuejs.org/api/sfc-script-setup.html#defineexpose) doesn't mention anything about that using it change the behaviour of other properties on the ref. So either it seems the documentation is unclear and needs to be clarified, or it is indeed a bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Vue Playground reproduction and compare the two Script Setup components, one using defineExpose() and one without it. Trace how the parent component's ref exposes myProp, then check the defineExpose documentation; done means the behavior is resolved or clearly documented, with the expected ref value consistent between the components.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100