Skip to content

Popping node vs. end tag behavior in <option> and <selectedcontent> #11653

Closed

Description

@dmsnell

What is the issue with the HTML Standard?

The recent changes in #10548 modify the parsing behavior so that a selected OPTION element will be appropriately cloned into the appropriate SELECTEDCONTENT. However, there seems to be a discrepancy between how the rules are written and how Chrome currently implements this.

(Given that this is currently a Chrome-only feature in production it’s unclear to me how other standards-compliant browsers and parsers will handle it).

The only reference to run the maybe clone an option into selectedcontent algorithm is found in the section for an end tag whose name is OPTION. However:

  • Chrome clones the appropriate OPTION into a SELECTEDCONTENT even when no end tag whose name is OPTION appears.
  • It is reasonable and preferable that the cloning operation runs regardless of the particular tokens in the markup.

Since the cloning probably needs to occur whenever popping any OPTION element off of the stack of open elements, it needs to run both during generate implied end tags and also when performing any pop operation on the stack of open elements.

Activity

  1. josepharhar commented on Sep 11, 2025

    @josepharhar
    Contributor

    I agree that this is a missing part of the spec, we should do that in generate implied end tags.

    It also makes me wonder if any other end tag rules for other elements are missing in generate implied end tags, and if the fix should be more generic to run end tag rules for any tag that gets closed in generate implied end tags.

  2. annevk commented on Sep 12, 2025

    @annevk
    Member

    cc @whatwg/html-parser

  3. dmsnell commented on Sep 12, 2025

    @dmsnell
    ContributorAuthor

    @josepharhar note that it’s not only in generate implied end tags where we might expect the algorithm to run. If I’m not misreading the spec, when:

    • IN BODY we encounter a star tag whose name is SELECT.
    • The parser was not created as part of the fragment case with SELECT as context element.
    • The stack of elements has a SELECT element in scope.

    Then we:

    Pop elements from the stack of open elements until a select element has been popped from the stack.

    So I think that this step skips generating implied end tags but might implicitly close any open OPTION elements, none of which contain the expected end tag, and one of which might be the selected content.

    <select id="real">
    <option>a
    <option selected>b
    <select id="closes-real-but-is-ignored">
  4. annevk commented on Sep 16, 2025

    @annevk
    Member

    We should have a follow-up issue on formalizing all those better though, I think. We don't want COMEFROM.

  5. josepharhar commented on Oct 7, 2025

    @josepharhar
    Contributor

    Thanks @zcorpan! I will make a paragraph like that for option elements for now.

    We should have a follow-up issue on formalizing all those better though, I think. We don't want COMEFROM.

    I agree. Would it make sense to move them all into one algorithm that runs any time any element is popped off the stack of open elements? I suppose that it's not perfect unless we also instrument every place that pops elements off the stack of open elements.

    Handling in generate implied end tags is still not sufficient, because, at least, the end-of-file token doesn't run those steps.

    Does this have an explicit step which pops elements off the stack which we could instrument?

  6. josepharhar commented on Oct 7, 2025

    @josepharhar
    Contributor

    I made a PR here: #11764

  7. annevk commented on Oct 8, 2025

    @annevk
    Member

    Would it make sense to move them all into one algorithm that runs any time any element is popped off the stack of open elements?

    Presumably this is what WebKit (and I guess Chromium) call finishParsingChildren()? It seems reasonable to let elements define such steps and then the parser pops we run those steps for the relevant element, if it has any defined. (Or they have them always defined but by default no-op.)

    Generally the existence of this mechanism is a bit of a design smell and cannot be replicated by custom elements as it would make it very easy to design elements that work declaratively, but not imperatively. I'm not sure how to convey that properly however.

    I suppose that it's not perfect unless we also instrument every place that pops elements off the stack of open elements.

    Right, I think we want to make "popping" an algorithm.

    Does this have an explicit step which pops elements off the stack which we could instrument?

    Yeah I think so. "Stops parsing" and "abort a parser" both pop.

  8. added a commit that references this issue on Oct 13, 2025
    4ce63af
  9. annevk commented on Oct 14, 2025

    @annevk
    Member

    Follow-up issue: #11781.

  10. added a commit that references this issue on Mar 31, 2026
    c84d0ff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions