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): deep manual dom elements fix #874

Merged
merged 4 commits into from
Dec 5, 2018

Conversation

davidturissini
Copy link
Contributor

Details

Fixes issue where manually appending non-empty DOM elements to lwc:dom="manual" would error when children were modified.

Does this PR introduce a breaking change?

  • Yes
  • No

@davidturissini davidturissini changed the title Dturissini/quill lwc dom fix(engine): deep manual dom elements fix Dec 3, 2018
// If node aleady has an ownerkey, we can skip
// Note: checking if a node as any ownerKey is not enough
// because this element could be moved from one
// shadow to another
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 replace this comment about handling the case where the node is moved from one shadow to another, with a test? :)

setCSSToken(node, shadowToken);
const { childNodes } = node;
for (let i = 0, len = childNodes.length; i < len; i += 1) {
const node: Node = childNodes[i];
Copy link
Member

Choose a reason for hiding this comment

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

I'm still a ts n00b but isn't the Node type inferred?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll double check, but I believe TS thinks that childNodes[i] can return Node | undefined

handleClick() {
const timeout = window.setTimeout(() => {
this.errorMessage = 'No error';
}, 200);
Copy link
Member

Choose a reason for hiding this comment

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

Non-zero values always throw me off. Since all the operations are sync, we can use 0 here right?

Copy link
Contributor Author

@davidturissini davidturissini Dec 4, 2018

Choose a reason for hiding this comment

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

MutationObserver operations are not sync, which is where the error would come from. They are run in a micro task which should execute before any timeouts, so a 0 duration timeout would probably work but I have the extra delay just to be safe

Copy link
Member

Choose a reason for hiding this comment

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

As you pointed out @davidturissini, by spec the MO callback need in a micro-task. I would be in favor of using a 0 value for the timeout.

});
browser.waitUntil(() => {
return errorElm.getText() === 'No error';
}, 1000, 'Manually adding elements with children should not error');
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 not specify a custom timeout here so that the default value is used implicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you clarify this? I don't quite understand what you mean

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}, 1000, 'Manually adding elements with children should not error');
it('should not error when manually adding elements with children', () => {
...
browser.waitUntil(() => {
return errorElm.getText() === 'No error';
});
// assert(true)?

return;
}
setNodeOwnerKey(node, ownerKey);
if (node instanceof HTMLElement) {
Copy link
Member

Choose a reason for hiding this comment

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

This condition needs to be updated with #872 depending on which PR lands first.

@salesforce-best-lwc-internal
Copy link

Benchmark results

Base commit: 94e6d2f | Target commit: 607df42

lwc-engine-benchmark

table-append-1k metric base(94e6d2f) target(607df42) trend
benchmark-table/append/1k duration 151.90 (±5.40 ms) 152.70 (±3.20 ms) +0.8ms (0.5%) 👌
table-clear-1k metric base(94e6d2f) target(607df42) trend
benchmark-table/clear/1k duration 6.50 (±0.40 ms) 6.30 (±0.30 ms) -0.2ms (3.1%) 👍
table-create-10k metric base(94e6d2f) target(607df42) trend
benchmark-table/create/10k duration 887.65 (±6.45 ms) 876.85 (±5.15 ms) -10.8ms (1.2%) 👍
table-create-1k metric base(94e6d2f) target(607df42) trend
benchmark-table/create/1k duration 118.65 (±2.70 ms) 117.95 (±2.55 ms) -0.7ms (0.6%) 👌
table-update-10th-1k metric base(94e6d2f) target(607df42) trend
benchmark-table/update-10th/1k duration 83.35 (±5.85 ms) 77.00 (±2.05 ms) -6.3ms (7.6%) 👍
tablecmp-append-1k metric base(94e6d2f) target(607df42) trend
benchmark-table-component/append/1k duration 255.20 (±5.15 ms) 255.90 (±6.90 ms) +0.7ms (0.3%) 👌
tablecmp-clear-1k metric base(94e6d2f) target(607df42) trend
benchmark-table-component/clear/1k duration 12.60 (±1.80 ms) 13.10 (±1.65 ms) +0.5ms (4.0%) 👌
tablecmp-create-10k metric base(94e6d2f) target(607df42) trend
benchmark-table-component/create/10k duration 1742.85 (±17.90 ms) 1737.50 (±13.25 ms) -5.3ms (0.3%) 👌
tablecmp-create-1k metric base(94e6d2f) target(607df42) trend
benchmark-table-component/create/1k duration 210.15 (±6.10 ms) 208.75 (±4.10 ms) -1.4ms (0.7%) 👌
tablecmp-update-10th-1k metric base(94e6d2f) target(607df42) trend
benchmark-table-component/update-10th/1k duration 74.85 (±5.55 ms) 70.65 (±6.15 ms) -4.2ms (5.6%) 👍
wc-append-1k metric base(94e6d2f) target(607df42) trend
benchmark-table-wc/append/1k duration 257.55 (±8.85 ms) 261.30 (±8.15 ms) +3.7ms (1.5%) 👌
wc-clear-1k metric base(94e6d2f) target(607df42) trend
benchmark-table-wc/clear/1k duration 23.60 (±2.25 ms) 23.55 (±2.70 ms) -0.1ms (0.2%) 👌
wc-create-10k metric base(94e6d2f) target(607df42) trend
benchmark-table-wc/create/10k duration 1828.95 (±40.60 ms) 1816.85 (±32.60 ms) -12.1ms (0.7%) 👌
wc-create-1k metric base(94e6d2f) target(607df42) trend
benchmark-table-wc/create/1k duration 224.05 (±4.00 ms) 221.60 (±5.85 ms) -2.5ms (1.1%) 👌
wc-update-10th-1k metric base(94e6d2f) target(607df42) trend
benchmark-table-wc/update-10th/1k duration 72.20 (±4.40 ms) 74.65 (±6.40 ms) +2.5ms (3.4%) 👌

@davidturissini davidturissini merged commit 041eb1e into master Dec 5, 2018
@pmdartus pmdartus deleted the dturissini/quill-lwc-dom branch December 21, 2018 16:15
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