vite-plugin-linaria icon indicating copy to clipboard operation
vite-plugin-linaria copied to clipboard

Style tag duplication for same styles

Open fyapy opened this issue 4 years ago • 4 comments

🐛 Bug report

Current Behavior

When we change file with Linaria styles, we will get new style tag on each change. For example, our changes will be like this: width: 543px; -> width: 545px;(new style tag) -> width: 546px;(new style tag) -> width: 545px;(nothing happens)

image

Desired Behavior

Update existed style tag, and update style tag in width: 545px; (nothing happens) case.

fyapy avatar May 06 '21 21:05 fyapy

@denn1s Sorry, but i don't know how to link my pull request to fix issue😅 PR: https://github.com/denn1s/vite-plugin-linaria/pull/3

fyapy avatar May 06 '21 21:05 fyapy

I am unable to replicate the duplicating issue, have tried on several different setups, would you happen so have a sample project?

after testing the pull request I noticed that handling the css in that way makes it so that it does not go through the rest of the rollup plugin chain, therefore, some features such as postcss stop working. I want to see an example of the duplication to see if I can figure what is causing it in the first place

denn1s avatar May 27 '21 22:05 denn1s

Of course, here is the repository, and a video with a playback example

Example repo: https://github.com/fyapy/vite-plugin-linaria-reproduction Video: https://drive.google.com/file/d/1M3HlVY-y7AUEDW6uZyROFxTomxLW3UvD/view

fyapy avatar May 28 '21 20:05 fyapy

As I understand it, vite assigns an id to each style. But our id is calculated by creating a hash from the style file. And thus, every time we change something in the styles, we get a new id, thus vite considers that this is a completely new css, and creates a new tag, and does not update the old one.

fyapy avatar May 28 '21 21:05 fyapy