Skip to content

fix(browser): preserve undefined command arguments - #10923

Open
nguyennvk wants to merge 4 commits into
vitest-dev:mainfrom
nguyennvk:fix/unparsed-undefined
Open

fix(browser): preserve undefined command arguments#10923
nguyennvk wants to merge 4 commits into
vitest-dev:mainfrom
nguyennvk:fix/unparsed-undefined

Conversation

@nguyennvk

Copy link
Copy Markdown

Description

Custom browser commands CANNOT read undefined arguments crossing the browser → Node RPC boundary. The entry was dropped from the argument array, shifting later arguments left. Example:

commands.myCustomCommand(undefined, 'file.ts')
// server received: { arg1: 'file.ts', arg2: undefined }

Cause

Line 136 in packages/browser/src/client/tester/tester-utils.ts

args = args.filter(arg => arg !== undefined);

This line filter out undefined values.

Fix

Remove that line and add a mapping in packages/browser/src/node/rpc.ts
to map null to undefined to match the test case created by @AriPerkkio

Tests

Includes the failing test from #10865 (authored by @AriPerkkio), which
now passes.

Resolves #10864

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

netlify Bot commented Aug 11, 2026

Copy link
Copy Markdown

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 870342d
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a7b6598501477000847013d
😎 Deploy Preview https://deploy-preview-10923--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.

Comment thread packages/browser/src/node/rpc.ts Outdated
AriPerkkio and others added 3 commits August 12, 2026 14:43
@nguyennvk
nguyennvk force-pushed the fix/unparsed-undefined branch from a2ac921 to ae2f72f Compare August 12, 2026 07:43
}
},
async triggerCommand(sessionId, command, testPath, payload) {
payload = payload.map(value => value === null ? undefined : value)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not where the fix should be. We should fix the serialisation instead (serialise/deserialise that we pass to birpc)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The serialization and deserialization is implemented in rpc.ts. I found that the serialization used functions from a package name "flatted". In order to achieve what we want, those functions need to be reimplemented.
Screenshot 2026-08-20 at 11 16 06 AM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, both stringify and parse accept a custom serializer. We could maybe provide a "hidden" value like "__VITEST_UNDEFINED__" to transform into undefined? Although I thought that flatted already supports undefined 🤔

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.

Custom commands shifts arguments when any value is undefined

3 participants