diff --git a/packages/next/src/shared/lib/bloom-filter.ts b/packages/next/src/shared/lib/bloom-filter.ts index 76be6cfdffaca1..28032d354d96ed 100644 --- a/packages/next/src/shared/lib/bloom-filter.ts +++ b/packages/next/src/shared/lib/bloom-filter.ts @@ -19,11 +19,6 @@ export class BloomFilter { bitArray: number[] constructor(numItems: number, errorRate: number) { - if (typeof window === 'undefined' && errorRate < 0.01) { - console.warn( - `Creating filter with error rate less than 1% (0.01) can increase the size dramatically proceed with caution. Received error rate ${errorRate}` - ) - } this.numItems = numItems this.errorRate = errorRate this.numBits = Math.ceil( @@ -31,6 +26,21 @@ export class BloomFilter { ) this.numHashes = Math.ceil((this.numBits / numItems) * Math.log(2)) this.bitArray = new Array(this.numBits).fill(0) + + if (typeof window === 'undefined') { + if (errorRate < 0.01) { + const filterData = JSON.stringify(this.export()) + const gzipSize = require('next/dist/compiled/gzip-size').sync( + filterData + ) + + if (gzipSize > 1024) { + console.warn( + `Creating filter with error rate less than 1% (0.01) can increase the size dramatically proceed with caution. Received error rate ${errorRate} resulted in size ${gzipSize} bytes (gzip)` + ) + } + } + } } static from(items: string[], errorRate = 0.01) {