Add "exports" field to use-sync-external-store's package.json#24440
Add "exports" field to use-sync-external-store's package.json#24440latin-1 wants to merge 1 commit intofacebook:mainfrom latin-1:patch-1
Conversation
|
doesn't this also need |
|
Oops, it appears I overlooked something. Updated. |
|
|
|
What's the motivation for this? |
|
This would help support React Native and be esm compliant. In TanStack/query#3582 RN support was broken because we imported from |
|
@gaearon @acdlite I think this PR would fix our issues we have over in react-query with the uSES shim for react native. apollo-client is having the same issue, and they have opted to copy over the uSES code to fix it on their side. I would rather wait for an official fix on your end, which I think this PR provides :) |
| "exports": { | ||
| ".": "./index.js", | ||
| "./with-selector": "./with-selector.js", | ||
| "./shim": "./shim/index.js", |
There was a problem hiding this comment.
thoughts on
| "./shim": "./shim/index.js", | |
| "./shim": { | |
| "react-native": "./shim/index.native.js", | |
| "default": "./shim/index.js" | |
| }, |
?
That way all code can just be use-sync-external-store/shim.
note that this relies on the bundler actually supporting exports and supplying react-native condition (which I'm guessing metro at least doesn't do), but it seems more future-proof than these (seemingly) somewhat random exports
There was a problem hiding this comment.
facebook/metro#670
Metro doesn't respect exports field at all.
There was a problem hiding this comment.
Right, so no issue.
This stanza should still work for any modern bundler, and metro whenever it enters the future
There was a problem hiding this comment.
There's Repack to consider (basically Webpack for react-native) so we might as well get this in now. Doing it in the future might be considered another breaking change.
|
I had to say this would be a breaking change, though. That's why I held this PR. I'm trying to find out a better approach but with no luck. |
|
@latin-1 What makes this a breaking change? |
|
@gaearon You can no longer import with extensions and some paths have changed (for ESM resolution): We may be able to support it by just exporting everything under the same path as before (maybe using glob exports). |
|
@sachinraja @gaearon @latin-1 what's the status of this PR? If the change are okay, could we release it as a new major version? We are still having troubles with the uSES shim in react-native because of it. Thanks 🙏 |
Don't we need #24440 (comment) for that? |
| "./shim": "./shim/index.js", | ||
| "./shim/index.native": "./shim/index.native.js", | ||
| "./shim/with-selector": "./shim/with-selector.js", | ||
| "./src/*": "./src/*", |
There was a problem hiding this comment.
Wouldn't this require changing the publish script? The latest version of uSES publishes no src folder (see https://unpkg.com/browse/use-sync-external-store@1.2.0/). What are you currently importing with use-sync-external-store/src/??
There was a problem hiding this comment.
It seems that the react package has this line.
react/packages/react/package.json
Line 30 in 3613284
|
|
||
| 'use strict'; | ||
|
|
||
| export {useSyncExternalStore} from './src/useSyncExternalStore'; |
There was a problem hiding this comment.
This file is used internally. The published entrypoints are in npm/ which can continue using relative imports.
|
Alternate that's not exposing non-existent |
|
Closing in favor of #25231 |
Summary
How did you test this change?