Skip to content

Async, tick, boundary and failed #16569

@fmorency

Description

@fmorency

Describe the bug

I'm playing with the new async feature. The page reloads the data by calling invalidateAll() every 1 second. I noticed the tick stops after the first error.

I tried moving error and reset outside the boundary without luck.

I'm not sure if this is a real issue or a misunderstanding on my end. Please be gentle.

Reproduction

First attempt - The page will stop reloading on the first error

<script lang="ts">
function getPromise() {
  return new Promise((resolve, reject) => {
    if (Math.random() < 0.5) {
      resolve(Math.random());
    } else {
      reject(new Error("Error occurred"));
    }
  });
}

let data = $state(getPromise());

let tick = $state(Date.now());
$effect(() => {
	const x = setInterval(() => {
		tick = Date.now();
	}, 1000);
	return () => clearInterval(x);
})

$effect(() => {
	if (tick) {
		data = getPromise();
  }
});

</script>

<main>
  <svelte:boundary>
    <p>{JSON.stringify((await data), null, 2)}</p>

    {#snippet pending()}
      <p>loading...</p>
    {/snippet}

    {#snippet failed(error, reset)}
      <p>error...</p>
    {/snippet}
  </svelte:boundary>
</main>

Second attempt - Move error and reset outside of boundary

<script lang="ts">
  function getPromise() {
    return new Promise((resolve, reject) => {
      if (Math.random() < 0.5) {
        resolve(Math.random());
      } else {
        reject(new Error("Error occurred"));
      }
    });
  }

  let data = $state(getPromise());
  let error = $state(null);
  let reset = $state(() => {});

  function failed(e, r) {
    error = e;
    reset = r;
    console.log("Error occurred:", e);
  }

  let tick = $state(Date.now());
  $effect(() => {
    const x = setInterval(() => {
      tick = Date.now();
    }, 1000);
    return () => clearInterval(x);
  })

  $effect(() => {
    if (tick) {
      if (error) {
        console.log("Resetting due to error");
        error = null;
        reset();
      } else {
        data = getPromise();
      }
    }
  });
</script>

<main>
  <svelte:boundary {failed}>
    <p>{JSON.stringify((await data), null, 2)}</p>

    {#snippet pending()}
      <p>loading...</p>
    {/snippet}

  </svelte:boundary>
</main>

Logs

System Info

System:
    OS: Linux 6.15 Manjaro Linux
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 15.74 GB / 39.02 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.17.0 - ~/.nvm/versions/node/v22.17.0/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.17.0/bin/npm
    pnpm: 10.13.
  System:
    OS: Linux 6.15 Manjaro Linux
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 15.74 GB / 39.02 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.17.0 - ~/.nvm/versions/node/v22.17.0/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.17.0/bin/npm
    pnpm: 10.13.1 - /usr/bin/pnpm
    bun: 1.2.19 - /usr/bin/bun
  Browsers:
    Chromium: 138.0.7204.183
  npmPackages:
    svelte: 5.37.3 => 5.37.3 1 - /usr/bin/pnpm
    bun: 1.2.19 - /usr/bin/bun
  Browsers:
    Chromium: 138.0.7204.183
  npmPackages:
    svelte: 5.37.3 => 5.37.3

Severity

annoyance

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