Skip to content

New rule proposal prefer-boundaries #1431

@T1xx1

Description

@T1xx1

Motivation

With async Svelte and remote functions, there are 2 ways to handle async values: await blocks and boundaries with pending/failed snippets.

In this video https://youtu.be/z0f7NLPdLYE?t=329 from Svelte society, boundaries are recommended over await blocks.

Await blocks are also not great when you need to await for 2 or more async values.

Description

prefer-boundaries which errors with await blocks

Examples

<!-- ✓ GOOD -->
<svelte:boundary>
    {@const asyncValue = await asyncValue()}
    ...

    {#snippet pending()}
        ...
    {/snippet}
    {#snippet failed()}
        ...
    {/snippet}
</svelte:boundary>

<!-- ✗ BAD -->
{#await asyncValue()}
    ...
{:then asyncValue}
    ...
{:catch error}
    ...
{/await}

<!-- Things can get really bad with nested awaits -->
<!-- ✓ GOOD -->
<svelte:boundary>
    {@const asyncValue = await asyncValue()}
    {@const asyncValue2 = await asyncValue2()}
    ...

    {#snippet pending()}
        ...
    {/snippet}
    {#snippet failed()}
        ...
    {/snippet}
</svelte:boundary>

<!-- ✗ BAD -->
{#await asyncValue()}
    {#await asyncValue()}
        ...
    {:then asyncValue}
        ...
    {:catch error}
        ...
    {/await}
{:then asyncValue}
    ...
{:catch error}
    ...
{/await}

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions