Skip to content

Initialize custom elements in connectedCallback #5139

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

Conversation

Truffula
Copy link

@Truffula Truffula commented Jul 13, 2020

When a custom element is created within a block of HTML, init() runs before attributes are available because attributeChangedCallback() has not yet fired to provide initial values. The result is that the component code first runs with the default values or undefined for each property.

This change updates the base SvelteElement and generated Custom Element code so that the initialisation and onMount() are deferred until connectedCallback() fires if—and only if—no options object is passed in to the constructor. This means any attributes on the element become available on init, and if any properties are set by JavaScript before DOM insertion (e.g. by a third party framework that binds attributes), they will also be captured and passed in when initialisation runs.

Fixes #2227
Affects #4527

@Truffula Truffula marked this pull request as ready for review July 13, 2020 12:46
mindrones and others added 19 commits August 3, 2020 15:19
No need for CSS here, the same effect could be achieved with just a `disabled` binding.
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](lodash/lodash@4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](lodash/lodash@4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Initial stab at a blog post

* Update site/content/blog/2020-06-04-svelte-and-typescript.md

Co-authored-by: pngwn <[email protected]>

* Update 2020-06-04-svelte-and-typescript.md

* Apply suggestions from code review

Co-authored-by: halfnelson <[email protected]>
Co-authored-by: Simon H <[email protected]>

* Tighten the post

* Fix degit sample

* Feedback

* More feeedback

* Handle feedback

* Handle all the feedback in the PR

* Add a note about the should work

* Change date

* code style consistency, fix syntax error

Co-authored-by: pngwn <[email protected]>
Co-authored-by: halfnelson <[email protected]>
Co-authored-by: Simon H <[email protected]>
Co-authored-by: Rich Harris <[email protected]>
@ScottAwesome
Copy link

@Truffula you need any help with these merge conflicts? I’m really looking forward to using svelte in a design system but the chat element limitations are my hang up. This and a few of the other PRs help fix that. I’m happy to help!

@Truffula
Copy link
Author

@ScottAwesome sure feel free if you want to tackle them! 👍🏻

@antony antony self-assigned this Jan 20, 2021
@stale
Copy link

stale bot commented Aug 18, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Aug 18, 2021
@stale
Copy link

stale bot commented Sep 12, 2021

This pull request has been closed as it was previously marked as stale and saw no subsequent activity.

@stale stale bot closed this Sep 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prop initialization in web/standalone components