fix(vite): alias use-sync-external-store index.js subpaths #66
main fromrefs/pull/66/head·opened Problem#
react-aria / react-aria-components import use-sync-external-store/shim/index.js (the explicit file subpath). The Vite plugin's ALIASES only contains use-sync-external-store/shim, and resolveId matches exact keys, so the subpath is never redirected.
In dev, that specifier falls through to the original CJS package, which is served raw (the shim is in optimizeDeps.exclude), and the app crashes on load:
SyntaxError: The requested module '/@fs/.../use-sync-external-store/shim/index.js' does not provide an export named 'useSyncExternalStore'
Production builds are unaffected because Rolldown converts the CJS shim, whose require('react') is then aliased to Redact.
Seen with @tanstack/redact 0.2.0 + react-aria-components 1.18.0 in a client-only Vite 8 app.
Fix#
Add use-sync-external-store/shim/index.js and use-sync-external-store/index.js to ALIASES, ahead of the bare shim entry (aliases prefix-match, so more specific first).
Tests#
- New test in
tests/vite-plugin.test.ts:use-sync-external-store,/index.js,/shimand/shim/index.jsall resolve to the same file asreact. - Fails without the fix (
expected null to be '.../dist/...'), passes with it. vite-plugin.test.ts: 31/31 pass locally. I didn't run the fulltest:prlocally; relying on CI for that.- Includes a patch changeset.
Summary by CodeRabbit#
- Bug Fixes
- Fixed Vite resolution for explicit
use-sync-external-storeindex subpath imports. These imports now resolve to the same React entry as the package root, preventing a development-time error.
- Fixed Vite resolution for explicit
- Tests
- Added coverage for resolution of the package root and its index and shim subpaths.
- 1
No actionable comments were generated in the recent review.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: defaults
- Review profile: CHILL
- Plan: Advanced
- Run ID:
031eb929-6741-45c4-9f2e-8aec0a057e3a
Commits-
Reviewing files that changed from the base of the PR and between d56d87cbe3bbdc412da836026a81f6a2b2da2ce5 and 87d94d73589ba86c616e155a0f69fb4f47398d26.
Files selected for processing: 3-
.changeset/use-sync-external-store-index-subpaths.mdpackages/redact/src/vite/index.tstests/vite-plugin.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
-
Walkthrough
-
The Vite plugin now aliases two explicit
use-sync-external-storeindex subpaths to@tanstack/redact. A test checks that these subpaths and two existing specifiers resolve to the same React entry in the client environment.Changes: Vite subpath aliases
Priority:Layer / File(s) Summary Alias resolution and validation
packages/redact/src/vite/index.ts,tests/vite-plugin.test.ts,.changeset/use-sync-external-store-index-subpaths.mdThe Vite plugin maps the explicit index.jsandshim/index.jssubpaths to@tanstack/redact. The test checks that four specifiers resolve to the same React entry in the client environment. A changeset declares a patch release. NormalEstimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix
Suggested reviewers:
tannerlinsley
Merge Risk:
Minimal · up to87d94-
The requested subpath aliases are correctly implemented and ready to merge.
Pre-merge checks:
5-
Check name Status Explanation Description Check Check skipped - CodeRabbit’s high-level summary is enabled. Title check The title clearly and concisely describes the main change: adding Vite aliases for the use-sync-external-storeindex.jssubpaths.Docstring Coverage No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Docstring Coverage
-
Explanation
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. (1 skipped: 1 unsupported.)
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment `@coderabbitai help` to get the list of available commands.-
Thanks @Daggron, your explicit shim-subpath aliases and regression tests landed through #76 and are included in 0.2.4.
AI review notes: Current main maps both use-sync-external-store/shim/index.js and use-sync-external-store/index.js to the Redact React entry, with the submitted alias regression coverage retained. The verified 0.2.4 package matches its release source across 347 built files. This PR’s implementation is already covered by that release.
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 87d94d73589ba86c616e155a0f69fb4f47398d26
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR