Skip to content
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

Extended Set Methods (like union()) Not Included in Default Polyfills Despite Documentation #74978

Open
nikolay-gipp-sibe opened this issue Jan 16, 2025 · 0 comments
Labels
Developer Experience Issues related to Next.js logs, Error overlay, etc. Performance Anything with regards to Next.js performance. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@nikolay-gipp-sibe
Copy link

Link to the code that reproduces this issue

https://github.com/nikolay-gipp-sibe/next-set-polyfill-issue

To Reproduce

  1. Create a new Next.js project using create-next-app
npx create-next-app@latest
  1. Create a new component file (e.g. app/test/page.tsx) with the following content:
'use client';

import { ReactElement } from 'react';
// Without this import, union() doesn't work
// import 'core-js/features/set'

export function TestSetUnion(): ReactElement {
    const set: Set<unknown> = new Set([1, 2, 3]).union(new Set([1, 2]));
    return <div>Test Set Union {set.size}</div>;
}
  1. Open the page in Chrome 103

  2. Observe the error: TypeError: a.union is not a function

  3. Add the polyfill import manually:

import 'core-js/features/set'
  1. Refresh the page - now it works correctly

Current vs. Expected behavior

Current Behavior

When using Set's extended methods like union() without manual polyfill import, the application throws TypeError: a.union is not a function in Chrome 103, despite Next.js documentation stating that Set polyfills are included by default.

Expected Behavior

Since Next.js documentation and source code (https://github.com/vercel/next.js/blob/canary/packages/next-polyfill-nomodule/src/index.js) include import 'core-js/features/set', all Set methods including extended ones like union() should work without requiring manual polyfill imports.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 65389
  Available CPU cores: 16
Binaries:
  Node: 22.13.0
  npm: 10.8.2
  Yarn: 1.22.19
  pnpm: 9.15.4
Relevant Packages:
  next: 15.1.4 // Latest available version is detected (15.1.4).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Documentation, Developer Experience, Runtime, Performance

Which stage(s) are affected? (Select all that apply)

next dev (local), Vercel (Deployed), Other (Deployed), next start (local)

Additional context

Additional Context

This issue affects older browsers like Chrome 103.

From Next.js documentation:

We inject widely used polyfills, including:
If any of your dependencies include these polyfills, they'll be eliminated automatically from the production build to avoid duplication.

And in polyfill source code:

import 'core-js/features/set'

The key points:

  • The extended Set methods like union() work fine in server components
  • But in client components, you get a TypeError unless you manually add import 'core-js/features/set' to the client component
  • This creates confusing behavior when moving components from server to client rendering
@nikolay-gipp-sibe nikolay-gipp-sibe added the bug Issue was opened via the bug report template. label Jan 16, 2025
@github-actions github-actions bot added Developer Experience Issues related to Next.js logs, Error overlay, etc. Documentation Related to Next.js' official documentation. Performance Anything with regards to Next.js performance. Runtime Related to Node.js or Edge Runtime with Next.js. labels Jan 16, 2025
@samcx samcx removed bug Issue was opened via the bug report template. Documentation Related to Next.js' official documentation. labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Experience Issues related to Next.js logs, Error overlay, etc. Performance Anything with regards to Next.js performance. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

2 participants