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

fix(engine): marking dynamic nodes as dynamic #810

Merged
merged 5 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions packages/lwc-engine/src/framework/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
createTextHook,
createCommentHook,
} from "./hooks";
import { markAsDynamicChildren, hasDynamicChildren, patchEvent } from "./patch";
import { markAsDynamicChildren, patchEvent } from "./patch";
import {
isNativeShadowRootAvailable,
} from "../env/dom";
Expand Down Expand Up @@ -458,15 +458,18 @@ export function f(items: any[]): any[] {
}
const len = items.length;
const flattened: VNodes = [];

// all flattened nodes should be marked as dynamic because
// flattened nodes are because of a conditional or iteration.
// We have to mark as dynamic because this could switch from an
// iterator to "static" text at any time.
// TODO: compiler should give us some sort of indicator
// to describe whether a vnode is dynamic or not
markAsDynamicChildren(flattened);
for (let j = 0; j < len; j += 1) {
const item = items[j];
if (isArray(item)) {
ArrayPush.apply(flattened, item);
// iteration mark propagation so the flattened structure can
// be diffed correctly.
if (hasDynamicChildren(item)) {
markAsDynamicChildren(flattened);
}
} else {
ArrayPush.call(flattened, item);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const assert = require('assert');
describe('Dynamic text nodes rendering duplicate text', () => {
const URL = 'http://localhost:4567/duplicate-text-rendering';

before(() => {
browser.url(URL);
});

it('should not render duplicate text', function () {
browser.click('integration-duplicate-text-rendering');
assert.notDeepEqual(browser.getText('integration-duplicate-text-rendering'), 'ab');
assert.deepEqual(browser.getText('integration-duplicate-text-rendering'), 'b');
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth adding an assert.notDeepEqual() here, or maybe a comment that describes the issue that these changes fix? I'm just curious about what was actually being rendered.

});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<template if:true={hasParts}>
<template for:each={text} for:item="part">
<template if:true={part.highlight}>
Copy link
Member

Choose a reason for hiding this comment

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

Can we simplify this by removing part.highlight from the picture?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oddly enough, the bug does not exhibit when we remove this condition,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

{part.text}
</template>
<template if:false={part.highlight}>
{part.text}
</template>
</template>
</template>
<template if:false={hasParts}>
{text}
</template>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { LightningElement, track } from 'lwc';

export default class App extends LightningElement {
@track text = [{
text: 'a',
highlight: false,
}]

get hasParts() {
return Array.isArray(this.text) && this.text.length > 0;
}

get highlight() {
return false
}

get firstPart() {
return this.text[0]
}

connectedCallback() {
this.addEventListener('click', () => {
this.text = 'b'
})
}

}