Skip to content

optimize-locales-plugin does not use hook filters #10301

Description

@wojtekmaj

Provide a general summary of the issue here

@react-aria/optimize-locales-plugin does its filtering inside resolveId, but Vite/Rollup/Rolldown can now skip many unnecessary hook calls entirely using hook filters.

Rolldown reported the plugin as a significant part of plugin time in one of my builds:

[PLUGIN_TIMINGS] Your build spent significant time in plugins. Here is a breakdown:
  - locales-plugin (76%)
  - vite:handlebars (12%)
  - sentry-vite-plugin (6%)
See https://rolldown.rs/reference/InputOptions.checks#plugintimings for more details.

🤔 Expected Behavior?

locales-plugin should only enter its resolveId handler for locale-looking specifiers where it can actually do something useful.

😯 Current Behavior

resolveId is called broadly and then quickly returns for most imports:

if (!/[/\\](@react-stately|@react-aria|@react-spectrum|@adobe[/\\]react-spectrum|react-stately|react-aria|react-aria-components)[/\\]/.test(sourcePath) || options?.ssr) {
  return;
}

The check is cheap, but the hook call itself is not free in Rolldown/Vite builds.

💁 Possible Solution

Use the object hook form supported by Vite/Rollup/Rolldown:

resolveId: {
  filter: {
    id: /[a-z]{2}-[A-Z]{2}/
  },
  handler(specifier, sourcePath, options) {
    // existing logic
  }
}

🔦 Context

Vite docs: https://vite.dev/guide/api-plugin#hook-filters

🖥️ Steps to Reproduce

  1. Build a Vite/Rolldown app using @react-aria/optimize-locales-plugin.
  2. Enable plugin timing checks.
  3. Observe locales-plugin taking a significant percentage of plugin time.

Version

2.0.0

What browsers are you seeing the problem on?

Other

If other, please specify.

not relevant

What operating system are you using?

not relevant

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions