Replies: 1 comment 5 replies
-
does this relate? vivid-3/libs/components/src/lib/menu/definition.ts Lines 18 to 22 in 13ebc0a |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
tl;dr
When importing elements that depend on others in a
<script src="...">
tag, make sure these dependencies are imported first.E.g, do:
instead of:
So pay attention to the order in the doc's
components.json
.But it worked so far?
Yes, but it doesn't if you make Accordion inherit from the FAST element, instead of creating it from scratch.
? 🤔
I know, right? I found out the hard way while prototyping the FAST-descending-Accordion. The test page I used locally worked well and, before opening a PR, the README needed to be updated to reflect the API changes. Except the samples in the README suddenly didn't work.
With.
The.
Same.
Code.
?? 😅
It turned out that, inside the sample, the FAST Accordion's code was failing to correctly identify and loop over its AccordionItem children. The following test was never true:
And sure enough, in that case
item.__proto__
revealed itself to beHTMLElement
rather thanAccordionItem
.OK, but why was it working in my test page?
??? 😓
I knew
instanceof
could have weird results when used inside iframes, which is where our samples live. But it wasn't relevant here (the AccordionItem was defined inside the frame anditem
was identified as anHTMLElement
anyway).The only tiny difference between the code in my test page and the sample's one was how components were loaded:
Both of these snippets are functionally equivalent: they import the component code and register it.
They are, however, processed differently.
Here's the timeline of events in the test page:
...and in the sample:
Oooh... 💡
So it seems that in the test page, where components are all imported "manually" inside a
<script>
tag, they only start to be defined in the registry once all of them are loaded. On the other hand, in the sample, where components are imported in their own<script>
tag, each of them is immediately registered as soon as it is loaded.And that is a problem for our Accordion because the failing code mentioned at the beginning relies on the AccordionItem class being defined in the execution scope (even if the custom component isn't registered yet), which is the case in the test page, but not yet in the sample. The solution for it was then simply to switch the <script> tags order and voilà !
Since I spent quite a bit of time on this bug, thank you for spending yours reading this.
Beta Was this translation helpful? Give feedback.
All reactions