Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

latin-1
Copy link
Contributor

@latin-1 latin-1 commented Apr 26, 2022

Summary

How did you test this change?

@gaearon
Copy link
Member

@gaearon gaearon commented Apr 26, 2022

doesn't this also need ./ and ./package.json?

@latin-1
Copy link
Contributor Author

@latin-1 latin-1 commented Apr 26, 2022

Oops, it appears I overlooked something. Updated.

@latin-1
Copy link
Contributor Author

@latin-1 latin-1 commented Apr 26, 2022

I'm not sure if "./src/*": "./src/*" is necessary for this package. Should I include that in the package.json as well?

@acdlite
Copy link
Member

@acdlite acdlite commented Apr 26, 2022

What's the motivation for this?

@sachinraja
Copy link

@sachinraja sachinraja commented May 9, 2022

This would help support React Native and be esm compliant. In tannerlinsley/react-query#3582 RN support was broken because we imported from use-sync-external-store/shim/index.js to support esm which does not support directory imports and must use extensions. With this PR we can import from use-sync-external-store/shim which would work correctly for esm and RN.

@TkDodo
Copy link

@TkDodo TkDodo commented May 10, 2022

@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",
Copy link
Contributor

@SimenB SimenB May 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts on

Suggested change
"./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

Copy link
Contributor Author

@latin-1 latin-1 May 10, 2022

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.

Copy link
Contributor

@SimenB SimenB May 10, 2022

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

@latin-1
Copy link
Contributor Author

@latin-1 latin-1 commented May 10, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants