Skip to content

fix(javascript): move gzip compression to node-only builds, remove fflate#6154

Merged
Fluf22 merged 2 commits intomainfrom
fix/compression-node-only
Mar 24, 2026
Merged

fix(javascript): move gzip compression to node-only builds, remove fflate#6154
Fluf22 merged 2 commits intomainfrom
fix/compression-node-only

Conversation

@Fluf22
Copy link
Copy Markdown
Collaborator

@Fluf22 Fluf22 commented Mar 23, 2026

Summary

  • Remove fflate from client-common, use node:zlib in server builds instead
  • Compression is opt-in via compression: 'gzip' on ClientOptions
  • Browser/worker builds strip compression from options and provide no compress implementation
  • Enable bundlewatch on all PRs, update size limits

Context

PR #6052 added fflate to client-common for gzip compression. Since client-common is bundled into every browser UMD via noExternal, fflate (~3.3KB gzip) ended up in all 13 browser bundles. Bundlewatch only ran on release branches, so this was never caught.

Design

Concern Property Scope
Intent (user) compression?: 'gzip' ClientOptions (public)
Implementation (build) compress?: (data: string) => Promise<Uint8Array> TransporterOptions (internal, hidden from ClientOptions)

Node/fetch/liteNode: injects compress via node:zlib, user enables with compression: 'gzip'.

Browser/worker: no compress implementation, compression stripped from user options at runtime. Manual browser compression is not recommended and blocked by CORS.

If compression: 'gzip' is set but no compress method exists, the transporter logs a warning via logger.info and sends uncompressed. With createNullLogger (default), the warning is silently swallowed.

@Fluf22 Fluf22 force-pushed the fix/compression-node-only branch from 3768ec3 to 012bbd4 Compare March 23, 2026 21:46
@algolia-bot
Copy link
Copy Markdown
Collaborator

algolia-bot commented Mar 23, 2026

💥 Breaking changes detected !!

Either this PR or a previous PR not released yet introduced breaking changes, be careful when merging.
You can find the details in the 'client java@21' CI job.

✔️ Code generated!

Name Link
🪓 Triggered by 38305ac049b692543a0d31fd711fe8d0935b6185
🍃 Generated commit 5503383f96c31f744f0c45b9d8d4942fba68377a
🌲 Generated branch generated/fix/compression-node-only
📊 Benchmark results

Benchmarks performed on the method using a mock server, the results might not reflect the real-world performance.

Language Req/s
javascript 2328
go 2252
php 1858
csharp 1530
python 1359
java 1119
ruby 925
swift 553
scala 23

@Fluf22 Fluf22 force-pushed the fix/compression-node-only branch 4 times, most recently from baaeeb7 to 4f27825 Compare March 24, 2026 09:24
@Fluf22 Fluf22 self-assigned this Mar 24, 2026
@Fluf22 Fluf22 force-pushed the fix/compression-node-only branch from 4f27825 to f404f22 Compare March 24, 2026 10:51
@Fluf22 Fluf22 marked this pull request as ready for review March 24, 2026 11:32
@Fluf22 Fluf22 requested a review from a team as a code owner March 24, 2026 11:32
Copy link
Copy Markdown
Contributor

@MarioAlexandruDan MarioAlexandruDan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Ok!

…late

Replace fflate (browser+node gzip library) with node:zlib for server
builds and CompressionStream for browser/worker builds. Compression is
now injected via a compress function in TransporterOptions.

Node/fetch builds: synchronous gzip via node:zlib (always available).
Browser/worker builds: async gzip via CompressionStream (noop if unavailable).
compress is hidden from ClientOptions — internal implementation detail.

- Remove fflate dependency from client-common
- Replace compression?: 'gzip' with compress?: function on TransporterOptions
- Add gzipSync in node/fetch/liteNode templates, CompressionStream in browser/worker
- Enable bundlewatch size check on all PRs, not just release branches
@Fluf22 Fluf22 merged commit 6064369 into main Mar 24, 2026
37 checks passed
@Fluf22 Fluf22 deleted the fix/compression-node-only branch March 24, 2026 18:29
algolia-bot added a commit that referenced this pull request Mar 24, 2026
…late (#6154) (generated) [skip ci]

Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
algolia-bot added a commit to algolia/algoliasearch-client-javascript that referenced this pull request Mar 24, 2026
…late (generated)

algolia/api-clients-automation#6154

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants