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

Warn when super.connectedCallback() is not called. #825

Closed
6 tasks done
dgp1130 opened this issue Oct 3, 2019 · 3 comments
Closed
6 tasks done

Warn when super.connectedCallback() is not called. #825

dgp1130 opened this issue Oct 3, 2019 · 3 comments

Comments

@dgp1130
Copy link

dgp1130 commented Oct 3, 2019

Description

I've made the mistake several times where I override connectedCallback() and disconnectedCallback() to set up event listeners and forget to call super.connectedCallback() or super.disconnectedCallback(). This makes the element not initialize and render() is never called. This is really awkward and hard to understand what is going on here. I think the framework should warn that the super methods have not been called.

I'm not sure exactly how to implement this, since LitElement won't ever receive the callback and doesn't necessarily know it was a developer mistake. However, this could be as simple as "if connectedCallback() is not called after 5 seconds, it's probably a developer error and warn to the console". I'm not sure if there are other practical instances where this warning might be erroneously triggered.

Live Demo

https://stackblitz.com/edit/lit-element-example-vtmnmx?file=index.js
(Element does not render because I forgot to call super.connectedCallback(). This is tricky to debug and the framework should help with that.)

Steps to Reproduce

  1. Override connectedCallback().
  2. Don't call super.connectedCallback().

Expected Results

LitElement should warn that super.connectedCallback() was never called.

Actual Results

Element does not render.

Browsers Affected

(I'm assuming this is all browsers, I only tested Chrome)

  • Chrome
  • Firefox
  • Edge
  • Safari 11
  • Safari 10
  • IE 11

Versions

  • lit-element: vX.X.X
  • webcomponents: vX.X.X
@justinfagnani
Copy link
Contributor

We would have to do this in a linter.

cc @runem @rictic

@runem
Copy link

runem commented Oct 5, 2019

The check is being implemented in eslint-plugin-wc eslint plugin. See these two issues:

I also created an issue for it at runem/lit-analyzer#57 :-)

@kevinpschaaf
Copy link
Member

Warning when failing to super to a lifecycle call is generally not possible in LitElement code itself, so we'll close this issue in favor of warning via linters; please follow the issues above for progress.

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

No branches or pull requests

4 participants