Skip to content

fix[isBuffer]: add browser export condition to avoid 44KB Buffer polyfill#1671

Open
jantimon wants to merge 2 commits intotoss:mainfrom
jantimon:fix/browser-buffer-polyfill
Open

fix[isBuffer]: add browser export condition to avoid 44KB Buffer polyfill#1671
jantimon wants to merge 2 commits intotoss:mainfrom
jantimon:fix/browser-buffer-polyfill

Conversation

@jantimon
Copy link
Copy Markdown

  • adds a browser-safe isBuffer stub (() => false) and a rollup alias plugin that swaps it in during the browser build
  • adds browser export condition to every subpath in package.json so bundlers like webpack/vite pick up the polyfill-free build automatically
  • refactors all inline typeof Buffer / Buffer.isBuffer() checks across mergeWith, isEmpty, cloneDeepWith, and isEqualWith to use the centralized isBuffer function

closes #1670

Build size comparison (Next.js test app)

Webpack

Raw Gzipped
Before 458 KB 143 KB
After 438 KB 136 KB
Diff -19.3 KB -6.5 KB (4.5%)

Turbopack

Raw Gzipped
Before 460 KB 134 KB
After 416 KB 116 KB
Diff -44.3 KB -18.2 KB (13.6%)

Test plan

  • yarn vitest run — all existing tests pass (isBuffer tests run against the real Node.js implementation)
  • yarn lint / tsc --noEmit — clean
  • Verified with a Next.js app: .next/static drops from 492K to 464K after the change
  • grep -r "Buffer" dist/browser/ confirms no Buffer references in the browser build

Copilot AI review requested due to automatic review settings March 29, 2026 15:06
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
es-toolkit Ready Ready Preview, Comment Mar 29, 2026 4:56pm

Request Review

@jantimon jantimon changed the title fix[isBuffer]: add browser export condition to avoid 28KB Buffer polyfill fix[isBuffer]: add browser export condition to avoid 44KB Buffer polyfill Mar 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a browser-safe build path for isBuffer to prevent bundlers (e.g. webpack/Next.js, Vite) from injecting large Buffer polyfills, and refactors internal call sites to use the centralized predicate.

Changes:

  • Introduces isBuffer.browser.ts stub and a Rollup alias to swap it into the browser ESM/UMD builds.
  • Adds browser export conditions for top-level subpath exports in publishConfig.exports.
  • Replaces inline Buffer checks in several utilities (isEqualWith, cloneDeepWith, isEmpty, mergeWith) with isBuffer().

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/predicate/isEqualWith.ts Refactors Buffer detection in typed-array comparison to use isBuffer().
src/predicate/isBuffer.browser.ts Adds browser-safe isBuffer stub used by the browser build.
src/object/cloneDeepWith.ts Switches Buffer cloning branch to use centralized isBuffer().
src/compat/predicate/isEmpty.ts Replaces inline Buffer check with isBuffer() in compat isEmpty.
src/compat/object/mergeWith.ts Uses isBuffer() when deciding whether to deep-clone Buffer source values.
rollup.config.mjs Adds browser ESM build output + alias plugin wiring for isBuffer stub.
package.json Adds browser conditional export mappings under publishConfig.exports.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@kms0219kms kms0219kms left a comment

Choose a reason for hiding this comment

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

LGTM

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.

es-toolkit blows up next.js bundle size by 28kb to 40kb

3 participants