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 compilation error on React < 18 #428

Merged
merged 1 commit into from Apr 8, 2024
Merged

Conversation

alex-pex
Copy link
Contributor

The error was Attempted import error: 'useInsertionEffect' is not exported from 'react' (imported as 'React').

I have used the same technique as Emotion emotion-js/emotion@75a2f74#diff-e87fa5e3ae2595fc1671477ceb9c7327f968d5556791d29958210ed43474fc92R17

Copy link

stackblitz bot commented Mar 25, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

codecov bot commented Mar 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (8cee71d) to head (3223588).
Report is 1 commits behind head on v3.

Additional details and impacted files
@@            Coverage Diff            @@
##                v3      #428   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines            1         1           
=========================================
  Hits             1         1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@molefrog
Copy link
Owner

Wow. What an interesting case. Didn't know minifiers can do that.
There is another PR from emotion, where the author says that the trick proposed is not bulletproof and some build tools can expand it.

@alex-pex
Copy link
Contributor Author

I don't know if you really need the bulletproof fix: do people embed wouter inside another package and still expect it to work with react < 18? It's a strange combo

@molefrog
Copy link
Owner

I see, could you also add a comment above that line to explain the hack?

@molefrog
Copy link
Owner

Also, one thing I can't wrap my head around is the import of useSyncExternalStore (also, React 18 only) in the shim library we use. They are essentially doing the same thing: importing the native method with a fallback to the user-land implementation. Wouter depends on this library, so I would expect webpack to complain about the import there too. Can you try to import this library directly for the sake of experiment?

@alex-pex
Copy link
Contributor Author

alex-pex commented Apr 8, 2024

image
with "use-sync-external-store": "^1.2.0",

The error is "Attempted import error: 'useInsertionEffect' is not exported from 'react' (imported as 'React')."
@molefrog
Copy link
Owner

molefrog commented Apr 8, 2024

image with "use-sync-external-store": "^1.2.0",

Magic... I have no idea why it works with useSES, but okay let's just merge the fix.

@molefrog molefrog merged commit c79d1f4 into molefrog:v3 Apr 8, 2024
4 checks passed
@molefrog
Copy link
Owner

molefrog commented Apr 8, 2024

Released in 3.1.2

@alex-pex
Copy link
Contributor Author

alex-pex commented Apr 9, 2024

thanks!

@molefrog molefrog mentioned this pull request Apr 24, 2024
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.

None yet

2 participants