Skip to content

Commit 691933f

Browse files
committed
update
1 parent 345711a commit 691933f

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

src/hooks/useStyleRegister.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import StyleContext, {
1515
ATTR_MARK,
1616
CSS_IN_JS_INSTANCE,
1717
} from '../StyleContext';
18-
import { isClientSide, normalizeValue, toStyleStr, where } from '../util';
18+
import { isClientSide, isNonNullable, toStyleStr, where } from '../util';
1919
import {
2020
CSS_FILE_STYLE,
2121
existPath,
@@ -323,10 +323,7 @@ export const parseStyle = (
323323
appendStyle(key, item);
324324
});
325325
} else {
326-
// 如果是 padding 属性,并且值为 undefined,则转换为 0
327-
if (key.startsWith('padding')) {
328-
appendStyle(key, normalizeValue(actualValue));
329-
} else {
326+
if (isNonNullable(actualValue)) {
330327
appendStyle(key, actualValue);
331328
}
332329
}

src/util/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ export function where(options?: {
201201
return hashPriority === 'low' ? `:where(${hashSelector})` : hashSelector;
202202
}
203203

204-
export const isNullable = <T>(val: T): val is Extract<T, null | undefined> => {
205-
return val === null || val === undefined;
206-
};
207-
208-
export const normalizeValue = <T>(val: T) => {
209-
return isNullable(val) ? 0 : val;
204+
export const isNonNullable = <T>(val: T): val is NonNullable<T> => {
205+
return val !== undefined && val !== null;
210206
};

tests/index.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,6 @@ describe('csssinjs', () => {
978978

979979
const styleContent = styles[styles.length - 1];
980980

981-
expect(styleContent.innerHTML).toContain('padding:0');
981+
expect(styleContent.innerHTML).not.toContain('padding');
982982
});
983983
});

0 commit comments

Comments
 (0)