-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move conditional
useInsertionEffect
declarations into separate pack…
…age (#2867) * Move conditional `useInsertionEffect` declarations into separate package * add missing dependecies * regenerate lockfile * Add missing peer dep * regenerate lockfile * add missing dev dep for a peer dep * regenerate lockfile * add changesets
- Loading branch information
Showing
15 changed files
with
118 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# @emotion/use-insertion-effect-with-fallbacks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
export const useInsertionEffectWithLayoutFallback = | ||
useInsertionEffect || React.useLayoutEffect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters