PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Question By
Unsolved

Dark mode in user dashboard

produkt

Apr 3rd, 2025 09:57 AM

I have added several pages within my user dashboard including some links in the sidebar. When I enable dark mode from the user menu it enables dark mode, obviously. However, if I navigate to another page within the user dashboard the theme switches back to light mode even though the toggle shows it should still be in dark. I have to disable dark mode and then re-enable it to become dark again, OR refresh the page and it switches back to dark.

If I enable dark mode and reload the page, it stays dark. It seems just navigating to new pages doesn't keep the theme until I press refresh. Any ideas on why this is happening?

bobbyiliev

Apr 4th, 2025 11:12 PM

Hey there,

Does this happen only for the new pages that you've added or all of the existing pages as well?

It's likely that navigating between dashboard pages doesn’t trigger a full page reload, which can prevent the dark mode class from being reapplied properly.

A possible fix would be to add a small global script in your layout to set the dark class early, based on localStorage, before Alpine or Livewire load. This ensures the theme sticks between pages.

- Bobby

produkt

Apr 5th, 2025 04:54 AM

It happens on both. The only original dashboard page I have remaining is the change log, but it’s happening on my new custom pages as well as the change log. Do you have an example of such a script you recommend?

Also, I did a fresh install of wave in a test environment, and it occurs there too. On a demo install, there are no additional pages actually, they are all just test links with the exception of the changelog, which the problem occurs there.

lars3

Apr 9th, 2025 01:58 AM

Hello, I just started out a new project in Wave and I experience the same issue. When navigating through the menu the theme switches back to light. A hard refresh the theme is back to black. I can't make much sense of it but it happens on a fresh install, firefox and chrome.

lars3

Apr 9th, 2025 10:25 PM

Some additional information. Localstorage has theme: dark property.

On page reload the html tag is as follows

<html class="dark" lang="en">

On livewire refresh this toggles back to

<html class="dark nprogress-busy" lang="en">

After livewire refresh is done, this is the result, back to light mode.

<html lang="en">

Afterpage refresh back to

<html class="dark" lang="en">

I also noticed a livewire error in the javascript console of my browser, it might be related:

Uncaught SyntaxError: expected expression, got ')'
    safeAsyncFunction https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:1174
    generateFunctionFromString https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:1184
    generateEvaluatorFromString https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:1189
    normalEvaluator https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:1154
    evaluateLater https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:1144
    handler2 https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:3532
    flushHandlers https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:1281
    stopDeferring https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:1286
    deferHandlingDirectives https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:1289
    initTree https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:1479
    start https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:1428
    start https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:1427
    start2 https://wave.localhost/vendor/livewire/livewire.js?id=13b7c601:8813
bobbyiliev

Apr 10th, 2025 12:43 AM

Hi there,

I am trying to reproduce it locally with a fresh new install but it seems to be working as expected:

Do you by any chance have some steps that I could try out locally to reproduce it reliably?

lars3

Apr 10th, 2025 04:12 AM

Hello,

I just spend some time trying to get to the bottom of it. I tried to remove as much code as possible and the problem still persists.

Then I figured it might be platform dependend, as I'm running a Macbook with Herd. So I deployed the application on a server to see. But the problem persists. You can see it here if you register an account: https://aibeacon.eu/

As far as reproducing the problem, it also occurs on a fresh project download so I have very little to point at.

produkt

Apr 10th, 2025 05:20 AM

I'm not able to reproduce your results. Although, I see where some of the confusion is now. Sub-pages under "settings" preserve dark mode but the rest don't. Try navigating to pages that are not under "Settings." Try:

  • Changelog
  • Notifications
  • Public profile
  • Dashboard
lars3

Apr 10th, 2025 06:26 AM

The issue seems to occur on links with 'wire:navigate'. I am kind of working around the issue removing all 'wire:navigate' on the links. This way a hard reload is forced and dark mode is correctly applied. Although this does not solve the actual problem, it does not bother me anymore.

Report
1
produkt

Apr 10th, 2025 06:31 AM

That does not feel like a good option for me. wire:navigate speeds load time and is a better user experience. There must be a better way.

bobbyiliev

Apr 10th, 2025 06:33 AM

Seems like this is discussed here: https://github.com/livewire/livewire/discussions/9191

I will look into it and see if there is a way around the limitation.

produkt

May 31st, 2025 05:57 AM

Any updates on this?