Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 49a4048

Browse files
committed
fix(sheet.ts): Fixed to pinpoint only the assigned class name
1 parent 1407bef commit 49a4048

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/core/method/sheet.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ export function sheet<T extends ClassesObjectType>(object: T & ClassesObjectType
1313
get: function (target, prop: string) {
1414
if (typeof prop === 'string' && prop in target) {
1515
const className = prop + '_' + base62Hash;
16-
if (isInDevelopment) injectCSS(className, styleSheet, 'sheet');
16+
const mediaBlockRegex = new RegExp(`(?:\\@media[^{]+\\{[\\s\\S]*?\\.${className}\\s*\\{[\\s\\S]*?\\})`, 'g');
17+
const classRuleRegex = new RegExp(`\\n\\.${className}\\s*\\{[\\s\\S]*?\\}`, 'g');
18+
const sheet = (Array.from(styleSheet.match(mediaBlockRegex) || []) as string[])
19+
.concat(Array.from(styleSheet.match(classRuleRegex) || []) as string[])
20+
.join('');
21+
if (isInDevelopment) injectCSS(className, sheet, 'sheet');
1722

1823
return isInDevelopment ? className : styles[className];
1924
}

0 commit comments

Comments
 (0)