svelte icon indicating copy to clipboard operation
svelte copied to clipboard

{{#await}} blocks with previously-resolved promises should skip to `then`

Open Rich-Harris opened this issue 8 years ago • 5 comments

In a case like this, it would be nice if we could bypass the pending stage:

{{#if foo}}
  {{#await alreadyFulfilled}}
    <p>this will be rendered initially when foo becomes true</p>
  {{then}}
    <p>then this will immediately replace it</p>
  {{catch}}
    <!-- ... -->
  {{/await}}
{{/if}}

I'm too lazy to test this right now but I think that the way promises work, the user won't see any flashing. But it's still wasteful. Perhaps the await block could do something grotesque like this:

promise.then(value => {
  promise.__value = value;
}, error => {
  promise.__error = error;
});

Rich-Harris avatar Dec 05 '17 03:12 Rich-Harris

Made a REPL to test it, you're correct it gets called but you don't see it.

https://svelte.technology/repl?version=1.54.1&gist=4d4b2fa27ea365d94032c0221e14de3f

aubergene avatar Feb 08 '18 12:02 aubergene

This situation feels like it's calling out for a WeakMap to act as a central lookup for already-resolved promises. But I don't know whether it's worth it if we have to implement this two ways, for with and without legacy: true.

Conduitry avatar Apr 17 '19 01:04 Conduitry

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 25 '21 18:12 stale[bot]

I want to give a +1 to this feature

MathiasWP avatar May 23 '23 16:05 MathiasWP

Wow, old issue, but yeah would still be nice. Updated REPL as syntax has changed

https://svelte.dev/repl/5a592e5cbb0d4142ace9787f11bf77e2?version=3.59.1

aubergene avatar May 23 '23 17:05 aubergene

closing in favour of #8459

Rich-Harris avatar Apr 01 '24 23:04 Rich-Harris