Skip to content

Commit 8a82452

Browse files
Not generate cache for identifier (#1796)
* Not generate cache for identifier * Add changeset --------- Co-authored-by: Liam Ma <[email protected]>
1 parent 4fa9dcf commit 8a82452

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

.changeset/many-sheep-change.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compiled/babel-plugin': patch
3+
---
4+
5+
Stop checking if styles are cssMap if being used as `css={styles}`. This is to improve build performance.

packages/babel-plugin/src/css-map/__tests__/index.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ describe('css map basic functionality', () => {
128128
129129
const styles = cssMap({ root: { color: 'red' } });
130130
`);
131-
}).toThrow(ErrorMessages.USE_VARIANT_OF_CSS_MAP);
131+
}).toThrow(
132+
'This CallExpression was unable to have its styles extracted — try to define them statically using Compiled APIs instead'
133+
);
132134
});
133135

134136
it('should error out if variants are not defined at the top-most scope of the module.', () => {

packages/babel-plugin/src/utils/css-builders.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1004,9 +1004,11 @@ export const buildCss = (node: t.Expression | t.Expression[], meta: Metadata): C
10041004
);
10051005
}
10061006

1007-
// In some cases, the `state.cssMap` is not warmed yet, so run it:
1008-
generateCacheForCSSMap(node, meta);
10091007
if (meta.state.cssMap[node.name]) {
1008+
// it doesn't cover the case where styles are defined after its consumer.
1009+
// e.g.
1010+
// <div css={styles} />
1011+
// const styles = cssMap({ root: { color: 'red' } });
10101012
throw buildCodeFrameError(
10111013
createErrorMessage(ErrorMessages.USE_VARIANT_OF_CSS_MAP),
10121014
node,

0 commit comments

Comments
 (0)