Fix Vite config plugin imports and add resolveId hook filter

Merged
MA
19d ago
+53-12

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Changes To Core Features

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?

Description

This PR fixes two issues in the Vite configuration template:

  1. Plugin import extension: Changed the local plugin import from "./vite-plugin-safari-cachebust" to "./vite-plugin-safari-cachebust.js" to include the file extension. Vite's native config loader (planned to become the default) cannot resolve extensionless relative imports and warns about them.

  2. resolveId hook optimization: Refactored the alwaysUseReactDomServerNode plugin's resolveId hook to use Vite's hook filter API. The hook now declares filter: { id: /react-dom\/server/ } to prevent the hook from being called for every import in the module graph. Without this filter, rolldown calls the hook for tens of thousands of imports, which dominates build time on large applications. The redundant source.includes("react-dom/server") check was removed since the filter now ensures only matching imports reach the handler.

Test Plan

Added two new unit tests in tests/units/utils/test_utils.py:

  • test_vite_config_template_imports_plugin_with_extension(): Verifies the plugin import includes the .js extension
  • test_vite_config_template_filters_react_dom_server_resolve_hook(): Verifies the resolveId hook declares the filter and handler

Both tests call vite_config_template() and assert the expected strings are present in the generated config.

https://claude.ai/code/session_01PXbBjFDmFjqYQPHdPjk4zp