mirror of https://github.com/sveltejs/svelte
feat: async fragments (#16542)
* init * fix * fix * maybe this works? * fix, minor cleanup * maybe this'll fix hydration issues? * apparently not, maybe this'll do it * add test, changeset * minor tweak * tabs * avoid timeouts in tests, they add up quickly * tweak * fix * some is more 'correct' than find * chore: remove `b.async` * simplify * apply suggestion from review Co-authored-by: Rich Harris <rich.harris@vercel.com> * Update .changeset/brave-baboons-teach.md --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/16560/head
parent
41a20aa975
commit
193f23fa05
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: allow `await` inside `@const` declarations
|
@ -0,0 +1,10 @@
|
|||||||
|
/** @import { AST } from '#compiler' */
|
||||||
|
/** @import { Context } from '../types.js' */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {AST.Fragment} node
|
||||||
|
* @param {Context} context
|
||||||
|
*/
|
||||||
|
export function Fragment(node, context) {
|
||||||
|
context.next({ ...context.state, fragment: node });
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `<h1>Loading...</h1>`,
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, `<h1>Hello, world!</h1>`);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,16 @@
|
|||||||
|
<script>
|
||||||
|
let name = $state('world');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
{#snippet pending()}
|
||||||
|
<h1>Loading...</h1>
|
||||||
|
{/snippet}
|
||||||
|
|
||||||
|
{#snippet greet()}
|
||||||
|
{@const greeting = await `Hello, ${name}!`}
|
||||||
|
<h1>{greeting}</h1>
|
||||||
|
{/snippet}
|
||||||
|
|
||||||
|
{@render greet()}
|
||||||
|
</svelte:boundary>
|
Loading…
Reference in new issue