Skip to content

When is slotchange handler fired? #515

Closed

Description

@trusktr

When is slotchange handler fired in the following case?

Activity

  1. hayatoito commented on Jun 7, 2016

    @hayatoito
    Contributor

    It's difficult to explain briefly here.
    These are now defined in the DOM Standard. The followings might be what you want to read:

  2. rniwa commented on Jun 7, 2016

    @rniwa
    Collaborator

    slotchange event fires at the end of the current microtask. Those custom element callbacks fire at the end of current "nanotask" which are basically when UA returns the control back to author scripts from their DOM, CSS OM, etc... APIs. So slotchange tends to fire a lot later than custom elements callbacks in common cases.

  3. trusktr commented on Jun 9, 2016

    @trusktr
    ContributorAuthor

    @rniwa How can a distributed node then run some code after slotchange handlers have fired without knowing about slotchange? If slotchange fired in the same tick as the custom element callbacks, then the simple solution is deferring to the next tick.

    I would really like to detect when the tree looks like this:

    div
     |
    slot
     |
    motor-node
    

    and I need that distributed motor-node to throw an error when it is distributed into a div.

  4. rniwa commented on Jun 9, 2016

    @rniwa
    Collaborator

    I don't follow what you're saying. slotchange event is fired on slot element, not the nodes distributed to the slot.

  5. trusktr commented on Jun 29, 2016

    @trusktr
    ContributorAuthor

    @rniwa Yep, that's exactly what I'm saying: that there's no way for a distributed node to know about being distributed because only the parent of the slot or slot itself can work with slotchange, so I suggested distributedCallback as a possible solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions