Skip to content

TextEncoder.encodeInto('') returns the previous call's { read, written } #2173

Description

@Sheraff

Describe the bug

TextEncoder.prototype.encodeInto('') returns the result of the previous encodeInto call, from any encoder instance, instead of { read: 0, written: 0 }. Nothing is written to the destination, but callers that trust written read stale bytes.

We hit it through Yuku's WebAssembly parser (@yuku-core/wasm), which TanStack Router/Start is moving to: parsing an empty string parses leftover bytes, so Start server functions fail in WebContainers.

Link to the blitz that caused the error

https://stackblitz.com/github/Sheraff/webcontainer-encodeinto-repro

Steps to reproduce

Open the project. It runs npm start (index.js):

const a = new TextEncoder()
const b = new TextEncoder()
a.encodeInto('abc', new Uint8Array(9)) // { read: 3, written: 3 }
a.encodeInto('', new Uint8Array(4))    // { read: 3, written: 3 }
b.encodeInto('', new Uint8Array(4))    // { read: 3, written: 3 }

and prints BUG: encodeInto("") returns the previous call's { read, written } (WebContainer, Node v22.22.3).

Expected behavior

Both empty calls return { read: 0, written: 0 }, as in Node (v22.12.0, v24.8.0), where the project prints OK.

Parity with Local

  • I have run the project in my local machine and I could not reproduce the issue.

Platform

  • OS: Linux
  • Browser: Chromium (Playwright)
  • WebContainer: process.versions.webcontainer = 2ed8f36d

Additional context

Found while testing TanStack Router's Yuku migration in the tanstack.com example playground. Written with Claude Code (AI-assisted).

Activity

  1. github-actions commented on Oct 10, 2026

    @github-actions

    We noticed that you did not provide a StackBlitz or Bolt reproduction link. Please update the issue and add a link to a public project.

  2. Sheraff commented on Oct 10, 2026

    @Sheraff
    Author

    Added a dedicated public repro: https://stackblitz.com/github/Sheraff/webcontainer-encodeinto-repro prints BUG on start.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions