Description
Version
3.0.2
Reproduction link
https://jsfiddle.net/ronald_d_rogers/5mxdpkLj/2/
Steps to reproduce
Make router-view
appearance conditional based on some variable (or simply have it not appear):
<div id="app">
<div v-if="condition">
<router-view />
</div>
</div>
Ensure that the component that matches the route has a beforeRouteEnter
guard, where a function is passed to the next(...)
method (e.g. next(vm => {}
):
export default {
beforeRouteEnter(to, from, next) {
// Poll happens only if you pass in a function to next(...)
next(vm => {})
}
}
Visit that route.
curl http://localhost:8080/route
A poll will happen infinitely until router-view
is created.
In a typical SSR application where an app is created per request, it will never be created.
The end result is a memory leak with an event loop filled with poll's every 16ms.
In the reproduction JS Fiddle, a leak occurs every time you press the SSR Request
button.
If you set dontLeak
to true, the leak stops.
The leak can be verified in the JS Fiddle by clicking on the SSR Request
button a few times (say 20 times), opening Chrome Developer Tools, going to the Performance tab, and in the recording looking at the contents of "Frame".
Here is an example repo as well:
https://github.com/ronald-d-rogers/vue-router-ssr-memory-leak
What is expected?
A new poll does not recurse infinitely for every SSR request.
What is actually happening?
A new poll recurses infinitely for every SSR request.