Skip to content

Align classic script and resource lifecycles - #4324

Open
domenic wants to merge 4 commits into
mainfrom
codex/align-classic-script-processing
Open

domenic wants to merge 4 commits into
mainfrom
codex/align-classic-script-processing

Conversation

@domenic

@domenic domenic commented Sep 16, 2026

Copy link
Copy Markdown
Member

Continue jsdom's lifecycle conformance work by aligning classic-script processing and resource cancellation with HTML's document-loading model.

domenic and others added 4 commits September 16, 2026 10:15
Replace the per-document resource loader, request manager, and generic resource queues with document-scoped cancellation and load-event delays. Fetch subresources through the dispatcher and let each element own its processing and events, instead of serializing unrelated images, stylesheets, and frames behind scripts.

Implement the force-async flag and ordered dynamic scripts, capture inline source and the preparation-time document, and queue errors for empty or invalid script URLs. Suppress execution of prepared scripts whose node document no longer matches their preparation-time document, while allowing scripts moved back before execution. Ignore destructive external-script document.write() calls when there is no parser insertion point.

Separate internal parsing completion from document.close(), which only finishes a script-created parser. Avoid replaying readiness and load events on repeated close calls. Deliver iframe load when its document finishes loading, including after document.open() during DOMContentLoaded, and suppress recursive iframe load events when reopening from an iframe load handler.

Abort pending subresource and XHR requests in descendant documents when stopping a window, without firing resource completion events for canceled requests. Suppress pending parser completion events after abort. Give subsequent requests a fresh cancellation lifetime, and preserve already-fetched ordered dynamic scripts while releasing canceled scripts from the execution order. Use explicit abort listeners until the AbortSignal.any() issue at nodejs/node#65995 is fixed in supported Node.js versions.

Wait for nested stylesheet imports, ignore import cycles, and fire one event for the owning element after imports finish. Both link and style fire load even when an import fails, matching Chromium and WebKit; top-level link fetch failures still fire error. Cover the import-event behavior with a tentative WPT because HTML's critical-subresource integration remains underspecified: whatwg/html#968. Restrict script-blocking stylesheet eligibility to parser-created elements, with link eligibility determined at creation. Cancel obsolete image and stylesheet requests so late responses cannot replace newer content.

The parsers still cannot pause for external scripts, so parsing-blocking scripts remain chained in parser order. Incremental document.write(), fragment-script initialization, and full VM microtask checkpoints remain incomplete.

Enable upstream dynamic-markup-insertion coverage, add lifecycle WPTs and script/resource benchmarks, and run tentative to-upstream WPTs while continuing to exclude upstream tentative tests.

Co-authored-by: codex <codex@openai.com>
Remove stale failure expectations for custom-element reaction ordering and DOMParser document URLs after the script and document lifecycle changes.

Expect the document.open() image-error failure only when canvas is available. Without canvas, images are not loaded and the test cannot exercise the missing event-listener erasure.

Record the location test's early iframe load failure and the postMessage test's timing-dependent failure. Our non-blocking parser can create and load an iframe before preceding scripts have defined its load handler.

Co-authored-by: codex <codex@openai.com>
Our parser does not pause for parsing-blocking scripts, so child frames can post their results before the parent installs its message handler. Mark both affected synchronous XHR tests flaky across Node.js versions until parser blocking is implemented.

Co-authored-by: codex <codex@openai.com>
Record timing-sensitive frame, image, stylesheet, and async-script tests while tokenization continues past blocking scripts. Include two expected failures that can unexpectedly pass when harness loading wins the race.

Link parser dependencies to #2413, and distinguish the upstream DOMParser and script-text test races that also need test fixes.

Co-authored-by: codex <codex@openai.com>
@domenic

domenic commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

The number of tests this moves to flaky makes me hesitate. It's a result of no longer serializing all resources into a single queue. Without parser-blocking script support, that might regress jsdom users.

I might hold off on merging this until we can get parser-blocking script work on top of it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant