Skip to content

perf: defer non-critical client plugin work until after hydration - #490

Merged
atinux merged 3 commits into
mainfrom
perf/delay-writing-pref
Oct 27, 2026
Merged

atinux merged 3 commits into
mainfrom
perf/delay-writing-pref

Conversation

@danielroe

Copy link
Copy Markdown
Contributor

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

this trims work from the client plugin before hydration.

  1. we now wait until the app has hydrated and the browser is idle before setting preference.

    it's almost always the value that was just read from it (and with storage: 'cookie' this also invokes useCookie, sets up watchers, etc.). this also fixes a small issue in SSR mode with local or session storage, where the default preference used to overwrite the stored value before app:mounted then wrote it back again

  2. the prefers-color-scheme listener is now deferred, rather than running before hydration.

  3. the plugin now reuses the inline script's value until hydration.

    with preference: 'system', the inline script resolves the color scheme , but previously we re-resolved it - meaning potentially up to six extra matchMedia calls.

@danielroe
danielroe requested a review from atinux October 26, 2026 23:52
@netlify

netlify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for nuxt-color-mode canceled.

Name Link
🔨 Latest commit 1d29fb6
🔍 Latest deploy log https://app.netlify.com/projects/nuxt-color-mode/deploys/6adfe7cc7c3b09e9fd58ab2c

@pkg-pr-new

pkg-pr-new Bot commented Oct 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxtjs/color-mode@490

commit: 1d29fb6

Comment thread src/runtime/plugin.client.ts
@atinux
atinux merged commit 49fd734 into main Oct 27, 2026
12 checks passed
@atinux
atinux deleted the perf/delay-writing-pref branch October 27, 2026 14:53
@github-actions github-actions Bot mentioned this pull request Oct 27, 2026

This branch was successfully deployed

1 active deployment
preview — 1d29fb69 Deployed Oct 26, 2026 by danielroe via Deploy Playground #898
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants