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

Added check in merge strat for watches if child is already an array (fix #5652) #5653

Merged
merged 4 commits into from
Jun 6, 2017
Merged

Added check in merge strat for watches if child is already an array (fix #5652) #5653

merged 4 commits into from
Jun 6, 2017

Conversation

strantr
Copy link
Contributor

@strantr strantr commented May 11, 2017

When performing multiple extends/mixins watches are converted to arrays of handlers.
If the parent does not watch an element, but the children do, it will not run the parent.concat code and instead always wrap the child.
If the child is already an array it does not need to be wrapped again.
Fixing #5652

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

If the child is already an array it does not need to be wrapped again.
Fixing #5652
@strantr strantr changed the title Added check for if child is already an array (fix #5652) Added check in merge strat for watches if child is already an array (fix #5652) May 11, 2017
@posva
Copy link
Member

posva commented May 11, 2017

Could you add a test for this, please?

@posva
Copy link
Member

posva commented May 11, 2017

Sorry, I checked the PR before the issue, but I'm not sure there's a problem here, mixins are pain javascript objects, not Vue sub classes

@dsonet
Copy link
Contributor

dsonet commented May 11, 2017

@posva It's very reasonable to add this check, to avoid wrap the child value accidentally.

@posva
Copy link
Member

posva commented May 11, 2017

@dsonet Yes, but we have to make sure the accident is possible 😄

@strantr
Copy link
Contributor Author

strantr commented May 23, 2017

@posva I've added the unit test based on the existence of Object.prototype.watch

expect(spy).toHaveBeenCalledWith(2, 1)
}).then(done)
})
afterEach(function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could group this test into a describe and use afterAll so the check is run only once. You can also setup the watch property on the beforeAll

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the suggested change

@strantr
Copy link
Contributor Author

strantr commented May 23, 2017

@posva Any idea why the CI test would fail on "Transition Basic: explicit transition type" - works fine locally and has no relation to my change

@@ -172,7 +172,7 @@ strats.watch = function (parentVal: ?Object, childVal: ?Object): ?Object {
}
ret[key] = parent
? parent.concat(child)
: [child]
: Array.isArray(child) ? child : [child]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I finally took a proper look at this issue - since the error is caused by native watch on Object.prototype (which is a function), I think the proper fix would be adding the following at the top of the function:

if (typeof parentVal === 'function') {
  parentVal = null
}
if (typeof childVal === 'function') {
  childVal = null
}

Essentially, ignore if the value is Object.prototype.watch. The test case will need to be updated accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yyx990803 I've added a new test for merging multiple layers of extends (I wasn't sure if it was more appropriate in the watch tests or the extends tests) - this causes the issue where child is wrapped multiple times. I am happy to make your change however this second test case will fail with your recommendation but work with the initial fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the initial fix was correct.The core reason caused bug was because it deal with the child value inconsistently. With the fix it can deal with it correctly.

@yyx990803 yyx990803 merged commit 48c0c1c into vuejs:dev Jun 6, 2017
@strantr strantr deleted the fix_watch_mixins branch June 6, 2017 10:58
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.

4 participants