Skip to content

@react-aria/optimize-locales-plugin not removing locales after 4-14 release #10109

@ashleyryan

Description

@ashleyryan

Provide a general summary of the issue here

We use rollup to generate esm, cjs, and systemjs outputs. Following the April release, we noticed that our bundle size had increased and all locales were being bundled in our system.js output, adding 60 KB to our bundle size. It's not noticeable with ESM where tree-shaking is handled by consuming apps (and may or may not work?), but I assume this applies to UMD outputs as well

AI says " @react-aria/optimize-locales-plugin silently stops working — all 26 locale files are included in the bundle regardless of the locales configuration."

🤔 Expected Behavior?

Only the locales specified in the config are included

😯 Current Behavior

Only the locales specified are included

💁 Possible Solution

AI suggested the following fix:

Add the bare monopackage names to the regex. The path separator anchors ([/\] on both sides) ensure they only match as complete path segments and won't incorrectly match react-aria-components:

// before
!/[/\\](@react-stately|@react-aria|@react-spectrum|react-aria-components)[/\\]/
// after
!/[/\\](@react-stately|@react-aria|@react-spectrum|react-aria-components|react-aria|react-stately)[/\\]/

It created this patch for the package that we run post-install

const fs = require('fs')
const path = require('path')

const pluginPath = path.join(__dirname, '..', 'node_modules', '@react-aria', 'optimize-locales-plugin', 'LocalesPlugin.js')

if (!fs.existsSync(pluginPath)) {
  console.warn('[patch] @react-aria/optimize-locales-plugin not found, skipping patch')
  process.exit(0)
}

const original = '/[/\\\\](@react-stately|@react-aria|@react-spectrum|react-aria-components)[/\\\\]/'
const patched = '/[/\\\\](@react-stately|@react-aria|@react-spectrum|react-aria-components|react-aria|react-stately)[/\\\\]/'

let content = fs.readFileSync(pluginPath, 'utf8')

if (content.includes(patched)) {
  console.log('[patch] @react-aria/optimize-locales-plugin already patched, skipping')
  process.exit(0)
}

if (!content.includes(original)) {
  console.warn('[patch] Expected pattern not found in LocalesPlugin.js — plugin may have been updated. Manual review needed.')
  process.exit(0)
}

content = content.replace(original, patched)
fs.writeFileSync(pluginPath, content, 'utf8')
console.log('[patch] @react-aria/optimize-locales-plugin patched for monopackage path support')

🔦 Context

No response

🖥️ Steps to Reproduce

  1. Configure optimize-locales-plugin with a subset of locales (e.g. ['en-US'])
  2. Import from react-aria or react-stately monopackages directly (rather than from individual @react-aria/* / @react-stately/* packages)
  3. Build your bundle and inspect the output
    Expected: only the configured locales are included
    Actual: all 26 locale files are included (~75KB extra in a minified bundle)

Version

react-aria 3.48.0

What browsers are you seeing the problem on?

Other

If other, please specify.

No response

What operating system are you using?

Mac OS 26.4.1

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions