-
Notifications
You must be signed in to change notification settings - Fork 47.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "exports" field to use-sync-external-store's package.json #24440
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
facebook/metro#670
Metro doesn't respect exports
field at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this require changing the publish script? The latest version of uSES
publishes no src
folder (see https://unpkg.com/browse/[email protected]/). What are you currently importing with use-sync-external-store/src/?
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the react package has this line.
react/packages/react/package.json
Line 30 in 3613284
"./src/*": "./src/*" |
@@ -9,4 +9,4 @@ | |||
|
|||
'use strict'; | |||
|
|||
export {useSyncExternalStore} from './src/useSyncExternalStore'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?