Skip to content

fix(theme plugin): use prefix to generate custom theme blocks#4514

Open
pdanpdan wants to merge 1 commit into
saadeghi:masterfrom
pdanpdan:fix/themes-plugin
Open

fix(theme plugin): use prefix to generate custom theme blocks#4514
pdanpdan wants to merge 1 commit into
saadeghi:masterfrom
pdanpdan:fix/themes-plugin

Conversation

@pdanpdan
Copy link
Copy Markdown
Contributor

@pdanpdan pdanpdan commented May 3, 2026

daisyui/theme plugin now:

  • tries to read and use the root option (but it is not the option passed to the daisyui plugin, it must be passed to the daisyui/theme plugin)
  • does not use the prefix option

I cannot find a way to use the same options in both plugins, so what this fixes is:

  • to also use the prefix option (both root and prefix options must be passed to the daisyui/theme plugin)

There are also some small tweaks:

  • consistency in quoting theme names
  • remove redundant checking if root is ':root' to build the dark-mode selector

ref #4513
example of bad behavior: https://play.tailwindcss.com/dwkjhIRnuv?file=css

The code generated by the example (only relevant parts):

/* original themes */
@layer base {
  :root:has(input.d-theme-controller[value=light]:checked),[data-theme=light] {
    color-scheme: light;
    --color-primary: oklch(45% 0.24 277.023);
  }
}
@layer base {
  :root:has(input.d-theme-controller[value=dark]:checked),[data-theme=dark] {
    color-scheme: dark;
    --color-primary: oklch(58% 0.233 277.117);
  }
}
/* first set of overwritten themes - notice absence of prefix */
@layer base {
  :where(:root),:root:has(input.theme-controller[value=light]:checked),[data-theme="light"] {
    color-scheme: light;
    --color-primary: oklch(63% 0.237 25.331);
  }
}
@layer base {
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
      color-scheme: dark;
      --color-primary: oklch(72% 0.219 149.579);
    }
  }
}
@layer base {
  :root:has(input.theme-controller[value=dark]:checked),[data-theme="dark"] {
    color-scheme: dark;
    --color-primary: oklch(72% 0.219 149.579);
  }
}
/* second set of overwritten themes - notice absence of prefix */
@layer base {
  :where(:root),:root:has(input.theme-controller[value=light]:checked),[data-theme="light"] {
    color-scheme: light;
    --color-primary: oklch(55% 0.027 264.364);
  }
}
@layer base {
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
      color-scheme: dark;
      --color-primary: oklch(79% 0.184 86.047);
    }
  }
}
@layer base {
  :root:has(input.theme-controller[value=dark]:checked),[data-theme="dark"] {
    color-scheme: dark;
    --color-primary: oklch(79% 0.184 86.047);
  }
}

`daisyui/theme` plugin now:
- tries to read and use the `root` option (but it is not the option passed to the `daisyui` plugin, it must be passed to the `daisyui/theme` plugin)
- does not use the `prefix` option

I cannot find a way to use the same options in both plugins, so what this fixes is:
- to also use the `prefix` option (both `root` and `prefix` options must be passed to the `daisyui/theme` plugin)

There are also some small tweaks:
- consistency in quoting theme names
- remove redundant checking if root is ':root' to build the dark-mode selector

ref saadeghi#4513
example of bad behavior: https://play.tailwindcss.com/dwkjhIRnuv?file=css
@pdanpdan
Copy link
Copy Markdown
Contributor Author

pdanpdan commented May 3, 2026

A fixed play (after the changes in this PR) would need to include the prefix (and root if needed) for each call to daisyui/theme: https://play.tailwindcss.com/AO6SXsZotq?file=css

@saadeghi do you have a solution for sharing the options from the call to the daisyui plugin?

@saadeghi saadeghi self-assigned this May 3, 2026
@saadeghi
Copy link
Copy Markdown
Owner

saadeghi commented May 3, 2026

@saadeghi do you have a solution for sharing the options from the call to the daisyui plugin?

You mean using the prefix defined in daisyui plugin, in the daisyui/theme plugin?

@pdanpdan
Copy link
Copy Markdown
Contributor Author

pdanpdan commented May 3, 2026

Yes

@saadeghi
Copy link
Copy Markdown
Owner

saadeghi commented May 3, 2026

I don't think so. Unless we read the file manually instead of using the Tailwind API, but that would create more problems which is not worth it.

By the way, do we need prefix for the themes? I'm trying to understand in what situation this would be helpful.

@pdanpdan
Copy link
Copy Markdown
Contributor Author

pdanpdan commented May 3, 2026

The themes set .theme-controller (see above extract)

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.

2 participants