File tree Expand file tree Collapse file tree 4 files changed +21
-2
lines changed
Expand file tree Collapse file tree 4 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @vanilla-extract/css ' : patch
3+ ---
4+
5+ Fix fileScope error if ` composeStyles ` is called at runtime
Original file line number Diff line number Diff line change 11import { generateIdentifier } from './identifier' ;
22import { registerComposition , registerClassName } from './adapter' ;
3+ import { hasFileScope } from './fileScope' ;
34
45type ClassNames = string | Array < ClassNames > ;
56
@@ -43,5 +44,14 @@ export function dudupeAndJoinClassList(classNames: Array<ClassNames>) {
4344}
4445
4546export function composeStyles ( ...classNames : Array < ClassNames > ) {
46- return createComposition ( dudupeAndJoinClassList ( classNames ) ) ;
47+ const classList = dudupeAndJoinClassList ( classNames ) ;
48+
49+ // When using Sprinkles with the runtime (e.g. within a jest test)
50+ // `composeStyles` can be called outside of a fileScope. Checking
51+ // the fileScope is bit of a hack but will solve the issue for now
52+ if ( ! hasFileScope ( ) ) {
53+ return classList ;
54+ }
55+
56+ return createComposition ( classList ) ;
4757}
Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ export function endFileScope() {
2020 fileScopes . splice ( 0 , 1 ) ;
2121}
2222
23+ export function hasFileScope ( ) {
24+ return fileScopes . length > 0 ;
25+ }
26+
2327export function getFileScope ( ) : FileScope {
2428 if ( fileScopes . length === 0 ) {
2529 throw new Error (
Original file line number Diff line number Diff line change 11import {
22 createMapValueFn ,
33 createNormalizeValueFn ,
4+ createAtomsFn ,
45} from '@vanilla-extract/sprinkles' ;
5- import { createAtomsFn } from '@vanilla-extract/sprinkles/createRuntimeAtomsFn' ;
66
77import {
88 atomicStyles ,
You can’t perform that action at this time.
0 commit comments