Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f7710e
commit ab3c8ed
Showing
11 changed files
with
76 additions
and
16 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@griffel-react-13bf5fac-a88b-41ad-98fc-a8df3be96e6d.json
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,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "chore: improve React 18 support", | ||
"packageName": "@griffel/react", | ||
"email": "olfedias@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
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 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,27 @@ | ||
import type { CSSRulesByBucket, GriffelInsertionFactory, GriffelRenderer } from '@griffel/core'; | ||
|
||
import { canUseDOM } from './utils/canUseDOM'; | ||
import { useInsertionEffect } from './useInsertionEffect'; | ||
|
||
export const insertionFactory: GriffelInsertionFactory = () => { | ||
const insertionCache: Record<string, boolean> = {}; | ||
|
||
return function insert(renderer: GriffelRenderer, dir: string, cssRules: CSSRulesByBucket) { | ||
if (useInsertionEffect) { | ||
// Even if `useInsertionEffect` is available, we can't use it in SSR as it will not be executed | ||
if (canUseDOM()) { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
useInsertionEffect(() => { | ||
renderer.insertCSSRules(cssRules!); | ||
}, [renderer, cssRules]); | ||
|
||
return; | ||
} | ||
} | ||
|
||
if (insertionCache[renderer.id] === undefined) { | ||
renderer.insertCSSRules(cssRules!); | ||
insertionCache[renderer.id] = true; | ||
} | ||
}; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as React from 'react'; | ||
|
||
export const useInsertionEffect: typeof React.useInsertionEffect | undefined = | ||
// @ts-expect-error Hack to make sure that `useInsertionEffect` will not cause bundling issues in older React versions | ||
// eslint-disable-next-line no-useless-concat | ||
React['useInsertion' + 'Effect'] ? React['useInsertion' + 'Effect'] : undefined; |
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,6 @@ | ||
/** | ||
* Verifies if an application can use DOM. | ||
*/ | ||
export function canUseDOM(): boolean { | ||
return typeof window !== 'undefined' && !!(window.document && window.document.createElement); | ||
} |