[CEReactions] step 3 pops the element queue before invoking it; all engines invoke first
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 66/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- html
- Domain
- documentation
Research direction
Read the [CEReactions] section of the HTML Standard source and the linked "enqueue an element on the appropriate element queue" algorithm it references, then compare with the Blink, WebKit and Gecko entry points quoted in the issue. Edit step 3 to invoke the current element queue and pop it afterwards, adding a short note that the queue can grow while being invoked. Done means the wording matches the engines and the behaviour described for html/semantics/forms/the-select-element/customizable-select/selectedcontent-custom-element-reactions.html is what the text now specifies.
Written by the indexing model from the issue text.
Description
What is the issue with the HTML Standard?
[CEReactions] step 3 says:
- Pop the element queue from the custom element reactions stack, and invoke custom element reactions in that queue.
Read literally, the element queue is popped before its reactions are invoked. While those reactions run, the queue being processed is no longer the current element queue. Any reaction enqueued during the invocation therefore goes through enqueue an element on the appropriate element queue: if this was the outermost [CEReactions] scope the stack is now empty, so the element is added to the backup element queue and a microtask is queued to process it.
A concrete case: the invocation runs an upgrade reaction for a connected element, and the upgrade enqueues that element's connectedCallback. The callback reaction is added to the element's own custom element reaction queue, and the element is appended to the backup element queue. The callback runs right away, because the element's reaction queue is still being drained. But the element stays on the backup element queue with an empty reaction queue, and the "processing the backup element queue" flag stays set until that microtask runs. A later reaction from a path that has no [CEReactions] scope (the parser, user editing, a native microtask) is then appended behind the stale entry. When the backup element queue is processed, the stale element's later reactions run first, so callbacks come out in the wrong order.
All three engines instead invoke the queue while it is still the current element queue, and pop it afterwards. Reactions enqueued during the invocation therefore join that same queue, never the backup queue:
- Blink:
CustomElementReactionStack::PopInvokingReactionscallsInvokeReactions(*queue), thenstack_.pop_back(). - WebKit:
~CustomElementReactionStackcallsm_queue.processQueue()whiles_currentProcessingStackis still this stack, then restores the previous one. - Gecko:
CustomElementReactionsStack::PopAndInvokeElementQueuecallsInvokeReactions, thenRemoveLastElement, with the recursion depth still set.
We hit this in an engine that followed the text literally. html/semantics/forms/the-select-element/customizable-select/selectedcontent-custom-element-reactions.html ("Removing the selected option ... runs the clones' reactions after remove() returns") observes the order: Chrome passes it. Switching to invoke-then-pop fixed it.
Proposed change to step 3:
- Invoke custom element reactions in the current element queue, then pop it from the custom element reactions stack.
("Invoke custom element reactions" may need a note that the queue can grow while it is being invoked.)
Related, but not the same: #10944 and #10465.
- Dominant language
- HTML
- Stars
- 9.5k
- Forks
- 3.2k
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 43
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from whatwg/html
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 2 days
-
13.2.5 Tokenization list of token types missing processing instruction?Possibly taken @foolip claimed this 4 days ago. Opentopic: parser
Difficulty 1/5 Under an hour Newbie friendliness 70/100
whatwg/html#13341 · 1 comment · 1 assignee ·
Maintainers usually reply within 2 days
-
topic: popover
Difficulty 1/5 Under an hour Newbie friendliness 76/100
Maintainers usually reply within 2 days
-
topic: url
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 2 days
-
interop topic: img topic: rendering
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
whatwg/html#13194 · 4 comments ·
Maintainers usually reply within 2 days
Similar issues
-
external integration integration-submission
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
langchain-ai/docs#8426 ·
Maintainers usually reply within 1 day
-
[Benchmark] RX 6900 XT (gfx1030): Linux rx6000 package runs Qwen4-35B-A3B Balanced, 60 tok/s decodeOpen
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 3 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
keyxmakerx/Chronicle#3048 ·
Maintainers usually reply within 1 day
-
marketing
Difficulty 1/5 1-3 hours Newbie friendliness 90/100
Maintainers usually reply within 1 day