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
Move conditional useInsertionEffect
declarations into separate package
#2867
Changes from all commits
8dc0645
c2f0ce5
dfbe3af
398c1fb
226604c
5be51df
19e8bed
ea5a2ea
273192d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@emotion/react': patch | ||
'@emotion/styled': patch | ||
--- | ||
|
||
Externalized code referencing `React.useInsertionEffect` to a separate `@emotion/use-insertion-effect-with-fallbacks` package. This package should be used in your defined externals if you bundle Emotion for whatever reason. It references `useInsertionEffect` in a very specific way that allows us to use it conditionally. However, if the code consuming Emotion is bundled as a library with Emotion in it then some bundlers might change the way in which we reference `useInsertionEffect` and that might create problems for bundlers used to consume the said library code. By externalizing this new package you can still bundle Emotion if you want to without running into this problem as you won't "destroy" the carefully crafted reference to `useInsertionEffect` in the process. | ||
|
||
Note that we don't recommend bundling Emotion. You should have very specific reasons to do so. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@emotion/use-insertion-effect-with-fallbacks': major | ||
--- | ||
|
||
A wrapper package that uses `useInsertionEffect` or a specific fallback for it. It comes with two exports: `useInsertionEffectAlwaysWithSyncFallback` and `useInsertionEffectWithLayoutFallback`. |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) Emotion team and other contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# @emotion/use-insertion-effect-with-fallbacks |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "@emotion/use-insertion-effect-with-fallbacks", | ||
"version": "0.0.0", | ||
"description": "A wrapper package that uses `useInsertionEffect` or a fallback for it", | ||
"main": "dist/emotion-use-insertion-effect-with-fallbacks.cjs.js", | ||
"module": "dist/emotion-use-insertion-effect-with-fallbacks.esm.js", | ||
"browser": { | ||
"./dist/emotion-use-insertion-effect-with-fallbacks.esm.js": "./dist/emotion-use-insertion-effect-with-fallbacks.browser.esm.js" | ||
}, | ||
"license": "MIT", | ||
"repository": "https://github.com/emotion-js/emotion/tree/main/packages/use-insertion-effect-with-fallbacks", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"peerDependencies": { | ||
"react": ">=16.8.0" | ||
}, | ||
"devDependencies": { | ||
"react": "16.14.0" | ||
}, | ||
"exports": { | ||
".": { | ||
"module": { | ||
"worker": "./dist/emotion-use-insertion-effect-with-fallbacks.worker.esm.js", | ||
"browser": "./dist/emotion-use-insertion-effect-with-fallbacks.browser.esm.js", | ||
"default": "./dist/emotion-use-insertion-effect-with-fallbacks.esm.js" | ||
}, | ||
"default": "./dist/emotion-use-insertion-effect-with-fallbacks.cjs.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"preconstruct": { | ||
"exports": { | ||
"envConditions": [ | ||
"browser", | ||
"worker" | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as React from 'react' | ||
|
||
const isBrowser = typeof document !== 'undefined' | ||
|
||
const syncFallback = create => create() | ||
|
||
const useInsertionEffect = React['useInsertion' + 'Effect'] | ||
? React['useInsertion' + 'Effect'] | ||
: false | ||
|
||
export const useInsertionEffectAlwaysWithSyncFallback = !isBrowser | ||
? syncFallback | ||
: useInsertionEffect || syncFallback | ||
Comment on lines
+11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please be extra careful when reviewing this as the shape of this has slightly changed when I moved this. I think that the current code is functionally equivalent to the old version though. |
||
|
||
export const useInsertionEffectWithLayoutFallback = | ||
useInsertionEffect || React.useLayoutEffect |
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.
Should this be
*-with-fallback
or*-with-fallbacks
? 😅 #realproblems