Skip to content

Serialization bug when uploading files in browser mode #9165

Description

@olivier-thatch

Describe the bug

When uploading a file in browser mode using the Interactivity API, the file size and contents do not match what's being uploaded.

Specifically, when uploading a file using this test code:

  // 1. Create a file with exactly 4 bytes of content
  const fileContent = 'test';
  const file = new File([fileContent], 'test.pdf', { type: 'application/pdf' });

  // 2. Perform the upload using the Vitest Browser Mode Interactivity API
  const input = screen.getByTestId('file-input');
  await input.upload(file);

The uploaded file as seen from the component's point of view is a 23-bytes long binary string.

I have written a minimal reproduction.

Some additional information:

  • the bug occurs on my local machine (2023 MacBook Pro) but not on StackBlitz. It might be specific to macOS / Apple Silicon.
  • the bug is not browser specific: I have reproduced it with Chromium, Firefox and Safari.
  • the incorrect length and contents change with the MIME type
  • using an actual file instead of an in-memory File instance does not trigger the bug
  • using DataTransfer and dispatchEvent does not trigger the bug
Image

Reproduction

https://github.com/olivier-thatch/vitest-upload-bug

https://stackblitz.com/~/github.com/olivier-thatch/vitest-upload-bug

System Info

System:
    OS: macOS 26.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 1.06 GB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.18.0 - /Users/olivier/.nodenv/versions/22.18.0/bin/node
    Yarn: 4.11.0 - /Users/olivier/.nodenv/versions/22.18.0/bin/yarn
    npm: 11.6.2 - /Users/olivier/.nodenv/versions/22.18.0/bin/npm
    pnpm: 10.20.0 - /Users/olivier/.nodenv/versions/22.18.0/bin/pnpm
    Watchman: 2025.11.10.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 143.0.7499.40
    Firefox: 145.0.2
    Safari: 26.1
  npmPackages:
    @vitejs/plugin-react: ^5.1.1 => 5.1.1
    @vitest/browser: ^3.2.4 => 3.2.4
    @vitest/ui: ^3.2.4 => 3.2.4
    playwright: ^1.57.0 => 1.57.0
    vite: ^7.2.4 => 7.2.6
    vitest: ^3.2.4 => 3.2.4
    vitest-browser-react: ^1.0.1 => 1.0.1

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions