Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await once #955

Open
Rich-Harris opened this issue Nov 25, 2017 · 4 comments
Open

await once #955

Rich-Harris opened this issue Nov 25, 2017 · 4 comments

Comments

@Rich-Harris
Copy link
Member

Follow-up to #952 / #654 (comment). It would modify the behaviour of await blocks such that you'd only see the 'pending' state once — thereafter, whenever a new promise value was set, the old one would be preserved until the promise resolved. An additional argument would be passed to the then block, allowing the UI to indicate that the currently displayed data was out of date:

<!-- autocomplete suggestion list — we don't want to blow away
     the previous set of suggestions while we're waiting for
     the server to send us some new ones -->
{{#await once suggestions}}
  <span>loading...</span>
{{then value, pending}}
  <datalist id='suggestions' style='opacity: {{pending ? 0.5 : 1}}'>
    {{#each value as suggestion}}
      <option>{{suggestion}}</option>
    {{/each}}
  </datalist>

  {{#if pending}}
    <span>updating...</span>
  {{/if}}
{{catch err}}
  <span class='error'>could not get suggestions!</span>
{{/await}}
@stale
Copy link

stale bot commented Dec 25, 2021

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 stale bot added the stale-bot label Dec 25, 2021
@fvarano
Copy link

fvarano commented Jun 9, 2022

For anyone stumbling on this you can use a custom component instead of an await block, something like this REPL
while we wait for updates, but in my opinion this should be the default behavior.

The await syntax makes writing reactive asynchronous UI really pleasant, but makes components flicker every time a variable they depend on has changed, forcing unwanted DOM changes and re-render cycles.

@vladshcherbin
Copy link

Much needed in svelte-kit with streaming data 🤞

@Rich-Harris
Copy link
Member Author

Related: #8459

@Rich-Harris Rich-Harris added this to the 5.x milestone Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants