-
Notifications
You must be signed in to change notification settings - Fork 395
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
test(integration): Add integration test for dom synchronization #143
Conversation
0278658
to
b1a1190
Compare
Benchmark comparisonBase commit:
|
I've tracked down the change that originally fixed this test. It was fixed early in 0.17.16 development by 66454b4 committed by @caridy on Feb 7, 2018. Running this test on anything earlier will cause it to fail. There were a lot of changes in that commit, so unclear exactly which change actually fixed the test. |
@@ -0,0 +1,9 @@ | |||
<template> | |||
<template for:each={transformedOptions} for:item="option"> | |||
<input type="checkbox" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are missing the key
attribute here. Which is now a compiler error (in 0.18.x). Without that, events and props might exhibit the wrong value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values are unique in this example, but I don't think this is the problem. I can make key={option.value}
get transformedOptions() { | ||
const { options, value } = this; | ||
const ret = options.map(option => ({ | ||
value: option.value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an id of some sort must be part of the final array of items so it can be used in the template.
assert.equal(checks.value[1].isSelected(), true); | ||
|
||
const button = browser.element('button'); | ||
button.click(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what exactly are you trying to prove here. You're manipulating internal state, and then pressing the internal button, and then looking at the value of the internal checkboxes to try to validate that the button updated the UI, but that's not how raptor works. Raptor works by hiding the internals, and exposing states that are only observable from outside, independently of what the user is seeing in the UI.
I spent half an hour debugging with @midzelis this issue this morning. Here are a couple of observations. First attempt<template>
<input type="checkbox" checked={checkbox.isChecked} value="My checkbox">
<button onclick={setUncheck}>Uncheck</button>
</template> import { Element, track } from 'engine';
export default class LightningCheckboxGroup extends Element {
@track checkbox = {
isChecked: false
};
setUncheck() {
this.checkbox = {
isChecked: false
};
}
} If you click on the checkbox and then click on the When clicking on the button, the template gets evaluated, and the diffing algo compares the old state of the VDom with the new state. But because the old VDom node Second attemptIn order to get around this issue, we decided to add a <template>
<input type="checkbox" checked={checkbox.isChecked} onchange={handleChange} value="My checkbox">
<button onclick={setUncheck}>Uncheck</button>
</template> import { Element, track } from 'engine';
export default class LightningCheckboxGroup extends Element {
@track checkbox = {
isChecked: false
};
setUncheck() {
this.checkbox = {
isChecked: false
};
}
handleChange(evt) {
this.checkbox = {
isChecked: evt.target.checked,
};
}
} Everything works as expected. But now every time the |
jaja! @pmdartus you guys wasted 1h then! I knew exactly what's doing on here. you should have asked. first attempt is incorrect, because you don't track the state of the checkbox, and the diffing algo doesn't know what to do. so, that's expected. second attempt is correct, but we have a bug (for a long time) in raptor, that is only taking into account but it is tricky without introducing a regression. Last time we spoke about this, we were saying that maybe a hash table with those names, and a check for existent in that table can be faster than the string comparison for each of them in that if statement. feel free to send a PR. |
@caridy I'm not sure I agree that the first attempt is incorrect. I could 'track' the state of the checkbox by in a different private variable, i.e. 'this.deferredState' . Then, the button would simply assign the deferredState to isChecked(). The thing is, the diffing algorithm runs. Notices that old vdom state == current state, and doesn't need to update dom. However, I think it should also check the current state of the element, and bring that up to date with the vnode state. |
already fixed with #341 |
Details
Adds a testcase for https://playground.sfdc.es/projects/BJ0IY7ytM
Does this PR introduce a breaking change?
If yes, please describe the impact and migration path for existing applications:
Please check if your PR fulfills the following requirements: