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 custom element initialization #394

Merged
merged 6 commits into from
Jun 26, 2019

Conversation

maier49
Copy link
Contributor

@maier49 maier49 commented Jun 10, 2019

Type: bug

The following has been addressed in the PR:

Description:
It's evidently not guaranteed that a custom element's children will be available when it is connected (see discussion here), but our connectedCallback was setup as if it was. I've setup a mutation observer so that the element will wait till the document is loaded or an element after it in the HTML hierarchy is present to perform setup logic.

Resolves #342

@agubler
Copy link
Member

agubler commented Jun 13, 2019

@maier49 FYI, this seems to be failing CI.

child = document.createTextNode('bar');
element!.appendChild(child);

waitFor(
Copy link
Member

Choose a reason for hiding this comment

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

curious, do you need to return this to ensure that the test waits for the promise to be resolved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes 🤦‍♂ . This is actually broken in IE. Looking into it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@agubler Ok it was still the test that was broken I just didn't fix it properly. Should be good now (pending CI)

@maier49 maier49 force-pushed the 342-custom-element-fix-v6 branch from e028563 to ccfa3f8 Compare June 24, 2019 17:16
@maier49 maier49 force-pushed the 342-custom-element-fix-v6 branch from ccfa3f8 to b5a20b6 Compare June 24, 2019 17:20
@maier49
Copy link
Contributor Author

maier49 commented Jun 24, 2019

@agubler A problem with the approach I was using is that if no children are appended it might never call the ready callback. I've updated it to use setTimeout.

@maier49
Copy link
Contributor Author

maier49 commented Jun 26, 2019

@agubler Testing against the v5 custom elements showcase everything worked properly out of the box. But there were was an issue with the setup being called too many times when I put the element scripts in the head. Have that fixed now, here's the showcase with the scripts in the head:
https://dist-ytwugedbhm.now.sh/

@maier49 maier49 merged commit 8bcc58d into dojo:master Jun 26, 2019
@maier49 maier49 deleted the 342-custom-element-fix-v6 branch June 26, 2019 16:22
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.

Buggy custom element behavior when script is included before element is used
2 participants