docs: add Tailwind v4 data-theme styling guidance - #395
Open
luisangelrod wants to merge 2 commits into
Open
Conversation
The README's 'Avoid Hydration Mismatch' section only documents the mounted-state workaround. But when using Tailwind v4 with next-themes' default data-theme attribute, hydration mismatch can be avoided entirely — because the attribute is set by next-themes' injected inline script before React hydrates, so component class names never change between server and client render. Fixes pacocoursey#364 Adds a new '#### Tailwind v4 with data attributes' subsection under 'With TailwindCSS' showing: - The @custom-variant dark CSS rule for globals.css - That ThemeProvider needs no attribute prop (data-theme is the default) - Why this sidesteps the hydration mismatch (attribute is CSS-driven, not React-driven)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #364
Adds a Tailwind v4 example that uses next-themes' default
data-themeattribute with@custom-variant.For CSS-only theme styling, this lets Tailwind respond to the attribute set by next-themes' injected browser script without branching rendered markup on
useTheme. The example keeps<html suppressHydrationWarning>, and the docs still direct readers to the mounted pattern whenuseThemevalues change rendered markup.What's added
globals.css
ThemeProvider — no
attributeprop is needed becausedata-themeis the default:Tailwind dark classes then work normally:
Validation
prettier next-themes/README.md --checkgit diff --check