Skip to content

Upgrade happy-dom past 20.11, whose Element.animate leaks unhandled rejections #1621

Open

Description

@joshunrau

happy-dom is held at ~20.11.15 in the catalog by the dependency update on the deps branch. It provides the environment for the web and react-core vitest projects. The newest release eligible under the repo's 7-day minimumReleaseAge on 2026-10-04 was 20.14.5.

Why it was not upgraded

happy-dom 20.12.0 added the Web Animations API (Element.animate), and motion 13 now detects it and animates through native Animation objects.

  • When motion cancels one, happy-dom's Animation.cancel() rejects the finished promise with an AbortError.
  • happy-dom leaves that rejection unhandled. The spec marks the cancelled finished promise as handled, so real browsers stay silent.

Under vitest, this produces:

Vitest caught 6 unhandled errors during the test run.
AbortError: The animation was canceled.
 ❯ Animation.cancel happy-dom@20.14.5/lib/animation/Animation.js:161:32
 ❯ NativeAnimationExtended.cancel motion-dom@13.4.4/dist/es/animation/NativeAnimation.mjs:75:28

The errors come from CopyButton.test.tsx, InstrumentSummary.test.tsx and ScalarInstrumentRenderer.test.tsx in packages/react-core. Every test passes, but pnpm test exits 1. No matching happy-dom issue was found.

What is required

Either:

  • report this to happy-dom, and bump once cancel() marks finished as handled, or
  • keep motion off native animations in tests, for example by setting MotionGlobalConfig.skipAnimations = true in a vitest setup file shared by web and react-core. There are currently no setup files (apps/web/AGENTS.md), so this would add the first.

Then move the catalog entry back to a caret range and run pnpm test.

Activity

  1. added
    Priority: Low
    Difficulty: Low
    Chore
    Area: Web
    Area: Shared
    Upstream
    on Oct 5, 2026
  2. joshunrau commented on Oct 26, 2026

    @joshunrau
    CollaboratorAuthor

    Still applies on main (d86740e). happy-dom is still ~20.11.15 (pnpm-workspace.yaml:35), and no happy-dom release fixes cancel() yet.

    Upstream

    There is already a report, filed before this issue: capricorn86/happy-dom#2339 (2026-09-01). capricorn86/happy-dom#2412 reports the same bug again. The fix is capricorn86/happy-dom#2340, which marks finished as handled and replaces it on cancel. All three are open, and the PR has one community approval and no review from the maintainer. lib/animation/Animation.js is identical in 20.14.6 and 21.0.4 (the latest, 2026-10-20), so a bump alone does not help. There is no date for an upstream fix, so I'd add a test-side workaround now and remove it once capricorn86/happy-dom#2340 ships.

    Patch happy-dom, not motion

    MotionGlobalConfig.skipAnimations covers less than it looks:

    • It only reaches motion 13.4.4. libui 6.16.1 depends on motion ^11.18.2, which is installed as a separate framer-motion@11.18.2 with its own MotionGlobalConfig. That copy detects WAAPI the same way (Object.hasOwnProperty.call(Element.prototype, "animate")), and its AcceleratedAnimation.cancel() cancels the native animation. libui's CopyButton, NotificationHub and DatePicker animate opacity through it, so they can leak the same error.
    • It changes what every test exercises: values jump to their last keyframe and exits finish at once. InstrumentShowcase.test.tsx:96-102 turns it on for one suite on purpose.

    Filtering the error in vitest's onUnhandledError would also hide a real unawaited finished rejection. The narrower fix is to add the spec step that happy-dom skips:

    // The Web Animations spec marks the rejected `finished` promise as handled on cancel; happy-dom does not
    // (capricorn86/happy-dom#2339). Remove once a release includes capricorn86/happy-dom#2340.
    // eslint-disable-next-line @typescript-eslint/unbound-method -- called below with the animation as `this`
    const { cancel } = Animation.prototype;
    Animation.prototype.cancel = function (this: Animation) {
      this.finished.catch(() => undefined);
      cancel.call(this);
    };

    A caller that awaits finished still gets the AbortError, and both motion copies are covered. cancel() is the only place happy-dom rejects finished, and Element.animate() constructs window.Animation, which vitest copies onto globalThis. The eslint-disable is required: @typescript-eslint/unbound-method is on and flags the destructuring.

    Plan

    Land this after #1660. That PR touches every vitest.config.ts (Vitest 5, named baseConfig export) and pnpm-workspace.yaml, and adds a bullet directly below the "no setup files" line in testing-strategy.md. It is currently CONFLICTING.

    1. Add the module as packages/react-core/src/testing/happy-dom.ts. List it in test.setupFiles in packages/react-core/vitest.config.ts and apps/web/vitest.config.ts. It needs no coverage exclude, and it imports nothing from vitest, so odc/test-tooling-in-tests-folder passes. Leave the other projects out. The ones that opt into happy-dom per file also run node-environment files, which have no Animation, so the module would throw there.
    2. Bump the catalog to ^21.0.3, which already clears minimumReleaseAge (21.0.4 clears it on 2026-10-27). The only breaking change in 21.0.0 turns CSS and iframe page loading off by default and deprecates disableIframePageLoading. Drop that flag and its comment from packages/react-core/vitest.config.ts:11-13. happy-dom still logs a NotSupportedError per iframe, so in packages/react-core/AGENTS.md:140-142 only the sentence about the flag changes. If you'd rather not take the major here, ^20.14.6 works too. Steps 1 and 2 must land together, because 20.11.15 has no Animation and the module would throw.
    3. Update every place that says there are no setup files: .agents/docs/architecture/testing-strategy.md:64, apps/web/AGENTS.md:184, and the same comment in six web tests (git grep -n "no vitest setup files"). Their conclusion still holds: RTL won't auto-unmount, because the setup does not call cleanup. Document the setup file in the Tests section of packages/react-core/AGENTS.md.

    Tests

    • packages/react-core/src/testing/__tests__/happy-dom.test.ts, which runs under the setup file:
      • Cancel a running document.body.animate(...) without reading finished, wait a macrotask, and assert that a process.on('unhandledRejection') listener was not called. This is the test that fails without the patch.
      • Keep finished, cancel, and assert it still rejects with name: 'AbortError'.
    • The regression check is the existing CopyButton.test.tsx, InstrumentSummary.test.tsx and ScalarInstrumentRenderer.test.tsx. pnpm test must exit 0 without Vitest caught … unhandled errors.
    • No new e2e spec. Playwright runs real browsers, which already mark the promise as handled, so a spec has nothing to drive. This needs an exception to the e2e rule like the ones in build: upgrade dependencies held back by breaking changes #1660. Run the existing suite.

    Triage note written with Claude Code. Code references point at main @ d86740e.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: SharedArea: WebChoreDifficulty: LowPriority: LowUpstream

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions