fix(test, frontend): bound the workflow-snapshot render's cost under jsdom - #7999
Open
Neilk1021 wants to merge 7 commits into
Open
fix(test, frontend): bound the workflow-snapshot render's cost under jsdom#7999Neilk1021 wants to merge 7 commits into
Neilk1021 wants to merge 7 commits into
Conversation
…jsdom `report-generation.service.spec.ts` drives the real html2canvas, which clones the whole document rather than the element it is pointed at. The unit-test builder runs spec files with `isolate: false`, so one jsdom document is shared by every spec file in a worker and the clone drags in whatever DOM the files before it left behind. On the macOS runner that clone was measured at 12-37s against a 20s test timeout, failing "fails when the editor cannot be rendered" while ubuntu and windows passed. The job log carried 5,691 `Not implemented: window.getComputedStyle(elt, pseudoElt)` stack traces for six renders -- about 950 per clone, so roughly 475 foreign elements were being cloned each time. The same run locally emits 56. Two changes, both test-only: - The snapshot suite parks the document's existing body nodes for the duration of the file, so the clone's cost depends only on the DOM these tests build. It spans the file rather than each test because the renders outlive the tests that start them. - `jsdom-svg-polyfill.ts` stops jsdom announcing `getComputedStyle(elt, pseudoElt)` and `scrollTo` on the virtual console, which vitest forwards to `console.error` as a full stack trace per call. Dropping `pseudoElt` changes no behaviour: jsdom complains and then ignores it, returning the element's own declaration either way. Measured against a seeded 500-node document, the traces alone cost ~30% of clone time (18.8s -> 13.1s across the file's six renders). This continues apache#7886, which stopped the four image-inlining tests waiting on the render; the flake moved to the two tests that still await one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
Backport auto-label reportThis
|
Contributor
Automated Reviewer SuggestionsBased on the
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7999 +/- ##
============================================
+ Coverage 93.24% 93.34% +0.09%
Complexity 4677 4677
============================================
Files 1177 1179 +2
Lines 47685 47713 +28
Branches 5312 5314 +2
============================================
+ Hits 44466 44537 +71
+ Misses 1743 1719 -24
+ Partials 1476 1457 -19
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
`setupFiles` is re-evaluated once per spec file, so the two patches added for html2canvas's `notImplemented` traces wrapped their own wrapper on every evaluation -- 41 layers deep by the end of a full run. The file already guards its process-level handlers and its loader hook against the same accumulation. Mark the installed function and the installed `contentWindow` getter, and skip the patch when the mark is already there. The mark rides on what was installed rather than on a `globalThis` flag so that a jsdom window replaced mid-run is still patched -- a flag would suppress the re-patch and let the traces back in. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Neutering `scrollTo` on this window was dead code. html2canvas's only call against it is `restoreOwnerScroll`, guarded by `x !== pageXOffset || y !== pageYOffset`; jsdom has no layout, so both offsets are 0 and the call never happens. The call that does happen belongs to the clone iframe's window, which the `contentWindow` patch below already covers. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ents Dropping `pseudoElt` wholesale was not behaviour-preserving after all. jsdom tests the argument against `/^::(?:part|slotted)\(/i` and throws a `TypeError` before it reaches `notImplemented`, so a shadow-DOM pseudo-element would have been answered with the element's own declaration instead of the rejection. Nothing in `src` passes one today; forward those arguments so nothing has to. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
html2canvas clones from `documentElement`, so `<head>` is walked as well -- measured at 185 elements there against the body's 463. Park both, restoring each node to the parent it came from. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`DocumentCloner.destroy` runs only on the render's success path, so each render these tests leave failing strands its clone iframe in the body -- three of them by the time the suite ends. Removing them before the parked nodes go back keeps the next spec file's renders from cloning them. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`beforeAll` / `afterAll` inside this `describe` span the suite, and a render that outlives them sees the restored DOM either way. Say "suite". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
What changes were proposed in this PR?
report-generation.service.spec.tsdrives the real html2canvas, which clones the whole documentrather than the element it is pointed at. The unit-test builder runs spec files with
isolate: false, so one jsdom document is shared by every spec file in a worker and the clonedrags in whatever DOM the files before it left behind.
On the macOS runner that clone was measured at 12–37s against a 20s test timeout, failing
fails when the editor cannot be renderedwhile ubuntu and windows passed on the same commit.Two changes, both test-only:
report-generation.service.spec.ts— the snapshot suite parks the document's existing bodynodes for the duration of the file and restores them after, so the render's cost depends only on
the DOM these tests build. It spans the file rather than each test because the renders outlive
the tests that start them (visible in the failing log: clone Setting up the initial project architecture #1 finished during test add the textdb-sandbox project #3).
jsdom-svg-polyfill.ts— stops jsdom announcinggetComputedStyle(elt, pseudoElt)andscrollToon the virtual console, which vitest forwards toconsole.erroras a full stack traceper call. The failing job carried 5,691 of them for six renders. Dropping
pseudoEltchanges nobehaviour: jsdom complains and then ignores the argument, returning the element's own declaration
either way.
scrollTohas nothing to move — jsdom has no layout, and the one html2canvas reachesfor belongs to the throwaway clone iframe, so it is neutered as each
contentWindowis handed out.Any related issues, documentation, discussions?
Closes #8001.
This continues #7886 (closing #7887), which stopped the four image-inlining tests in this file
waiting on the render. The flake moved to the two tests that still await one.
Scope note for reviewers: this bounds the render's cost, it does not remove the dependency on a
real render. The two remaining tests still await html2canvas, so a sufficiently loaded runner
could in principle still be slow — just not by the two orders of magnitude measured here. Taking
#7886's logic to its conclusion (no test in this file waiting on a real render) would need a
stub html2canvas that survives
isolate: false, which is a larger change to what those two testscover; happy to do that instead if reviewers prefer it.
Unrelated pre-existing noise left alone: a full run still emits ~827 jsdom
HTMLCanvasElement.prototype.getContexttraces fromJointUIService.getMeasureContext(
joint-ui.service.ts:219). Silencing it would change whatmeasureTextreturns for thejoint-ui specs, so it is out of scope here.
How was this PR tested?
ng test --watch=falseon this branch (base444fc58284), four full runs: 201 files,5131 passed / 1 skipped each time, no
Not implemented: window.getComputedStyletraces.Clone time across the file's six renders was 79–353 ms on three warm runs; the test that was
timing out renders in 85–114 ms. The first run on a cold checkout was slower — up to 3.9s for a
clone — which is a reminder that machine load, not document size, is what is left.
The effect of the console noise was measured directly by seeding the document with 500 nodes:
clone time across the six renders went 18.8s → 13.1s with the polyfill change alone (~30%; the
share is larger where console forwarding is slower, as on CI).
yarn --cwd frontend format:ciis clean.I cannot demonstrate the macOS leg green from here — that needs CI on this branch.
Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 5 [1M context])