Repository navigation
perf(nuxt): drop unctx from client environment (+ defu in single-object config) - #36371
Conversation
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/vite-server
@nuxt/webpack-builder
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughThe change adds a Nuxt context wrapper with client-side singleton contexts and server-side Priority: ⬇️ Low 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
<!-- ☝️ PR title should follow conventional commits (https://conventionalcommits.org). In particular, the title should start with one of the following types: - docs: 📖 Documentation (updates to the documentation or readme) - fix: 🐞 Bug fix (a non-breaking change that fixes an issue) - feat: ✨ New feature/enhancement (a non-breaking change that adds functionality or improves existing one) - feat!/fix!:⚠️ Breaking change (fix or feature that would cause existing functionality to change) - chore: 🧹 Chore (updates to the build process or auxiliary tools and libraries) --> ### 🔗 Linked issue <!-- If it resolves an open issue, please link the issue here. For example "Resolves #123" --> * resolves #1138 ### 📚 Description <!-- Describe your changes in detail --> <!-- Why is this change required? What problem does it solve? --> Nuxt 4.6.0 changed where it stores the browser instance, moving it from `unctx` to `globalThis.__nuxt_app_ctx__` (nuxt/nuxt#36371). Since this addon was still registering the instance directly through `unctx`, `useNuxtApp()` fails to pick it up on 4.6.x and throws `NUXT_E1001`, which breaks existing stories. To fix this, we switch to `getNuxtAppCtx` from `#app/nuxt` so it points to the correct store regardless of the Nuxt version. I've also removed the `unctx` dependency since it's no longer needed. For testing, I packed the addon and ran `storybook build` against a minimal Nuxt 4.6.1 setup with a story using `useNuxtApp()`. It threw `NUXT_E1001` before the fix, but now builds cleanly without any console errors. I also verified that the playground still builds and works fine on Nuxt 4.4.8, and all unit tests pass.
<!-- ☝️ PR title should follow conventional commits (https://conventionalcommits.org). In particular, the title should start with one of the following types: - docs: 📖 Documentation (updates to the documentation or readme) - fix: 🐞 Bug fix (a non-breaking change that fixes an issue) - feat: ✨ New feature/enhancement (a non-breaking change that adds functionality or improves existing one) - feat!/fix!:⚠️ Breaking change (fix or feature that would cause existing functionality to change) - chore: 🧹 Chore (updates to the build process or auxiliary tools and libraries) --> <!-- If it resolves an open issue, please link the issue here. For example "Resolves #123" --> * resolves #1138 <!-- Describe your changes in detail --> <!-- Why is this change required? What problem does it solve? --> Nuxt 4.6.0 changed where it stores the browser instance, moving it from `unctx` to `globalThis.__nuxt_app_ctx__` (nuxt/nuxt#36371). Since this addon was still registering the instance directly through `unctx`, `useNuxtApp()` fails to pick it up on 4.6.x and throws `NUXT_E1001`, which breaks existing stories. To fix this, we switch to `getNuxtAppCtx` from `#app/nuxt` so it points to the correct store regardless of the Nuxt version. I've also removed the `unctx` dependency since it's no longer needed. For testing, I packed the addon and ran `storybook build` against a minimal Nuxt 4.6.1 setup with a story using `useNuxtApp()`. It threw `NUXT_E1001` before the fix, but now builds cleanly without any console errors. I also verified that the playground still builds and works fine on Nuxt 4.4.8, and all unit tests pass. (cherry picked from commit f04a310)

🔗 Linked issue
📚 Description
this drops a couple of unneeded deps - unctx brings in an extra 1 KB which isn't needed in the browser, where there is no
AsyncLocalStorage... and defu was being used even when there was only one app.config - an unnecessary call