Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 80cd6ee The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
sravan27
force-pushed
the
fix-sync-streams-length-code-points
branch
from
June 6, 2026 15:54
e6f94fe to
f0033dc
Compare
sravan27
force-pushed
the
fix-sync-streams-length-code-points
branch
from
June 6, 2026 16:12
f0033dc to
5842027
Compare
sravan27
pushed a commit
to sravan27/powersync-service
that referenced
this pull request
Jun 6, 2026
substring() used String.prototype.substring and .length, which count UTF-16 code units. For non-BMP code points (emoji 😀, CJK Extension B-G, ancient scripts) slicing in the middle of a surrogate pair returned a broken unpaired surrogate. Server-side substring output silently disagreed with SQLite client output. Same silent-failure class as merged powersync-ja#644 / powersync-ja#645 / powersync-ja#646 / powersync-ja#647 and open PRs powersync-ja#662 (JOIN) / powersync-ja#663 (ASCII upper/lower) / powersync-ja#664 (length code points).
…QLite JS String.prototype.length counts UTF-16 code units. SQLite length() returns characters (code points). For any non-BMP code point (emoji 😀, CJK Extension B-G, ancient scripts) the two diverge: 2 units vs 1 character. Bucket-key expressions like length(name) silently routed rows to the wrong bucket. Same silent-failure class as merged powersync-ja#644 / powersync-ja#645 / powersync-ja#646 / powersync-ja#647, open powersync-ja#565 JOIN PR powersync-ja#662 and ASCII upper/lower PR powersync-ja#663.
sravan27
force-pushed
the
fix-sync-streams-length-code-points
branch
from
June 7, 2026 09:12
5842027 to
80cd6ee
Compare
sravan27
added a commit
to sravan27/powersync-service
that referenced
this pull request
Jun 7, 2026
substring() used String.prototype.substring and .length, which count UTF-16 code units. For non-BMP code points (emoji 😀, CJK Extension B-G, ancient scripts) slicing in the middle of a surrogate pair returned a broken unpaired surrogate. Server-side substring output silently disagreed with SQLite client output. Same silent-failure class as merged powersync-ja#644 / powersync-ja#645 / powersync-ja#646 / powersync-ja#647 and open PRs powersync-ja#662 (JOIN) / powersync-ja#663 (ASCII upper/lower) / powersync-ja#664 (length code points).
Contributor
Author
|
recheck |
Contributor
Author
|
Acknowledged — closing reasoning carries over from #663 (Unicode-aware JS over ASCII-only SQLite is the preferred direction for the engine). Will park the SQLite-matching framing and look at the inverse: client-side overrides in powersync-js so the wa-sqlite client matches the Service's Unicode behavior. Thanks for the time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Same silent-data-loss class as the merged Sync Streams fixes #644 / #645 / #646 / #647, the open #565 JOIN loud-error PR #662, and the ASCII upper/lower PR #663.
The bug
length()on text returnedvalue.length— JavaScript'sString.prototype.length, which counts UTF-16 code units. SQLite'slength(X)returns the number of characters (Unicode code points).For any string containing a non-BMP code point (emoji like
😀, CJK Extension B–G, ancient scripts) the two counts diverge: each non-BMP code point is one UTF-16 surrogate pair = 2 code units in JS but 1 character in SQLite.length()(JS)length()(SQLite)"hello"55"straße"66"😀"21"a😀b"43"𐀀"(Linear B)21A bucket-parameter or filter using
length(...)silently routed any row containing such characters to a different bucket than the client query asks for.Fix
A tiny
countCodePoints(text)helper that iterates the string withfor…of(which walks code points, not code units) andlengthuses it for the text case. The blob branch already matches SQLite (byte length).Tests
New
syncTest('length() counts Unicode code points, not UTF-16 code units (matches SQLite)')insqlite_semantics.test.tscovering:"hello"→5n(ASCII control)"straße"→6n(BMP non-ASCII, unchanged)"😀"→1n(was2n)"a😀b"→3n(was4n)"𐀀"(U+10000, Linear B) →1n(was2n)Full
sync_rules.test.ts: 40/40.