Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
huseeiin opened this issue Feb 15, 2025 · 7 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@huseeiin
Copy link
Contributor

Duplicates

  • I have searched the existing issues

Latest version

  • 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 huseeiin added bug Something isn't working needs triage labels Feb 15, 2025
@huseeiin
Copy link
Contributor Author

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

@brenelz
Copy link
Contributor

brenelz commented Feb 15, 2025

Could you maybe PR a failing test for this?

@lxsmnsyc
Copy link
Member

lxsmnsyc commented Feb 16, 2025

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.

@huseeiin
Copy link
Contributor Author

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

@lxsmnsyc
Copy link
Member

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

@huseeiin
Copy link
Contributor Author

no-fix

what does no-fix mean?

@lxsmnsyc
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants