Repository navigation
Conversation
Add streamHTML(), streamAppendHTML(), streamPrependHTML(), streamBeforeHTML(), streamAfterHTML(), and streamReplaceWithHTML(), and their Unsafe counterparts. Each returns a WritableStream whose string chunks are parsed incrementally by an HTML fragment parser that inserts top-level nodes directly at a position fixed when the method is called. The stream errors if the node that content is inserted before stops being a child of the target. With runScripts, streamed scripts are parser-inserted and run in the target's document like during document loading: parser-blocking scripts pause the parser without blocking writes, and defer and module scripts run after close() settles. To support this, the HTML fragment parsing algorithm's setup is factored out into "create an HTML fragment parser", which every fragment parser (and only those) uses. The stream parser's own inert document holds its pending parsing-blocking script and deferred scripts, and a new script execution document on Document lets the existing cross-document check in "prepare the script element" compare against the target's document. A halted stream parser stops before its next tokenizer or tree construction step. This also changes existing behavior: * Fragment parsing creates top-level elements directly in the target's node document (or, when sanitizing, in the inert document of the fragment) rather than in an inert document from which they are adopted. This fixes the non-sanitizing top-level case of whatwg#13068. * Fragment parsers no longer run "the end", so fragment parsing never spins the event loop. * Scripts created by a fragment parser whose context document has scripting disabled are marked as already started, so that their clones don't run. * The HTML parser only processes an SVG script element at its end tag if the parser runs scripts and the element is connected and in the document the parser's scripts run in. In particular, document parsing no longer processes an SVG script element whose ancestor was removed, or that was moved to another document, before its end tag. Tests: web-platform-tests/wpt PR 61748. Fixes whatwg#2142.
Owner
Author
|
Closing since this was is an artifact to help create whatwg/spec-ai#12 . The new issue found was a bonus. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An experiment for a possible redesign option in the
spec-pr-reviewskill (whatwg/spec-ai). An AI agent rewrote the spec change ofwhatwg/html#12758from its base (a7f6aed), given only a brief: the intent, the constraints, the problems raised in review, and the tests. It didn't see the PR's text or thread. Not for merging.The diff here is against the base. Diff against the merged text (289f9189).
Verdict: structurally simpler, but not better. It reintroduces problems that review had already fixed, so a rewrite like this is input to a comparison, not a replacement.
Simpler:
Documentfield, vs seven parser fields plus a per-script intended document.Regressions, each a case the merged text handles:
createContextualFragment()in a scripting-disabled document never run, even after insertion into a normal document. This changes non-streaming behavior.loadevent leaves custom element reaction queues unbalanced.write()rather than from a task, so what's inserted afterabort()depends on network timing.The cause was the brief: it recorded those problems as fixed, without saying how, or which neighboring cases the fix had to cover.
Possible bug in the merged text: the resume and deferred-script tasks are queued on the original document's global. If the target moves to another document and the original document's iframe is then removed, they never run, so
close()never settles. (Custom elements in content dropped at aDocumenttarget can still be constructed, but document parsing does the same.)Worth porting to the merged text as follow-ups:
Documentscript execution document instead of the per-script field, undoing the XML and XSLT edits;For the skill: offer a blind redesign only as one option for a design question, always followed by a comparison and port-back into the existing text. The brief has to give each fixed problem as a must-pass case, with the generalization review settled on. Running the tests would catch some of the regressions, but needs an implementation.