-
Notifications
You must be signed in to change notification settings - Fork 257
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
Differentiate script setup from option api component with setup #1928
Differentiate script setup from option api component with setup #1928
Conversation
✅ Deploy Preview for vue-test-utils-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
the test from b7be04a should now pass, as well as any other test from the suite.
7b45b79
to
aec9623
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this @renatodeleao 👍
Your fix looks good to me, I was afraid we would need more cases to make everything work.
As I commented in the review, let's try just using _isScriptSetup
and see if that's OK.
src/mount.ts
Outdated
// Also ensures not to include option API components in this this block | ||
// since they can also have setup state but need to be patched using | ||
// the regular method. | ||
if (hasSetupState(this) && this.$.setupState.__isScriptSetup) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your suggestion to have a isScriptSetup
util function 👍
And maybe this check can just rely on _isScriptSetup
and we can remove hasSetupState
here.
I think hasSetupState
is used elsewhere and is really needed to know if the component has a setup (but not necessarily a script setup). If tests are green, we can cut a release and give it a go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo this this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, you're right! I've removed the hasSetupState
check from here because it's redundant, but we can't replace hasSetupState
with isScriptSetup
as they check for different things and some specs around expose fail if we did.
Thanks for the review!
…se it - drop hasSetupState check, if a component is <script setup> i always has setup state - do note that isScriptSetup and hasSetupState check for different things. I tried to replaced hasSetupScript with isScriptSetup but some specs around expose started to fail so we are required to keep it for now.
39d2312
to
f509cef
Compare
Thanks @renatodeleao , we'll cut a release soon |
After a lot of discussion at #1869 and failed attempts to reproduce the issue I finally made the error happen and propose a fix. It's very ugly, but the tests are green and make more VTU@2 "customers" happy (at least one customer :) )
The patch
Using yet another vue internal property
__isScriptSetup
12 to differentiate<script setup>
components from Option API components withsetup()
hook since both fall in thehasSetupState
block. The latter can be patched regularly without triggering Proxy trap set error that lead to the2.2.3
patch in the first place (#1861), and only when patched like that, it actually works in all possible scenarios.The only reason for this to be acceptable code is because the previous implementation also relied on
devtoolsRawSetupState
which is also considered internal property.Before
test-utils/src/mount.ts
Lines 481 to 485 in a48712d
After
test-utils/src/mount.ts
Lines 485 to 488 in aec9623
Notes for the reviewer
[email protected]
of the codebase.git reset HEAD^ --hard && npm run test mocks
to see the spec failing.hasSetupState
toisScriptSetup
and move the && check within the helper. We can also check if simply using the__isScriptSetup
flag is enough.Footnotes
https://github.com/vuejs/core/blob/0c07f12541061cf10996f998705d7ad36193aa4f/packages/runtime-core/__tests__/apiCreateApp.spec.ts#L517 ↩
https://github.com/vuejs/core/blob/8a123ac34fd30fc36ac9e0c252dd345d6d7c7f50/packages/compiler-core/src/options.ts#L121 ↩