Skip to content

Make lazy loaded components compatible with Vue Suspense API #2396

@jnoordsij

Description

@jnoordsij

What problem is this solving

Per the current docs:

Vue Router has built-in support for lazily loading components using dynamic imports. These are distinct from async components and currently they will not trigger <Suspense>. However, they can still have async components as descendants and those can trigger <Suspense> in the usual way.

It would be nice to have such components to do work with Suspense, as currently I could find no trivial way to easily track the loading state of lazy component in a manner visible to users. The best solution I've seen around so far involved route guards to alter some global loading state ref, but this feels somewhat complex to me.

Documentation above suggests attempts to achieve compatibility have been made or are at least planned ("and currently they will not"), however I could find no issue tracking progress on this.

Proposed solution

When using a RouterView component within Suspense and (lazy) loading of a route component start, it works in such a manner that the Loading State of the Suspense is triggered.

Describe alternatives you've considered

Use workarounds like #1469 (comment).

Final note

As mentioned, I've created this as the docs seem to suggest this may be possible and/or already considered. If this is considered to be technically infeasible, I suggest to reword the docs to make users aware this will never happen. If there's already some other place tracking progress on this that I haven't found, feel free to close this and lead me that way!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions