diff --git a/.changeset/sharp-dingos-admire.md b/.changeset/sharp-dingos-admire.md new file mode 100644 index 00000000000..aeb1b082ad5 --- /dev/null +++ b/.changeset/sharp-dingos-admire.md @@ -0,0 +1,5 @@ +--- +"@firebase/firestore": patch +--- + +Re-enable useFetchStreams with the latest WebChannel implementation. This reduces the memory usage of WebChannel. diff --git a/packages/firestore/src/platform/browser/webchannel_connection.ts b/packages/firestore/src/platform/browser/webchannel_connection.ts index aa790f0ac2b..83e8faef88a 100644 --- a/packages/firestore/src/platform/browser/webchannel_connection.ts +++ b/packages/firestore/src/platform/browser/webchannel_connection.ts @@ -27,7 +27,6 @@ import { EventTarget, StatEvent, Event, - FetchXmlHttpFactory, Stat } from '@firebase/webchannel-wrapper/webchannel-blob'; @@ -209,7 +208,7 @@ export class WebChannelConnection extends RestConnection { } if (this.useFetchStreams) { - request.xmlHttpFactory = new FetchXmlHttpFactory({}); + request.useFetchStreams = true; } this.modifyHeadersForRequest( diff --git a/packages/firestore/test/integration/api/query.test.ts b/packages/firestore/test/integration/api/query.test.ts index c7681fb56c9..01fd0e47e35 100644 --- a/packages/firestore/test/integration/api/query.test.ts +++ b/packages/firestore/test/integration/api/query.test.ts @@ -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 => {