diff --git a/.changeset/metal-phones-like.md b/.changeset/metal-phones-like.md new file mode 100644 index 0000000000..ed0c66b994 --- /dev/null +++ b/.changeset/metal-phones-like.md @@ -0,0 +1,6 @@ +--- +'@clerk/clerk-js': patch +'@clerk/types': patch +--- + +Introduce experimental `cssLayerName` option to allow users to opt into CSS layers. diff --git a/packages/clerk-js/src/ui/lazyModules/providers.tsx b/packages/clerk-js/src/ui/lazyModules/providers.tsx index 223c9fba02..6843a30427 100644 --- a/packages/clerk-js/src/ui/lazyModules/providers.tsx +++ b/packages/clerk-js/src/ui/lazyModules/providers.tsx @@ -32,7 +32,10 @@ type LazyProvidersProps = React.PropsWithChildren<{ clerk: any; environment: any export const LazyProviders = (props: LazyProvidersProps) => { return ( - + {props.children} diff --git a/packages/clerk-js/src/ui/styledSystem/StyleCacheProvider.tsx b/packages/clerk-js/src/ui/styledSystem/StyleCacheProvider.tsx index 37564095c9..55d663be8f 100644 --- a/packages/clerk-js/src/ui/styledSystem/StyleCacheProvider.tsx +++ b/packages/clerk-js/src/ui/styledSystem/StyleCacheProvider.tsx @@ -1,25 +1,80 @@ // eslint-disable-next-line no-restricted-imports +import type { StylisPlugin } from '@emotion/cache'; +// eslint-disable-next-line no-restricted-imports import createCache from '@emotion/cache'; // eslint-disable-next-line no-restricted-imports import { CacheProvider } from '@emotion/react'; -import React, { useMemo } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; + +/** + * A Stylis plugin that wraps CSS rules in a CSS layer + * @param layerName - The name of the CSS layer to wrap the styles in + * @returns A Stylis plugin function + */ +export const wrapInLayer: (layerName: string) => StylisPlugin = layerName => node => { + // if we're not at the root of a