Skip to content

fix!: allow mutating happy-dom/jsdom window object#10373

Draft
hi-ogawa wants to merge 2 commits into
vitest-dev:mainfrom
hi-ogawa:fix-allow-mutating-happy-dom-jsdom-window-object
Draft

fix!: allow mutating happy-dom/jsdom window object#10373
hi-ogawa wants to merge 2 commits into
vitest-dev:mainfrom
hi-ogawa:fix-allow-mutating-happy-dom-jsdom-window-object

Conversation

@hi-ogawa
Copy link
Copy Markdown
Collaborator

@hi-ogawa hi-ogawa commented May 18, 2026

Description

I'm somewhere between

  • ignore this happy-dom specific behavior and close issues
  • just hard-code known specific combinations e.g. happy-dom + innerWidth and allow mutation
  • go all-in and allow mutations always (this is what this PR does)

The reason why I don't care much on changing this is that mutating innerWidth and affecting matchMedia isn't possible in real dom. They aren't completely non-writable either but dom spec has rather odd handling that if you write window.innerWidth = ..., then you just read the written value afterwards that is different from window's actual innerWidth.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 18, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 462ea56
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a0ab5f5713c1200086d4806
😎 Deploy Preview https://deploy-preview-10373--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@sheremet-va
Copy link
Copy Markdown
Member

Cannot find many issues with this approach, to be honest

@hi-ogawa hi-ogawa changed the title fix: allow mutating happy-dom/jsdom window object fix!: allow mutating happy-dom/jsdom window object May 29, 2026
Comment on lines +81 to +89
// propagate changes to underlying window implementation,
// which can affect other window API behavior internally, e.g.
// updating `innerWidth` affects `matchMedia("(max-width: *)")` on happy-dom.
try {
win[key] = v
}
catch {
// haven't found a case it throws but just in case
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed that we can just remove try/catch to surface if there's any setter error.

@hi-ogawa hi-ogawa self-assigned this May 29, 2026
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.

Setting window.innerWidth doesn't actually set innerWidth on happy-dom's window object

2 participants