perf(nuxt): drop `unctx` from client environment (+ `defu` in single-object config) by danielroe · Pull Request #36371 · nuxt/nuxt · GitHub
Skip to content

perf(nuxt): drop unctx from client environment (+ defu in single-object config) - #36371

Merged
danielroe merged 2 commits into
mainfrom
perf/drop-client-deps
Sep 19, 2026
Merged

danielroe merged 2 commits into
mainfrom
perf/drop-client-deps

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 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

@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

@github-actions github-actions Bot added 5.x ⚡ performance Performance degradation or optimization opportunity labels Sep 19, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

pnpm add https://pkg.pr.new/nuxt/nuxt/@nuxt/kit@36371
npm i https://pkg.pr.new/nuxt/nuxt/@nuxt/kit@36371
yarn add https://pkg.pr.new/nuxt/nuxt/@nuxt/kit@36371.tgz

@nuxt/nitro-server

pnpm add https://pkg.pr.new/nuxt/nuxt/@nuxt/nitro-server@36371
npm i https://pkg.pr.new/nuxt/nuxt/@nuxt/nitro-server@36371
yarn add https://pkg.pr.new/nuxt/nuxt/@nuxt/nitro-server@36371.tgz

nuxt

pnpm add https://pkg.pr.new/nuxt/nuxt@36371
npm i https://pkg.pr.new/nuxt/nuxt@36371
yarn add https://pkg.pr.new/nuxt/nuxt@36371.tgz

@nuxt/rspack-builder

pnpm add https://pkg.pr.new/nuxt/nuxt/@nuxt/rspack-builder@36371
npm i https://pkg.pr.new/nuxt/nuxt/@nuxt/rspack-builder@36371
yarn add https://pkg.pr.new/nuxt/nuxt/@nuxt/rspack-builder@36371.tgz

@nuxt/schema

pnpm add https://pkg.pr.new/nuxt/nuxt/@nuxt/schema@36371
npm i https://pkg.pr.new/nuxt/nuxt/@nuxt/schema@36371
yarn add https://pkg.pr.new/nuxt/nuxt/@nuxt/schema@36371.tgz

@nuxt/vite-builder

pnpm add https://pkg.pr.new/nuxt/nuxt/@nuxt/vite-builder@36371
npm i https://pkg.pr.new/nuxt/nuxt/@nuxt/vite-builder@36371
yarn add https://pkg.pr.new/nuxt/nuxt/@nuxt/vite-builder@36371.tgz

@nuxt/vite-server

pnpm add https://pkg.pr.new/nuxt/nuxt/@nuxt/vite-server@36371
npm i https://pkg.pr.new/nuxt/nuxt/@nuxt/vite-server@36371
yarn add https://pkg.pr.new/nuxt/nuxt/@nuxt/vite-server@36371.tgz

@nuxt/webpack-builder

pnpm add https://pkg.pr.new/nuxt/nuxt/@nuxt/webpack-builder@36371
npm i https://pkg.pr.new/nuxt/nuxt/@nuxt/webpack-builder@36371
yarn add https://pkg.pr.new/nuxt/nuxt/@nuxt/webpack-builder@36371.tgz

commit: 2f31569

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 0f4589b3-6d4b-40d2-967a-882fddd7711c

📥 Commits

Reviewing files that changed from the base of the PR and between bef2789 and 2f31569.

📒 Files selected for processing (6)
  • packages/nuxt/src/app/internal/context.ts
  • packages/nuxt/src/app/nuxt.ts
  • packages/nuxt/src/core/nuxt.ts
  • packages/nuxt/src/core/templates.ts
  • packages/nuxt/test/templates.test.ts
  • test/bundle.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The change adds a Nuxt context wrapper with client-side singleton contexts and server-side unctx fallback. Nuxt uses the local wrapper, and the transform plugin runs only in server builds. App configuration output omits defuFn when no config layers exist. Tests and bundle snapshots cover the updated output and sizes.

Priority: ⬇️ Low

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarises both primary changes: removing client-side unctx usage and avoiding defu for a single app configuration.
Description check ✅ Passed The description directly explains the removal of unnecessary client-side dependencies and the optimisation to avoid an unnecessary defu call.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

@danielroe
danielroe added this pull request to the merge queue Sep 19, 2026
Merged via the queue into main with commit 1b227df Sep 19, 2026
39 checks passed
@danielroe
danielroe deleted the perf/drop-client-deps branch September 19, 2026 08:06
@github-actions github-actions Bot mentioned this pull request Sep 18, 2026
danielroe added a commit that referenced this pull request Sep 23, 2026
@github-actions github-actions Bot mentioned this pull request Sep 17, 2026
danielroe added a commit that referenced this pull request Sep 23, 2026
danielroe added a commit that referenced this pull request Sep 23, 2026
@github-actions github-actions Bot mentioned this pull request Oct 5, 2026
huang-julien pushed a commit to nuxt-modules/storybook that referenced this pull request Oct 16, 2026
<!--
☝️ 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.
huang-julien pushed a commit to nuxt-modules/storybook that referenced this pull request Oct 16, 2026
<!--
☝️ 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x ⚡ performance Performance degradation or optimization opportunity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant