Skip to content

Streaming HTML hangs if the target's original document is destroyed while a parser-blocking script is pending #13205

Open

Description

@zcorpan

What is the issue with the HTML Standard?

After streamHTMLUnsafe({ runScripts: true }) on an element in an iframe's document, the element can be moved to another document and streaming continues there. But when a streamed parser-blocking script is pending, the parser resumes from a task tied to the iframe's document:

Queue a global task on the DOM manipulation task source given the parser's script target document's relevant global object to perform the following steps:

  1. Execute the pending parsing-blocking scripts for this parser.
  2. If this parser's aborted is false, then run a fragment parser given this parser.

The script target document is set once, to the context document, when the stream is created. A task whose document isn't fully active isn't runnable, so if the iframe is removed before that task runs, the parser never resumes, and nothing aborts it. As far as I can tell, the rest of the content is never inserted and close() never settles:

// div is in iframe.contentDocument
const writer = div.streamHTMLUnsafe({ runScripts: true }).getWriter();
await writer.write('<script src="slow.js"></script><p>after</p>');
document.body.append(div);
iframe.remove();
await writer.close(); // never settles

Maybe the task could use the target's current node document's relevant global object, or the parser could be aborted, rejecting close(), when the script target document stops being fully active.

(Found while comparing #12758 with a rewrite of it, zcorpan#1.)

Activity

  1. added
    topic: parser
    on Nov 6, 2026
  2. zcorpan commented on Nov 6, 2026

    @zcorpan
    MemberAuthor
  3. self-assigned this
    on Nov 8, 2026
  4. noamr commented on Nov 8, 2026

    @noamr
    Contributor

    I think aborting would be better. If you stream into an element in an active document and it's destroyed half way, it's a bit like an "abort" condition.

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

Metadata

Metadata

Assignees

Labels

topic: parser

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions