solid-start icon indicating copy to clipboard operation
solid-start copied to clipboard

[Bug?]: Buffer is converted to an array-like object on the client-side

Open huseeiin opened this issue 10 months ago • 7 comments

Duplicates

  • [x] I have searched the existing issues

Latest version

  • [x] I have tested the latest version

Current behavior 😯

{0: 102, 1: 240, 2: 142, 3: 156, 4: 217, 5: 251, 6: 19, 7: 196, 8: 113, 9: 88, 10: 46, 11: 27, 12: 246, 13: 206, 14: 74, 15: 43}

Expected behavior 🤔

[102,240,142,156,217,251,19,196,113,88,46,27,246,206,74,43]

Steps to reproduce 🕹

import { createAsync, query } from "@solidjs/router";
import { randomBytes } from "node:crypto";

const getData = query(async () => {
  "use server";
  return randomBytes(16);
}, "data");

export default function Home() {
  const data = createAsync(() => getData());
  console.log(data());

  return (
    <>
      <div>Hello World</div>
    </>
  );
}

go to chrome console and you'll see

Context 🔦

this didn't happen before solidstart started using tanstack server functions

Your environment 🌎


huseeiin avatar Feb 15 '25 19:02 huseeiin

this issue should probably be moved to @tanstack/server-functions-plugin instead

huseeiin avatar Feb 15 '25 19:02 huseeiin

Could you maybe PR a failing test for this?

brenelz avatar Feb 15 '25 23:02 brenelz

this issue should probably be moved to @tanstack/server-functions-plugin instead

this is a seroval behavior so this is fine. (@tanstack/server-functions-plugin doens't define the serializer, we do)

Now for why this happens. The reason Buffer instances aren't serialized into an array is because Buffers aren't really arrays, Buffers are typed arrays (specifically, Uint8Array). Although interestingly enough, it's not serialized as a Uint8Array because seroval doesn't check for class inheritance, so the serialization now falls back to plain object serialization (which is why it is an object in the log). I'm honestly not sure if I should change the behavior or not, because it impacts the perf badly.

lxsmnsyc avatar Feb 16 '25 02:02 lxsmnsyc

this issue should probably be moved to @tanstack/server-functions-plugin instead

this is a seroval behavior so this is fine. (@tanstack/server-functions-plugin doens't define the serializer, we do)

Now for why this happens. The reason Buffer instances aren't serialized into an array is because Buffers aren't really arrays, Buffers are typed arrays (specifically, Uint8Array). Although interestingly enough, it's not serialized as a Uint8Array because seroval doesn't check for class inheritance, so the serialization now falls back to plain object serialization (which is why it is an object in the log). I'm honestly not sure if I should change the behavior or not, because it impacts the perf badly.

it should definitely be a Uint8Array

huseeiin avatar Feb 16 '25 08:02 huseeiin

I'll leave that open-ended when we expose the Plugin API. This will be no-fix in seroval

lxsmnsyc avatar Feb 16 '25 17:02 lxsmnsyc

no-fix

what does no-fix mean?

huseeiin avatar Feb 16 '25 19:02 huseeiin

it means I won't change the current behavior in seroval. Once the Plugin API is exposed in SolidStart, I'll let users decide how to serialize Buffers

lxsmnsyc avatar Feb 17 '25 03:02 lxsmnsyc

seroval issue

huseeiin avatar Jul 03 '25 13:07 huseeiin