Perfect Next.js dark mode in 2 lines of code. Support System preference and any other theme with no flashing
by pacocourseyTypeScript
Last 12 weeks · 0 commits
2 of 6 standards met
Problem Node.js 25+ ships an experimental Web Storage API that aliases to . This breaks on Node.js 25+ because the SSR guard evaluates at module load time: This causes: on the server calls on the server nonce rendered empty during SSR on startup Reported in #389. Fix Replace with . is a browser-only API — Node.js does not expose it, even in v25+. This is a reliable cross-version SSR guard: Changes — 2 occurrences updated Testing Tested on Node.js v24.15.0, pnpm v10.32.1.
What happened? A bug encontred! Nextjs 16.2.1 Issue: Encountered a script tag while rendering React component. Scripts inside React components are never executed when rendering on the client. Consider using template tag instead (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template). Version 0.4.6 What browsers are you seeing the problem on? Google-Chrome, Safari, Orion.
Repository: pacocoursey/next-themes. Description: Perfect Next.js dark mode in 2 lines of code. Support System preference and any other theme with no flashing Stars: 6336, Forks: 255. Primary language: TypeScript. Languages: TypeScript (100%). License: MIT. Homepage: https://next-themes-example.vercel.app/ Topics: dark-mode, dark-theme, nextjs, react, themes. Latest release: v0.4.6 (1y ago). Open PRs: 23, open issues: 46. Last activity: 6mo ago. Community health: 42%. Top contributors: pacocoursey, trm217, BlankParticle, dependabot[bot], brunocrosier, 0xflotus, Unsleeping, amrhassab, andreacassani, arturbien and others.