Skip to content

Commit

Permalink
Re-enable useFetchStreams in the updated WebChannel release (#8259)
Browse files Browse the repository at this point in the history
* Re-enable useFetchStreams in the updated WebChannel release. Added a test for the fixed WebChannel issue with reading multi-byte characters that are split across multiple streaming chunks.
  • Loading branch information
MarkDuckworth committed Sep 18, 2024
1 parent 629919e commit ff0475c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-dingos-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/firestore": patch
---

Re-enable useFetchStreams with the latest WebChannel implementation. This reduces the memory usage of WebChannel.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
EventTarget,
StatEvent,
Event,
FetchXmlHttpFactory,
Stat
} from '@firebase/webchannel-wrapper/webchannel-blob';

Expand Down Expand Up @@ -209,7 +208,7 @@ export class WebChannelConnection extends RestConnection {
}

if (this.useFetchStreams) {
request.xmlHttpFactory = new FetchXmlHttpFactory({});
request.useFetchStreams = true;
}

this.modifyHeadersForRequest(
Expand Down
45 changes: 45 additions & 0 deletions packages/firestore/test/integration/api/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,51 @@ apiDescribe('Queries', persistence => {
});
}
).timeout('90s');

it('can query large documents with multi-byte character strings', () => {
function randomMultiByteCharString(length: number): string {
const charCodes: number[] = [];

for (let i = 0; i < length; i++) {
charCodes.push(randInt(1, 65535));
}

return String.fromCharCode(...charCodes);
}

function randInt(min: number, max: number): number {
const scale = max - min + 1;
return Math.floor(Math.random() * scale);
}

let bigString = randomMultiByteCharString(10000);

// Encode and decode `bigString` to/from UTF-8 to
// ensure that any transformations applied during
// UTF-8 encoding are applied equally to the expected
// and actual results.
const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();
bigString = textDecoder.decode(textEncoder.encode(bigString));

const doc = {
field: bigString
};

expect(bigString).to.deep.equal(bigString);

return withTestCollection(
persistence,
{ 1: doc },
async collectionReference => {
const querySnap = await getDocs(collectionReference);
expect(querySnap.size).to.equal(1);

const fieldValue = querySnap.docs[0].get('field');
expect(fieldValue).to.deep.equal(bigString);
}
);
});
});

apiDescribe('Hanging query issue - #7652', persistence => {
Expand Down

0 comments on commit ff0475c

Please sign in to comment.