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

Restrict Presence Type to JSON Serializable Types #591

Open
chacha912 opened this issue Jul 27, 2023 · 1 comment
Open

Restrict Presence Type to JSON Serializable Types #591

chacha912 opened this issue Jul 27, 2023 · 1 comment
Labels
cleanup 🧹 Paying off technical debt

Comments

@chacha912
Copy link
Contributor

Description:

Currently, the presence type is defined to extend Indexable, and when transmitting presence via protobuf, it is converted to a string using JSON.stringify.

The current type <P extends Indexable> allows any type as its value since type Indexable = Record<string, any>. Consequently, values that are not JSON serializable, such as byte array, Date, and Long, may not work correctly. Therefore, it is essential to restrict the type of P(presence) to only allow JSON serializable types not Indexable.

Reference) JSON type used in other libraries:

export type Json = string | number | boolean | null | { [key: string]: Json } | Json[];
  • JSON type defined in liveblocks:
export type Json = JsonScalar | JsonArray | JsonObject;
export type JsonScalar = string | number | boolean | null;
export type JsonArray = Json[];
export type JsonObject = { [key: string]: Json | undefined };

Why:
Using non-JSON serializable values in the presence type may lead to unexpected behavior.

@hackerwins hackerwins added the cleanup 🧹 Paying off technical debt label Jul 27, 2023
@hackerwins
Copy link
Member

Feel free to send a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup 🧹 Paying off technical debt
Projects
None yet
Development

No branches or pull requests

2 participants