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

Component $attrs and $listeners are readonly in counter-vuex-spec #1

Open
amirrustam opened this issue Jan 27, 2018 · 0 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@amirrustam
Copy link
Owner

amirrustam commented Jan 27, 2018

This issue is part of effort to fix cypress-io#6, and get Vuex fully operational in component unit tests.

Exhibited Behavior

When clicking on an increment button within the counter-vuex-spec run, Vue displays a warning message stating the $attrs and $listeners properties of the Counter component are readonly.

Analysis

The increment mutation will trigger updating of the child components, in this case the child component is Counter. This updating is done via the aptly named updateChildComponent() function within vue/src/core/instance/lifecycle.js.

updateChildComponent() sets the global flag isUpdatingChildComponent to true before the update, and to false after update.

This global flag is checked during rendering time within initRender() to define the reactive properties $attrs and $listeners:

// vue/src/core/instance/render.js

defineReactive(vm, '$attrs', parentData && parentData.attrs || emptyObject, () => {
  !isUpdatingChildComponent && warn(`$attrs is readonly.`, vm)
}, true)
defineReactive(vm, '$listeners', options._parentListeners || emptyObject, () => {
  !isUpdatingChildComponent && warn(`$listeners is readonly.`, vm)
}, true)

The issue is caused by the global isUpdatingChildComponent flag being set to false before the rendering is initialized.

Context

"cypress": "1.4.1",
"vue": "2.5.13",
"vue-loader": "13.6.1",
"vue-template-compiler": "2.5.13",
"vuex": "3.0.1"
@amirrustam amirrustam added the bug Something isn't working label Jan 27, 2018
@amirrustam amirrustam self-assigned this Jan 27, 2018
amirrustam added a commit that referenced this issue Jan 28, 2018
Refactors how the Vue instance within the component app frame is initialized, and fully fixes Vue integration.
- fixes lingering issues after pull request cypress-io#13
- fully fixes cypress-io#6
- fixes #1
- README docs have been updated to reflect refactoring
- 'vue' option has been deprecated (with warning to user) as it's no longer necessary
- spread operator support has been added for upcoming Vuex example
bahmutov pushed a commit to cypress-io/cypress-vue-unit-test that referenced this issue Jan 31, 2018
* fix: vuex integration (#6)

The inner Vue instance within Vuex Store must be refeshed by `resetStoreVM` to restore reactivity of the store state. This doesn’t fix stale mapped getters within components. That’s a separate WIP issue.

* fix: stale mapped getter `evenOrOdd` (#6)

Current mapped vuex getters within components become stale. To have a working Counter example, the computed mapped `evenOrOdd` is accessed directly via `$store`. This will be changed back once the stale mapped getter issue (WIP) is fixed.

* feat: added example tests for Counter component

Added tests to cover all the features within the component. Fixes #6

* minor: following better practices

* fix: refactor Vue initialization in app frame

Refactors how the Vue instance within the component app frame is initialized, and fully fixes Vue integration.
- fixes lingering issues after pull request #13
- fully fixes #6
- fixes amirrustam#1
- README docs have been updated to reflect refactoring
- 'vue' option has been deprecated (with warning to user) as it's no longer necessary
- spread operator support has been added for upcoming Vuex example

* feat: enhanced Vuex Counter example and test spec

To thoroughly demonstrate Vuex support after the refactoring in commit amirrustam/cypress-vue-unit-test@e8773383, Counter.vue now:
- Utilizes all Vuex mapping functions.
- Can properly use computed mapped getters in its template. This was an issue after #13.
- Set count state via an input field to demonstrate mapped mutations. Two tests have been added to the spec for this new input field.

Close #6

* minor: remove redundant declaration
bahmutov added a commit to cypress-io/cypress-vue-unit-test that referenced this issue Jan 31, 2018
* working on Vuex example for #6

* fix: Vuex integration and add Counter example tests (#13)

* fix: vuex integration (#6)

The inner Vue instance within Vuex Store must be refeshed by `resetStoreVM` to restore reactivity of the store state. This doesn’t fix stale mapped getters within components. That’s a separate WIP issue.

* fix: stale mapped getter `evenOrOdd` (#6)

Current mapped vuex getters within components become stale. To have a working Counter example, the computed mapped `evenOrOdd` is accessed directly via `$store`. This will be changed back once the stale mapped getter issue (WIP) is fixed.

* feat: added example tests for Counter component

Added tests to cover all the features within the component. Fixes #6

* minor: following better practices

* Full Vuex support with enhanced Counter.vue example and test spec (#15)

* fix: vuex integration (#6)

The inner Vue instance within Vuex Store must be refeshed by `resetStoreVM` to restore reactivity of the store state. This doesn’t fix stale mapped getters within components. That’s a separate WIP issue.

* fix: stale mapped getter `evenOrOdd` (#6)

Current mapped vuex getters within components become stale. To have a working Counter example, the computed mapped `evenOrOdd` is accessed directly via `$store`. This will be changed back once the stale mapped getter issue (WIP) is fixed.

* feat: added example tests for Counter component

Added tests to cover all the features within the component. Fixes #6

* minor: following better practices

* fix: refactor Vue initialization in app frame

Refactors how the Vue instance within the component app frame is initialized, and fully fixes Vue integration.
- fixes lingering issues after pull request #13
- fully fixes #6
- fixes amirrustam#1
- README docs have been updated to reflect refactoring
- 'vue' option has been deprecated (with warning to user) as it's no longer necessary
- spread operator support has been added for upcoming Vuex example

* feat: enhanced Vuex Counter example and test spec

To thoroughly demonstrate Vuex support after the refactoring in commit amirrustam/cypress-vue-unit-test@e8773383, Counter.vue now:
- Utilizes all Vuex mapping functions.
- Can properly use computed mapped getters in its template. This was an issue after #13.
- Set count state via an input field to demonstrate mapped mutations. Two tests have been added to the spec for this new input field.

Close #6

* minor: remove redundant declaration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant