fix(compat): handle listener, style and class in legacy functional components #1080
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.
This one was quite tricky to debug 🕙
Basically, when dealing with legacy functional component we need to enable
FUNCTIONAL_COMPONENT
compatibility flag for@vue/compat
The problem is that we're wrapping this component inside
mount.ts
into script-setup component, which triggers Vue to render this component in "Vue 3 mode".Usually this is not a problem - each component controls own compat flags usingcompatConfig
but this is not a case for functional components - they do not have own instance, and compat config calculation is instance-based. This resulted into wrong normalization applied insid@vue/compat
and result component simply ignoring event handlers inside test. To fix this we explicitly setFUNCTIONAL_COMPONENT
flag in our "wrapper component" so Vue could correctly handle thisOriginal explanation was wrong, now I figured root cause of the issue. When
INSTANCE_LISTENERS
orINSTANCE_ATTRS_CLASS_STYLE
is set - Vue is slicing "props" to props/listeners/attrs combination. The problem is thatscript setup
simply has no way of accessinglisteners
(for example) if this compat flag is enabled so they are just lost. In order to mitigate this we explicitly set two flags mentioned inatrrsFallthrough.ts
tofalse
for our component making sure they will be passed to our component under test in proper way