Skip to content

Commit

Permalink
fix "TextEncoder undefined" issue in some platforms (#8765)
Browse files Browse the repository at this point in the history
  • Loading branch information
milaGGL authored Feb 5, 2025
1 parent 313faf6 commit 5250e80
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/firestore/src/util/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import { randomBytes } from '../platform/random_bytes';
import { newTextEncoder } from '../platform/text_serializer';

import { debugAssert } from './assert';

Expand Down Expand Up @@ -77,8 +78,8 @@ export interface Equatable<T> {
/** Compare strings in UTF-8 encoded byte order */
export function compareUtf8Strings(left: string, right: string): number {
// Convert the string to UTF-8 encoded bytes
const encodedLeft = new TextEncoder().encode(left);
const encodedRight = new TextEncoder().encode(right);
const encodedLeft = newTextEncoder().encode(left);
const encodedRight = newTextEncoder().encode(right);

for (let i = 0; i < Math.min(encodedLeft.length, encodedRight.length); i++) {
const comparison = primitiveComparator(encodedLeft[i], encodedRight[i]);
Expand Down

0 comments on commit 5250e80

Please # to comment.