Skip to content

docs: add "things to remember" in lifecycle callbacks#118

Merged
keithamus merged 1 commit intomainfrom
docs-add-things-to-remember-in-lifecycle-callbacks
Feb 19, 2021
Merged

docs: add "things to remember" in lifecycle callbacks#118
keithamus merged 1 commit intomainfrom
docs-add-things-to-remember-in-lifecycle-callbacks

Conversation

@keithamus
Copy link
Copy Markdown
Contributor

This adds a couple of notes about the caveats of connectedCallback and attributeChangedCallback which developers have noticed while using Catalyst. This should help future users be less likely to hit these problems, or at the very least give us a place to point them to if they get bit by these behaviours.

@keithamus keithamus requested a review from a team as a code owner February 19, 2021 15:25
@github-pages github-pages Bot temporarily deployed to github-pages February 19, 2021 15:26 Inactive
Copy link
Copy Markdown
Contributor

@koddsson koddsson left a comment

Choose a reason for hiding this comment

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

:shipit:


#### Things to remember

The `connectedCallback` is called _as soon as_ the element is attached to a `document`. This _may_ occur _before_ an element has any children appended to it, so you should be careful not expect an element to have children during a `connectedCallback` call. This means avoiding checking any `target`s or using other methods like `querySelector`. Instead use this function to initialize itself and avoid doing initialization work which depend on children existing.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This feels like a good candidate for a lint rule that we could offer.

@keithamus keithamus merged commit ee35967 into main Feb 19, 2021
@keithamus keithamus deleted the docs-add-things-to-remember-in-lifecycle-callbacks branch February 19, 2021 16:49
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.

2 participants