Skip to content

Re-enable useFetchStreams in the updated WebChannel release #8259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 18, 2024
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
Loading