[bug]: adding shadcn to existing remix project with dark mode creates bug
Describe the bug
Hi just wanted to share a small bug I observed.
I had an existing project in remix with darkMode enabled i.e. in tailwind.config.ts I already had:
export default {
...
darkMode: 'class'
}
Adding shadcn updated the config to this incorrect setting which broke dark mode
export default {
...
darkMode: ['class', 'class']
}
Understand this is a niche and uncommonly faced issue - just pointing it out - and it may apply to other frameworks not just remix.
Affected component/components
Dark Mode
How to reproduce
- Have existing tailwind/remix project with darkMode enabled but no shadcn
- Install shadcn
Codesandbox/StackBlitz link
No response
Logs
System Info
Remix, Tailwind, is a code issue not an infrastructure issue.
Before submitting
- [x] I've made research efforts and searched the documentation
- [x] I've searched for existing issues
Hey, had a brief look at it this morning - first time I have actually interacted with the shadcn codebase so didn't make a pull request, but I have identified the cause of this error.
In this configuration update file, a function addTailwindConfigProperty is called to add dark mode (line 99 call, line 121 definition). (As far as I can tell, this function is only called in the entire shadcn codebase to add dark mode, despite supporting much more general functionality).
First this function checks if a darkMode property exists in the config (line 135). If it does not, then it adds it. This part seems to be correct, and is likely the execution path for most projects running this function as they don't already have darkMode initialized.
However, after that conditional block is over, it subsequently checks if the property does exist and satisfies a particular type condition (line 152). In this case, if the property is a string it converts it to an array containing that single element and crucially then adds the new value to the array without checking if the value is already in the array (lines 157-161). In my case, this converts the string 'class' to the array ['class', 'class']
This is a relatively simple fix - just check if the existing string value is the same as the value to be added, and do nothing if it is the same. I'm not currently set up to contribute to this repo, but if I do in the future I will submit a pull request. For those contributors reading, this is literally a one line fix!