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-server): isConnected should not be true during construction #1977

Merged
merged 4 commits into from
Jul 17, 2020

Conversation

ekashida
Copy link
Member

@ekashida ekashida commented Jul 11, 2020

Details

When rendering on the server, isConnected should reflect the current vm state.

Does this PR introduce breaking changes?

  • No, it does not introduce breaking changes.

The PR fulfills these requirements:

  • Have tests for the proposed changes been added? ✅

GUS work item

W-7391508

@@ -323,6 +323,11 @@ export function getAssociatedVM(obj: VMAssociable): VM {
return vm!;
}

export function isConnected(obj: VMAssociable): boolean {
const vm = getAssociatedVM(obj);
return vm.state === VMState.connected;
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is going away with node-reactions, this seems like the wrong abstraction.

@caridy
Copy link
Contributor

caridy commented Jul 12, 2020

IMO, on the server side, you can simply have a weakmap that allows you to track what elements are connected after core invokes the corresponding insertion mechanism (insertBefore/appendChild/etc). I don't think we will ever have removal on the server side, so, this should be easier to keep track of without having to expose anything from core.

Copy link
Member

@pmdartus pmdartus left a comment

Choose a reason for hiding this comment

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

Instead of creating a new API, I would rather look at the node.parent property. The DOM version of isConnected is more complex because the parent node might or not be connected to a Document. In the case of SSR, we can make a safe assumption that as soon as a node has a parent it is considered connected.

In order to make it work the renderComponent API has also to be updated to attached the rendered component to a fake root element before invoking connectRootElement.

@jodarove
Copy link
Contributor

@ekashida is this related to W-7532119?

<template shadowroot="open">Is connected? true</template>
<template shadowroot="open">
<ul>
<li>connectedCallback</li>
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 test should directly test that isConnected property

  • in constructor is false
  • in connectedCallback is true

@salesforce-best-lwc-internal
Copy link

⚠ Performance Regression

Best has detected that there is a 5.6% performance regression across your benchmarks.

Please click here to see more details.

Click to view significantly changed benchmarks

@lwc/engine-dom

❌ Regressions base (00da41b) target (0f7ec5c) trend
table-append-1k.benchmark/benchmark-table/append/1k 253.32 (± 5.18ms) 276.17 (± 2.13ms) +22.8ms (9.0%)
table-clear-1k.benchmark/benchmark-table/clear/1k 14.51 (± 0.47ms) 16.89 (± 0.18ms) +2.4ms (16.4%)
table-create-1k.benchmark/benchmark-table/create/1k 154.45 (± 4.22ms) 172.44 (± 0.97ms) +18.0ms (11.6%)
table-update-10th-1k.benchmark/benchmark-table/update-10th/1k 138.00 (± 3.20ms) 146.68 (± 2.13ms) +8.7ms (6.3%)
tablecmp-append-1k.benchmark/benchmark-table-component/append/1k 357.42 (± 4.06ms) 384.27 (± 3.22ms) +26.8ms (7.5%)
tablecmp-clear-1k.benchmark/benchmark-table-component/clear/1k 7.96 (± 0.52ms) 9.82 (± 0.15ms) +1.9ms (23.4%)
tablecmp-create-10k.benchmark/benchmark-table-component/create/10k 1940.86 (± 20.97ms) 2075.72 (± 8.20ms) +134.9ms (6.9%)
tablecmp-create-1k.benchmark/benchmark-table-component/create/1k 224.94 (± 8.52ms) 244.79 (± 1.77ms) +19.9ms (8.8%)
tablecmp-update-10th-1k.benchmark/benchmark-table-component/update-10th/1k 116.54 (± 1.40ms) 128.69 (± 0.88ms) +12.1ms (10.4%)
wc-clear-1k.benchmark/benchmark-table-wc/clear/1k 22.45 (± 0.70ms) 26.52 (± 0.39ms) +4.1ms (18.1%)

@salesforce-best-lwc-internal
Copy link

⚠ Performance Regression

Best has detected that there is a 6.6% performance regression across your benchmarks.

Please click here to see more details.

Click to view significantly changed benchmarks

@lwc/engine-dom

❌ Regressions base (00da41b) target (c4139c9) trend
table-append-1k.benchmark/benchmark-table/append/1k 253.32 (± 5.18ms) 275.81 (± 1.97ms) +22.5ms (8.9%)
table-clear-1k.benchmark/benchmark-table/clear/1k 14.51 (± 0.47ms) 17.20 (± 0.30ms) +2.7ms (18.5%)
table-create-1k.benchmark/benchmark-table/create/1k 154.45 (± 4.22ms) 175.40 (± 1.25ms) +20.9ms (13.6%)
table-update-10th-1k.benchmark/benchmark-table/update-10th/1k 138.00 (± 3.20ms) 148.00 (± 2.20ms) +10.0ms (7.2%)
tablecmp-append-1k.benchmark/benchmark-table-component/append/1k 357.42 (± 4.06ms) 389.63 (± 2.23ms) +32.2ms (9.0%)
tablecmp-clear-1k.benchmark/benchmark-table-component/clear/1k 7.96 (± 0.52ms) 9.82 (± 0.15ms) +1.9ms (23.4%)
tablecmp-create-10k.benchmark/benchmark-table-component/create/10k 1940.86 (± 20.97ms) 2086.71 (± 17.07ms) +145.9ms (7.5%)
tablecmp-create-1k.benchmark/benchmark-table-component/create/1k 224.94 (± 8.52ms) 248.18 (± 1.38ms) +23.2ms (10.3%)
tablecmp-update-10th-1k.benchmark/benchmark-table-component/update-10th/1k 116.54 (± 1.40ms) 130.66 (± 1.19ms) +14.1ms (12.1%)
wc-clear-1k.benchmark/benchmark-table-wc/clear/1k 22.45 (± 0.70ms) 26.86 (± 0.30ms) +4.4ms (19.6%)
wc-create-1k.benchmark/benchmark-table-wc/create/1k 373.02 (± 12.21ms) 427.62 (± 28.06ms) +54.6ms (14.6%)
wc-update-10th-1k.benchmark/benchmark-table-wc/update-10th/1k 119.89 (± 4.28ms) 130.30 (± 1.70ms) +10.4ms (8.7%)

@salesforce-best-lwc-internal
Copy link

⚠ Performance Regression

Best has detected that there is a 5.5% performance regression across your benchmarks.

Please click here to see more details.

Click to view significantly changed benchmarks

@lwc/engine-dom

❌ Regressions base (00da41b) target (152539b) trend
table-append-1k.benchmark/benchmark-table/append/1k 253.32 (± 5.18ms) 274.93 (± 1.43ms) +21.6ms (8.5%)
table-clear-1k.benchmark/benchmark-table/clear/1k 14.51 (± 0.47ms) 16.75 (± 0.16ms) +2.2ms (15.4%)
table-create-1k.benchmark/benchmark-table/create/1k 154.45 (± 4.22ms) 172.11 (± 1.14ms) +17.7ms (11.4%)
table-update-10th-1k.benchmark/benchmark-table/update-10th/1k 138.00 (± 3.20ms) 145.76 (± 1.33ms) +7.8ms (5.6%)
tablecmp-append-1k.benchmark/benchmark-table-component/append/1k 357.42 (± 4.06ms) 381.56 (± 2.08ms) +24.1ms (6.8%)
tablecmp-clear-1k.benchmark/benchmark-table-component/clear/1k 7.96 (± 0.52ms) 9.78 (± 0.12ms) +1.8ms (22.9%)
tablecmp-create-10k.benchmark/benchmark-table-component/create/10k 1940.86 (± 20.97ms) 2082.84 (± 17.84ms) +142.0ms (7.3%)
tablecmp-create-1k.benchmark/benchmark-table-component/create/1k 224.94 (± 8.52ms) 245.82 (± 1.87ms) +20.9ms (9.3%)
tablecmp-update-10th-1k.benchmark/benchmark-table-component/update-10th/1k 116.54 (± 1.40ms) 128.78 (± 0.90ms) +12.2ms (10.5%)
wc-clear-1k.benchmark/benchmark-table-wc/clear/1k 22.45 (± 0.70ms) 26.43 (± 0.36ms) +4.0ms (17.7%)

@ekashida ekashida changed the title fix(engine-server): isConnected should reflect current vm state fix(engine-server): isConnected should not be true during construction Jul 17, 2020
@ekashida ekashida merged commit 93c2c25 into master Jul 17, 2020
@ekashida ekashida deleted the ekashida/is-connected branch July 17, 2020 09:01
import { HostElement, HostNodeType } from '../types';

const FakeRootElement: HostElement = {
type: HostNodeType.Element,
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be just a fragment type?

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.

5 participants