Nuxt 3: SSR memory leak in `useHead()` with computed getter on the server
See original GitHub issueEnvironment
- Operating System:
Linux
- Node Version:
v16.15.0
- Nuxt Version:
3.0.0-rc.11
- Nitro Version:
0.5.4
- Package Manager:
npm@8.5.5
- Builder:
vite
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Reproduction
<script setup lang="ts">
import { useHead } from '#head';
// ...
useHead(() => getMeta(meta.value));
</script>
Describe the bug
Using a computed getter (() => ...)
) as an argument of the getHead()
results to memory leak on the server.
See also: https://github.com/nuxt/framework/issues/8003.
Temporary fix
<script setup lang="ts">
import { useHead } from '#head';
// ...
if (process.server) {
useHead(getMeta(meta.value));
} else {
useHead(() => getMeta(meta.value));
}
</script>
Additional context
Memory consumption
Production build of an application, 60 requests per second, 10 minutes of load (36 000 requests).
Before fix
After fix
Memory difference
Flame graph
Table
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Solving server-side memory leaks on Nuxt.js - Medium
In this article, you'll find our historic with server-side memory leaks on Nuxt.js, as well as the process we established to detect them...
Read more >Nuxt huge memory usage / leakage and how to prevent
It will cause memory leak on server-side. So using Vue.use() inside injection function may cause memory leakage not Vue.use() itself.
Read more >Functions | VueUse
useEventSource-an EventSource or Server-Sent-Events instance opens a persistent connection to ... resolveRef-normalize value/ref/getter to ref or computed.
Read more >Scaling Nuxt : r/Nuxt - Reddit
Do you guys encounter any performance bottlenecks with server-side rendering in Nuxt? I'm working on a what I would consider a medium scale ......
Read more >Nuxt Collate 030421 | PDF | Namespace - Scribd
You do not need to add ssr: true to your nuxt config in order to enable server-side-rendering as it is enabled by default....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The issue here was not actually (IIRC) the use of
useHead
within the component but rather that Nuxt itself was calling use head in a plugin meaning thatcomputed
was being called outside of component setup.I believe this is resolved as computed is no longer being called by
@vueuse/head
, and functional/computed types are excluded fromapp.head
innuxt.config
.Let me know if not and I’ll happily reopen.
@antlionguard Datadog APM with Continuous profiler.