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

Fix use-sync-external-store import for Webpack 5 #276

Merged
merged 3 commits into from
Jan 11, 2023

Conversation

HansBrende
Copy link
Contributor

Fixes #275
There is an open facebook PR that should fix this as well whenever it EVENTUALLY gets merged: facebook/react#25231

But in the meantime, React Query seems to have had luck with this hack.

(See TanStack/query#3561 and TanStack/query#3601)

@codecov
Copy link

codecov bot commented Jan 6, 2023

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (1520ee3) compared to base (12dc229).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #276   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          217       217           
  Branches        53        53           
=========================================
  Hits           217       217           
Impacted Files Coverage Δ
react-deps.js 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@HansBrende HansBrende changed the title Use sync external store import Fix use-sync-external-store import for Webpack 5 Jan 6, 2023
@@ -0,0 +1 @@
export { useSyncExternalStore } from "use-sync-external-store/shim/index.native.js";
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not familiar with how modules are bundled in native, is this some kind naming convention? I see that this file isn't actually referenced anywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@molefrog it is referenced to the same degree that the .js version is, since we are not specifying any extension at all when we import it. It is up to the bundling system to select which extension to use, whether that be .js or .native.js!

That being said, I'm not too familiar with react native either, all I know is that I copied this fix over verbatim from react-query and it worked for them. 😄

Copy link
Owner

Choose a reason for hiding this comment

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

I was able to find the docs on .native.js extension, it seems like their bundler can handle these types of files. Looks legit!

Copy link
Owner

@molefrog molefrog left a comment

Choose a reason for hiding this comment

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

Looks good.

@molefrog molefrog merged commit 9f68c05 into molefrog:main Jan 11, 2023
@HansBrende HansBrende deleted the use-sync-external-store-import branch January 11, 2023 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't resolve 'use-sync-external-store/shim' in `~/.../node_modules/wouter'. Did you mean 'index.js'?
2 participants