Skip to content

docs(integrations): fallback to auto for better dark mode support on vite ssr#6062

Merged
benjamincanac merged 2 commits intov4from
docs/ssr-color-mode
Feb 17, 2026
Merged

docs(integrations): fallback to auto for better dark mode support on vite ssr#6062
benjamincanac merged 2 commits intov4from
docs/ssr-color-mode

Conversation

@atinux
Copy link
Member

@atinux atinux commented Feb 16, 2026

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)

📚 Description

Avoid FOUC when value was 'auto' after first load.

@github-actions github-actions bot added the v4 #4488 label Feb 16, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

Documentation update to the SSR integration guide modifying three example blocks. Changes: navigation.icon value updated from i-simple-icons-markdown to i-lucide-server; some Vue imports adjusted to use import type { DefineComponent } from 'vue' for type-only usage; color-scheme handling now defaults the vueuse-color-scheme localStorage value to 'auto' using || 'auto' and checks theme === 'auto' for media-query fallback rather than theme === null. Other edits are formatting; no exported/public API changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: updating documentation to fallback to 'auto' for better dark mode support on Vite SSR, which aligns with the core fix addressing FOUC issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description directly addresses the changes: avoiding FOUC when color-mode value is 'auto' after first load, which aligns with the color scheme handling updates in the documentation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docs/ssr-color-mode

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Fix all issues with AI agents
Verify each finding against the current code and only fix it if needed.


In `@docs/content/docs/1.getting-started/6.integrations/6.ssr.md`:
- Around line 121-122: The current snippet should default the stored scheme to
'auto' and treat explicit 'auto' the same as missing value so system preference
is respected; update the logic around theme (from
localStorage.getItem('vueuse-color-scheme')) so theme is set to 'auto' when
falsy and change the condition to check theme === 'dark' || (theme === 'auto' &&
window.matchMedia('(prefers-color-scheme: dark)').matches), referencing the
theme variable, localStorage.getItem('vueuse-color-scheme') and
window.matchMedia to ensure dark mode is applied when either explicitly set to
'dark' or when 'auto' (explicit or default) and the media query matches.
🧹 Nitpick comments (1)
🤖 Fix all nitpicks with AI agents
Verify each finding against the current code and only fix it if needed.


In `@docs/content/docs/1.getting-started/6.integrations/6.ssr.md`:
- Around line 121-122: The current snippet should default the stored scheme to
'auto' and treat explicit 'auto' the same as missing value so system preference
is respected; update the logic around theme (from
localStorage.getItem('vueuse-color-scheme')) so theme is set to 'auto' when
falsy and change the condition to check theme === 'dark' || (theme === 'auto' &&
window.matchMedia('(prefers-color-scheme: dark)').matches), referencing the
theme variable, localStorage.getItem('vueuse-color-scheme') and
window.matchMedia to ensure dark mode is applied when either explicitly set to
'dark' or when 'auto' (explicit or default) and the media query matches.
docs/content/docs/1.getting-started/6.integrations/6.ssr.md (1)

121-122: LGTM! This fix correctly handles the 'auto' color scheme value.

The updated logic now properly handles when vueuse-color-scheme is explicitly set to 'auto' in localStorage. Previously, if a user had 'auto' stored, the old condition checking for null would fail, and dark mode wouldn't be applied even when the system preferred dark mode. By defaulting to 'auto' and checking for it in the condition, the media query is now correctly evaluated in both cases:

  • When no value is stored (defaults to 'auto')
  • When 'auto' is explicitly stored

This effectively prevents FOUC on initial SSR load as described in the PR objectives.

Optional: Consider defensive error handling

For production use, users might want to wrap localStorage access in a try-catch, as it can throw errors in restricted contexts (e.g., some private browsing modes or sandboxed iframes). However, keeping documentation examples simple and clear is often more valuable than defensive code.

 <script>
+try {
   const theme = localStorage.getItem('vueuse-color-scheme') || 'auto';
   if (theme === 'dark' || (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
       document.documentElement.classList.add('dark');
   } else {
       document.documentElement.classList.remove('dark');
   }
+} catch (e) {
+  // Fallback to system preference if localStorage is unavailable
+  if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
+      document.documentElement.classList.add('dark');
+  }
+}
 </script>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/content/docs/1.getting-started/6.integrations/6.ssr.md` around lines 121
- 122, The current snippet should default the stored scheme to 'auto' and treat
explicit 'auto' the same as missing value so system preference is respected;
update the logic around theme (from localStorage.getItem('vueuse-color-scheme'))
so theme is set to 'auto' when falsy and change the condition to check theme ===
'dark' || (theme === 'auto' && window.matchMedia('(prefers-color-scheme:
dark)').matches), referencing the theme variable,
localStorage.getItem('vueuse-color-scheme') and window.matchMedia to ensure dark
mode is applied when either explicitly set to 'dark' or when 'auto' (explicit or
default) and the media query matches.

@benjamincanac benjamincanac changed the title docs(vite): fallback to auto for better dark mode support on ssr docs(integrations): fallback to auto for better dark mode support on vite ssr Feb 17, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 17, 2026

npm i https://pkg.pr.new/@nuxt/ui@6062

commit: 95fc196

@benjamincanac benjamincanac merged commit 89a4590 into v4 Feb 17, 2026
18 checks passed
@benjamincanac benjamincanac deleted the docs/ssr-color-mode branch February 17, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v4 #4488

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants