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

feat(engine): Add support for isConnected on LightningElement #1711

Merged
merged 7 commits into from
Feb 11, 2020

Conversation

ravijayaramappa
Copy link
Contributor

@ravijayaramappa ravijayaramappa commented Feb 7, 2020

Details

Developers can now check if an LWC element is connected to the DOM using the isConnected property on the component instance.

Fixes #1698

Does this PR introduce breaking changes?

  • No, it does not introduce breaking changes.

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

The PR fulfills these requirements:

  • Have tests for the proposed changes been added? ✅
  • Have you followed these instructions to clearly describe the issue being fixed or feature enhanced? ✅

GUS Work Item

W-7199523

get isConnected(): boolean {
const vm = getAssociatedVM(this);
const { elm } = vm;
return elm.isConnected;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ravijayaramappa ravijayaramappa marked this pull request as ready for review February 10, 2020 01:47
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.

The code looks good, but let's extract the unrelated code changes in multiple PR. This would allow reverting individual changes if needed.

@@ -12,3 +12,5 @@ If yes, please describe the impact and migration path for existing applications.
## The PR fulfills these requirements:
* Have tests for the proposed changes been added? ✅ / ❌
* Have you followed [these instructions](../CONTRIBUTING.md#-commit-message-conventions) to clearly describe the issue being fixed or feature enhanced? ✅ / ❌

## GUS Work Item
Copy link
Member

Choose a reason for hiding this comment

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

Let's split that in another PR.

const componentTag = getComponentTag(vm);
assert.isFalse(
isBeingConstructed(vm),
`this.isConnected cannot be accessed during the construction phase of the custom` +
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
`this.isConnected cannot be accessed during the construction phase of the custom` +
`this.isConnected shouldn't be accessed during the construction phase of the custom` +

assert.isFalse(
isBeingConstructed(vm),
`this.isConnected cannot be accessed during the construction phase of the custom` +
` element for ${componentTag} because it is redundant. The value will always be` +
Copy link
Member

Choose a reason for hiding this comment

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

Even if the error makes sense in 99% of the case, I would like to bring more nuance to this statement. If the element is already connected to the DOM before the upgrade the isConnected will be true in the constructor: https://jsfiddle.net/pmdartus/fb1Lt8wa/2/

@@ -12,9 +12,3 @@ export interface Context {
tplCache?: Template;
[key: string]: any;
}

export let currentContext: Context = {};
Copy link
Member

Choose a reason for hiding this comment

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

Let's move the context removal to another PR.

@ravijayaramappa ravijayaramappa merged commit 5a48cb8 into master Feb 11, 2020
@ravijayaramappa ravijayaramappa deleted the ravi/master/isConnected branch April 27, 2020 17:36
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.

Exposing Node.prototype.isConnected on LightningElement
3 participants