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

Directive plugin API crashes on unknown properties, without error message #795

Closed
catrope opened this issue Mar 3, 2020 · 0 comments
Closed

Comments

@catrope
Copy link
Contributor

catrope commented Mar 3, 2020

Version

3.0.0-alpha.7

Reproduction link

https://jsfiddle.net/catrope/s0th46n2/11/

Steps to reproduce

Register a directive that has unrecognized properties. For example, a directive that has both a Vue3-style "mounted" method and a Vue2-style "bind", which one might try to do to write a plugin that's compatible with both Vue2 and Vue3. But literally any property that isn't "beforeMount", "mounted", "beforeUpdate", "updated", "beforeUnmount" or "unmounted" will cause this crash.

app.directive( 'foo', {
    mounted( el ) {
        el.innerHTML = 'example';
    bind( el ) {
        el.innerHTML = 'example2';
    }
} );

Then use the directive in a component somewhere (e.g. <p v-foo />)

What is expected?

Either the directive just works ("mounted" is used and "bind" is ignored), or I get a reasonably clear error message that explains what I did wrong

What is actually happening?

Registering the directive doesn't fail, but using it causes a JS error while rendering: TypeError: Cannot destructure 'directiveToVnodeHooksMap[key]' as it is undefined.


The destructuring that fails is here: https://github.com/vuejs/vue-next/blob/52cc7e823148289b3dcdcb6b521984ab815fce79/packages/runtime-core/src/directives.ts#L130

It fails because it expects every single key in dir to also exist in directiveToVnodeHooksMap, and it doesn't check that assumption.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant