Abdulkader Safi

LaralCN-UI 0.5.2: dark mode had two switches

LaralCN-UI 0.5.2 fixes two bugs in the Composer CLI. Dark mode followed the .dark class for colours but the OS setting for dark: utilities, so the UI could end up half dark, and ui:init reported success on apps that could not render a single component.

4 min read

Share
Two outline buttons on a dark page, the left one wrongly light because it followed the OS setting, the right one dark as intended.

LaralCN-UI 0.5.2 went out on 29 Nov 2026 with two fixes to the Composer CLI. The first was found during the docs review from the last post: dark mode had two switches, and they could disagree. The second was a ui:init that printed a warning, exited 0 and left you with an app where the first <x-ui.button> crashed. Both lived in the package (PR #4). Registry fixes reach people on merge; these needed a tag.

Half the UI went dark

The theme that ui:init writes defines every colour token twice: once in :root and once under a .dark class. Toggle the class on <html> and bg-background, text-foreground and the rest switch over. That part worked.

The trouble was the components that also use Tailwind's dark: variant. The outline button is one of them:

'outline'
    => 'border border-input bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50',

Tailwind v4's dark: variant follows prefers-color-scheme unless you tell it otherwise. So on a light OS with .dark set, the tokens went dark and dark:bg-input/30 never applied: a light-looking outline button on a dark page. A dark OS with no class did the opposite. Carousel and a few other components had the same split. My fault. I had only tested with the OS in dark mode and the class set, the one case where both switches agree.

One line in the theme block

The fix is to point the dark: variant at the same class the tokens use. The theme stub now opens with it:

/*
 * The dark tokens below live under a .dark class. Tailwind v4's dark: variant
 * follows prefers-color-scheme by default, so point it at the same class or
 * dark: utilities and the tokens disagree whenever the OS and the class do.
 */
@custom-variant dark (&:where(.dark, .dark *));

ui:init writes the theme between sentinel markers and replaces that block in place, so existing projects pick up the line by running ui:init again. CSS outside the markers is left alone. In the rebuilt docs CSS, dark:bg-input/30 now compiles under :where(.dark,.dark *) and the string prefers-color-scheme appears 0 times.

PR #3 had added a paragraph to the Theming page telling people to paste this line by hand. That paragraph now says the block already includes it.

ui:init passed while the app could not render

Every component funnels its classes through TailwindMerge::merge(), so gehrisandro/tailwind-merge-laravel is a hard requirement. Before 0.5.2, ui:init noticed when it was missing, printed a yellow warning and exited 0. Green output. Then a fatal error on the first page that used a component.

Now ui:init offers to install it:

private function installTailwindMerge(Composer $composer): bool
{
    if (
        !$this->input->isInteractive() ||
        !$this->confirm(
            self::TAILWIND_MERGE . " is missing. Install it now?",
            true,
        )
    ) {
        return false;
    }

    if (!$composer->requirePackages([self::TAILWIND_MERGE], false, $this->output)) {
        return false;
    }

    $this->line(
        "  <fg=green>✓</> " . self::TAILWIND_MERGE . " installed",
    );

    return true;
}

Composer here is Laravel's own Illuminate\Support\Composer helper, so the CLI did not need a new dependency. If you decline or composer require fails, the command prints the exact composer require line and returns exit code 1. A non-interactive run (-n or CI) gets the same failure and never installs a package on its own. Changing someone's composer.json from a CI job without asking felt wrong.

The earlier steps, such as publishing the config and writing the theme block, still run first. So after you install the package by hand, a second ui:init has nothing left to redo except confirm it.

Testing without installing anything

InitCommandTest mocks Composer, so the suite never runs a real composer require. It covers the yes path, a declined prompt, --no-interaction and a failed install, and it asserts that the @custom-variant line lands in the CSS file. The package suite went from 123 to 126 passing tests, and ui:diff reported no differences from the registry.

The release itself is commit c1969dc. It bumps version in both composer.json files (the root manifest Packagist reads and the path-repo shim the docs site installs from) and refreshes website/composer.lock.

Upgrading from 0.5.1

composer update safi/laralcn-ui
php artisan ui:init

The second command rewrites the theme block with the new line. If you skip it, the CLI is updated but your CSS still has the old block, and the half-dark bug stays.

Where it is

composer require --dev safi/laralcn-ui
php artisan ui:init
php artisan ui:add button

Release notes: gh release view v0.5.2 or the Releases page on GitHub. Docs: https://laralcn-ui.abdulkadersafi.com (dark mode is covered on the Theming page). Code: https://github.com/Abdulkader-Safi/LaralCN-UI, MIT licensed.

Next: right-to-left support, where about a hundred physical utilities became logical ones and the docs gained an /ar version.

Last updated 1 Dec 2026 · filed under Laravel, blade, tailwindcss, laralcn-ui

Every entry on this project

26 build notes, in order

Including the ones where nothing worked. You are on part 8.

Read the series →

FAQ

Frequently asked questions

I run my own dark mode toggle. Do I need anything besides the new line?

No. As long as your toggle adds or removes .dark on <html> (or any ancestor), both the tokens and the dark: utilities now follow it.

What if I want dark mode to follow the OS instead of a class?

Add .dark to <html> from a small script that reads matchMedia('(prefers-color-scheme: dark)'). Removing the @custom-variant line would split the two switches again, since the tokens only respond to the class.

Will ui:init touch my composer.json in CI?

No. With -n or no TTY it skips the prompt, prints the composer require command and exits 1, so the pipeline fails loudly instead of installing anything.

Did the components change in this release?

No. Both fixes are in the CLI and the theme stub. Component files in your app stay as they are.

Written by

Abdulkader Safi

Software Engineer

Lead engineer at DSRPT, from Lebanon and based in Kuwait. I write about the tools and bugs from real client work, with the numbers I measured.

About me → GitHub LinkedIn

Need this kind of work done on your project?

Start a project →

Keep reading

More from LaralCN-UI: shadcn-style Blade components and blocks you own

All 26 entries →