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

Empty map can't be streamed? #26

Closed
caprica opened this issue May 8, 2024 · 3 comments
Closed

Empty map can't be streamed? #26

caprica opened this issue May 8, 2024 · 3 comments

Comments

@caprica
Copy link
Contributor

caprica commented May 8, 2024

I am using Remix.run which I understand uses v2.0.0 of this library for sending responses between server and client. I am not sure if this an issue for Remix, or if it belongs here.

I have an object that contains two maps, either of them could be empty.

When I log the object prior to serialisation it looks like this:

features: {
    activated: Map(0) {},
    notActivated: Map(2) {
      'someCoolFeature' => false,
      'anotherCoolFeature' => false,
    }
  }

Remix reports this and the page fails to render:

Unable to decode turbo-stream response from [whatever url]

If I return null instead of empty map:

features: {
    activated: null,
    notActivated: Map(2) {
      'someCoolFeature' => false,
      'anotherCoolFeature' => false,
    }
  }

This has no error and the page renders correctly, although I would rather deal with an empty map instead of a null.

So the question is should empty maps be serialisable?

@caprica
Copy link
Contributor Author

caprica commented May 8, 2024

In turbo-stream.ts I see this when it tries to parse the JSON for the current line:

read.value = [["M",]]
reason =  SyntaxError: Unexpected token ] in JSON at position 6

Whereas a non-empty map:

[["M",1,2,3,4],"foo","bar","baz","qux"]

@jacob-ebey
Copy link
Owner

Fixed by #27

@jacob-ebey
Copy link
Owner

jacob-ebey commented May 30, 2024

Closing for now. Please re-open if the issue persists. Thanks for investigating and the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants