fix(theme): inconsistent results with different algorithm order (#38481)

* fix(theme): inconsistent results with different algorithm order

* fix: revert

* fix: revert

* fix: revert again

* test: update

* fix: lint
This commit is contained in:
Dunqing 2022-11-10 17:18:40 +08:00 committed by GitHub
parent f25da16c52
commit 382b2cacf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -153,4 +153,27 @@ describe('ConfigProvider.Theme', () => {
theme.defaultConfig.hashed = false;
});
it('The order does not affect the result', () => {
const tokens = {
a: {},
b: {},
};
const Token: React.FC<{ type: 'a' | 'b' }> = ({ type }) => {
const [, token] = useToken();
tokens[type] = token;
return null;
};
render(
<>
<ConfigProvider theme={{ algorithm: [darkAlgorithm, compactAlgorithm] }}>
<Token type="a" />
</ConfigProvider>
<ConfigProvider theme={{ algorithm: [compactAlgorithm, darkAlgorithm] }}>
<Token type="b" />
</ConfigProvider>
</>,
);
expect(tokens.a).toMatchObject(tokens.b);
});
});

View File

@ -32,7 +32,7 @@ const derivative: DerivativeFunc<SeedToken, MapToken> = (token, mapToken) => {
// Dark tokens
...colorPalettes,
// Colors
...genColorMapToken(mapToken ?? token, {
...genColorMapToken(token, {
generateColorPalettes,
generateNeutralColorPalettes,
}),