Skip to content

Actions mapped to namespaced modules pass unexpected explicit undefined payload to store.dispatch #1571

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

Closed
markrian opened this issue Jun 26, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@markrian
Copy link

markrian commented Jun 26, 2019

Version

3.1.1

Reproduction link

https://codepen.io/markrian/pen/vqeGZZ?editors=0010

Steps to reproduce

  1. Open https://codepen.io/markrian/pen/vqeGZZ?editors=0010
  2. Open the browser's console
  3. Observe the differing logged arguments passed to store.dispatch depending on whether it's a root-mapped action or a namespace-mapped action ([ "foo" ] and [ "childModule/foo", undefined ] respectively - note the extra undefined argument in the second case; the different action name is of course expected)

Note that this only really applies in a testing scenario, where the test spies on store.dispatch to ensure the component dispatches the expected actions.

What is expected?

store.dispatch receives exactly the same arguments regardless of whether the actions are namespace-mapped or not.

What is actually happening?

store.dispatch receives a payload argument of undefined for namespace-mapped actions.


I encountered this when refactoring a store into a namespaced module, and found that my expectations needed to change: that store.dispatch received an extra undefined argument.

I'm not sure if this should be considered a bug in Vuex, or in my testing approach of spying on store.dispatch 🤷‍♂️

@ghost
Copy link

ghost commented Jun 26, 2019

This is happening because of https://github.com/vuejs/vuex/blob/v3.1.1/src/store.js#L360 (explicitly passing payload to dispatch even if undefined). A simple (but admittedly not elegant) fix would be

-  return store.dispatch(type, payload)
+  return payload ? store.dispatch(type, payload) : store.dispatch(type)

@ant1m4tt3r
Copy link

I can work on this issue. Seems preety simple to implement @gitlab-winnie solution.

@kiaking
Copy link
Member

kiaking commented Apr 30, 2020

Closing due to it might already fixed. See comment #1676 (comment). Please feel free to open another issue if this is something that we should solve.

@kiaking kiaking closed this as completed Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants