From 244066af8a86fc9976fee6d99a4ffaa3d56ecbfa Mon Sep 17 00:00:00 2001 From: Stefanos Mousafeiris Date: Mon, 29 Apr 2024 17:16:31 +0300 Subject: [PATCH] fix(client): Fix text encoding polyfill being fed numbers (#1204) Addressing issue [raised in discord](https://discord.com/channels/933657521581858818/1231997358133477477) The `TextEncoderLite` polyfill for the TextEncoder does not coerce its input to a string, and we force cast numbers with `as string` in the encoding stage, resulting in the input being encoded as an empty bytearray. This does mean that the polyfill does not have the _exact_ same behaviour as the original (which it should), but the immediate solution is to respect types and not force cast to a string when it isn't. --- .changeset/two-ties-scream.md | 5 +++++ clients/typescript/src/satellite/client.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/two-ties-scream.md diff --git a/.changeset/two-ties-scream.md b/.changeset/two-ties-scream.md new file mode 100644 index 0000000000..870aad7523 --- /dev/null +++ b/.changeset/two-ties-scream.md @@ -0,0 +1,5 @@ +--- +"electric-sql": patch +--- + +Fix TextEncoder polyfill being fed numbers rather than strings and breaking replication of number types diff --git a/clients/typescript/src/satellite/client.ts b/clients/typescript/src/satellite/client.ts index cc2900f9cd..60e202f952 100644 --- a/clients/typescript/src/satellite/client.ts +++ b/clients/typescript/src/satellite/client.ts @@ -1410,7 +1410,7 @@ function serializeColumnData( case PgBasicType.PG_BYTEA: return columnValue as Uint8Array default: - return typeEncoder.text(columnValue as string) + return typeEncoder.text(String(columnValue)) } }