Skip to content

Commit

Permalink
fix(client): Fix text encoding polyfill being fed numbers (#1204)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
msfstef authored Apr 29, 2024
1 parent 1b79344 commit 244066a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/two-ties-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electric-sql": patch
---

Fix TextEncoder polyfill being fed numbers rather than strings and breaking replication of number types
2 changes: 1 addition & 1 deletion clients/typescript/src/satellite/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down

0 comments on commit 244066a

Please sign in to comment.