Skip to content

Dependency tag #5351

Closed
Closed
@joas8211

Description

@joas8211

I've had problems with loading components asyncronously using dynamic import and SSR on JAM-stack site. Consider a situation where locally stored JSON data dictates what component to load at build-time.

The workaround I've been using thus-far is loading all the components on build-time on module context and only needed components on client-side using render-blocking if-block. But that is ugly and might cause a race condition (although only on rare cases) since the component loading on build-time isn't awaited.

What I would like to have is way to block build-time rendering (SSR) for the time of loading dynamically imported components.

I tried to implement some kind of beforeMount lifetime hook, but it doesn't seem possible with the compiled code and template being tied together. Then I tried implementing top-level await for the script block but Acorn JavaScript parser started complaining just by thought of that.

Potential feature that could solve it could be svelte:dependency tag. It could function as an await after script execution and before template rendering.

<svelte:dependency await={promise} />

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