Skip to content

parseDate: false is not respected for WebSocket messages #257

Open

Description

@qimingweng

Description

When creating a treaty client with parseDate: false, HTTP responses correctly leave ISO date strings as strings. However, WebSocket messages still auto-convert ISO date strings to Date objects — the parseDate option is not forwarded to the WS message parser.

Reproduction

import { Elysia } from "elysia";
import { treaty } from "@elysiajs/eden";

const app = new Elysia()
  .get("/api/time", () => {
    return { time: "2026-04-09T12:00:00.000Z" };
  })
  .ws("/ws", {
    open(ws) {
      ws.send({ time: "2026-04-09T12:00:00.000Z" });
    },
    message() {},
  })
  .listen(0);

const port = app.server!.port;
const client = treaty<typeof app>(`http://localhost:\${port}`, {
  parseDate: false,
});

// HTTP: parseDate:false works
const { data } = await client.api.time.get();
console.log(typeof data!.time); // "string" ✓

// WS: parseDate:false is ignored
const ws = client.ws.subscribe();
ws.on("message", ({ data: wsData }) => {
  console.log(typeof wsData.time); // "object" ✗ (Date)
  console.log(wsData.time instanceof Date); // true ✗
  ws.close();
  app.stop();
});

Expected behavior

typeof wsData.time should be "string" when parseDate: false is set.

Actual behavior

wsData.time is a Date object — the parseDate: false config is ignored for WebSocket messages.

Root cause

Looking at the compiled source, the WS message deserializer (S function in chunk-I5KHAGLL.mjs) receives a config parameter r, and checks r?.parseDate === false. However the treaty client does not pass its config through when calling this function for WS messages.

Environment

  • @elysiajs/eden: 1.4.9
  • elysia: 1.4.27
  • bun: 1.3.11

Activity

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