Skip to content

Provide way to destroy app in SSR #9463

Open
@ronald-d-rogers

Description

@ronald-d-rogers

What problem does this feature solve?

This issue is related to: vuejs/vue-router#2606
Providing a way to destroy the app or mark the SSR request as complete (maybe on $ssrContext) is a potential fix to this problem, though maybe not the best one.

To recap:
A memory leak happens when the router-view is programmed to appear conditionally, and the component matching the view has a beforeRouteEnter guard and a callback is passed to it's next(...) method (e.g. next(vm => {})).

This will cause vue-router to poll every 16ms until the router-view materializes.

In a typical SSR application an instance of the app is created per request, which means the router-view will never appear, causing infinitely recursing poll methods.

What does the proposed API look like?

A potential fix to this would be to detect when the app is destroyed in vue-router's poll method, and allow the user to destroy the app that they created in entry-server.js.

A simplified example:

export default context => {
  return new Promise((resolve, reject) => {
    const { app, router } = createApp(context)

    const { url } = context

    router.push(url)

    router.onReady(() => {
      resolve(app)
    }, reject)
  }).then(destroyApp)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions