Skip to content

Commit

Permalink
fix: remove eslint exception in RendererProvider (#566)
Browse files Browse the repository at this point in the history
* fix: make RendererProvider isomorphic without disabling lint rules

Moves the `canUseDOM()` call inside the `useMemo()` hook, allowing
RendererProvider to work without disabling React hooks linting and
therefore potential React Compiler optimizations.

* Change files

---------

Co-authored-by: Oleksandr Fediashov <[email protected]>
  • Loading branch information
spmonahan and layershifter authored Aug 8, 2024
1 parent 4436d63 commit fb21c43
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: make RendererProvider compatible with React Compiler",
"packageName": "@griffel/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
13 changes: 4 additions & 9 deletions packages/react/src/RendererContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@ const RendererContext = React.createContext<GriffelRenderer>(createDOMRenderer()
* @public
*/
export const RendererProvider: React.FC<RendererProviderProps> = ({ children, renderer, targetDocument }) => {
'use no memo';

if (canUseDOM()) {
// This if statement technically breaks the rules of hooks, but is safe because the condition never changes after
// mounting.
// eslint-disable-next-line react-hooks/rules-of-hooks
React.useMemo(() => {
React.useMemo(() => {
if (canUseDOM()) {
// "rehydrateCache()" can't be called in effects as it needs to be called before any component will be rendered to
// avoid double insertion of classes
rehydrateRendererCache(renderer, targetDocument);
}, [renderer, targetDocument]);
}
}
}, [renderer, targetDocument]);

return <RendererContext.Provider value={renderer}>{children}</RendererContext.Provider>;
};
Expand Down

0 comments on commit fb21c43

Please sign in to comment.