Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generated self-referencing CSS variables #82

Merged
merged 8 commits into from
Oct 21, 2024

Conversation

wtto00
Copy link
Contributor

@wtto00 wtto00 commented Oct 18, 2024

Fix incorrect output like blow:

.dark {
    --un-preset-theme-colors-container: var(--un-preset-theme-colors-container);
    --un-preset-theme-colors-container--alpha: var(--un-preset-theme-colors-container--alpha, 1);
    --un-preset-theme-colors-border: var(--un-preset-theme-colors-border);
    --un-preset-theme-colors-border--alpha: var(--un-preset-theme-colors-border--alpha, 1);
    --un-preset-theme-colors-text: var(--un-preset-theme-colors-text);
    --un-preset-theme-colors-text--alpha: var(--un-preset-theme-colors-text--alpha, 1);
    --un-preset-theme-colors-primary: var(--un-preset-theme-colors-primary);
    --un-preset-theme-colors-primary--alpha: var(--un-preset-theme-colors-primary--alpha, 1);
    --un-preset-theme-colors-primary-border: var(--un-preset-theme-colors-primary-border);
    --un-preset-theme-colors-primary-border--alpha: var(--un-preset-theme-colors-primary-border--alpha, 1);
}

fix #81

TODO: Add tests.
The existing tests cannot identify this issue. I referred to https://github.com/unocss/unocss/blob/main/packages/runtime/test-dom/runtime-dom.test.ts and attempted the runtime-dom vitest tests, but they also failed to detect this problem.

Regarding the unit test, I wasn't able to find a better solution, so I had to resort to comparing the bundled CSS output.

My approach to fixing the issue is to check whether the CSS variable already exists when assigning it. If it does, the existing value will be used rather than generating a new one.

@wtto00 wtto00 marked this pull request as ready for review October 19, 2024 16:29
Copy link
Member

@Dunqing Dunqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!

@Dunqing Dunqing added this pull request to the merge queue Oct 21, 2024
Merged via the queue into unocss-community:main with commit 7621da4 Oct 21, 2024
3 checks passed
@Dunqing
Copy link
Member

Dunqing commented Oct 21, 2024

I just found the test file is not in a suitable place where we should move to https://github.com/unpreset/unocss-preset-theme/tree/main/tests

@wtto00
Copy link
Contributor Author

wtto00 commented Oct 21, 2024

I just found the test file is not in a suitable place where we should move to https://github.com/unpreset/unocss-preset-theme/tree/main/tests

Another pr by me or push to main by you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

最新版本的vite和unocss不兼容,样式未生效
2 participants