Skip to content
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

fix(compat): handle listener, style and class in legacy functional components #1080

Merged
merged 1 commit into from
Nov 17, 2021

Conversation

xanf
Copy link
Collaborator

@xanf xanf commented Nov 16, 2021

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 using compatConfig 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 set FUNCTIONAL_COMPONENT flag in our "wrapper component" so Vue could correctly handle this

Original explanation was wrong, now I figured root cause of the issue. When INSTANCE_LISTENERS or INSTANCE_ATTRS_CLASS_STYLE is set - Vue is slicing "props" to props/listeners/attrs combination. The problem is that script setup simply has no way of accessing listeners (for example) if this compat flag is enabled so they are just lost. In order to mitigate this we explicitly set two flags mentioned in atrrsFallthrough.ts to false for our component making sure they will be passed to our component under test in proper way

@xanf xanf changed the title fix(compat): handle listeners in legacy functional components fix(compat): handle listener, style and class in legacy functional components Nov 17, 2021
@lmiller1990
Copy link
Member

I have no idea how you figured this out! Nice job. It seems few libraries are actually using the compat/migration build, but opting for re-writes. Glad to see you are making use of this for Vue Boostrap.

@lmiller1990 lmiller1990 merged commit 7fad6e5 into master Nov 17, 2021
@lmiller1990 lmiller1990 deleted the functional-component-on branch November 17, 2021 11:32
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.

2 participants