-
Notifications
You must be signed in to change notification settings - Fork 57
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
Use typeof instead of instanceof to check for functions (fix for [vuex] unknown local mutation type) #46
Conversation
Hello @davestewart, thanks for responding so fast! Not exactly: if I take your assertions, it produces exactly the same result. The problem is when the variable is exported, here is a reproducer:
dist/vue-pathify.js:
My setup is:
|
No problem - I've been terrible recently! OK, seems strange, but the fix will of course be compatible. I'll investigate next week, and will do a release as well. Thanks! |
Thanks! I admit that I haven't found the exact cause of the issue; my guess would be a change in the Babel plugins used by Nuxt or one of its dependencies that converts exported functions into another type, but I haven't found any mention of that. |
There are only 7 JS types; Let's see what happens this week :) |
Yes sure about the primary types, which start with a lowercase letter and are the possible outputs of |
I've taken the time to investigate a bit this evening. If I do:
Then it doesn't work server-side: the function is not instanceof Function. However, if I do instead:
It works both server-side and client-side! So my guess is that there is something in the "universalization" header of the |
Hmm. That's interesting. I don't know enough about the internals of the bundling to know what that could be, but if you think it makes a difference, thanks for catching and investigating. Did this happen only on the server side? Can you make webpack aliases on the server side, so you could do:
Then just import as normal. ? |
Thanks for the input! I cannot make it work naming the alias exactly the same as the module name, there seems to be a precedence order that make Webpack check the node module first. If I name the alias differently (and import consequently), everything works well. To answer your first question, I haven't had any trouble with vuex-pathify client-side, the problem was server-side. Using the ESM module server-side fixes it without messing the client-side either. I've read that Webpack 4 is configured to import ES modules first (see here: https://webpack.js.org/configuration/resolve/#resolvemainfields) but I don't understand why it doesn't actually happen with these Nuxt version and libs... |
I had to reconfigure a project today using Post CSS and after half an hour of reading through docs and having about 10 tabs open of different articles saying different things, my head started to hurt. Setup sucks! |
Hello, thank you I've just downloaded the 1.2.0 from npm, I indeed have the new folder "types" in it but in the dist/vuex-pathify.(esm.)js files I still have the "instanceof Function" checks, it seems that my PR was not released in the 1.2.0... |
Oh shiiiiiiiit. I completely forgot to build! It's been that long since I updated that I forgot that step. Thanks for pointing that out. Stand-by for a 1.2.1 update |
OK, all done. Thanks! |
Ah ah, no problem, thank you, everything is working great now! :D |
Hello,
After upgrading to Nuxt 2.4, I noticed vue-pathify had stopped working correctly when using state functions with server-side rendering, like this one:
I investigated and I discovered that the error was coming from the function check inside Vue-pathify: the "state instanceof Function" doesn't return true anymore while it is clearly a function.
Using instanceof to check for functions is not a good pratice because the "Function" type doesn't cover all the JS functions:
I haven't completely investigated why in the case of SSR and with the new versions of the libs that Nuxt 2.4 use, the functions that are exported by a component do not have the "Function" type anymore, anyway this should be fixed to avoid future problems.
Thanks!