From 3e0a730d1d96cdd2a4d4d3565fb3bb212c91e165 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sat, 13 May 2023 00:34:32 -0700 Subject: [PATCH] Update warning --- packages/next/src/shared/lib/bloom-filter.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) 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) {