mirror of https://github.com/sveltejs/svelte
fix: ensure await block scope transforms are isolated (#13622)
parent
6a38bbe8a3
commit
ed790ee166
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: ensure await block scope transforms are isolated
|
@ -0,0 +1,36 @@
|
||||
import "svelte/internal/disclose-version";
|
||||
import * as $ from "svelte/internal/client";
|
||||
|
||||
function increment(_, counter) {
|
||||
counter.count += 1;
|
||||
}
|
||||
|
||||
var root = $.template(`<button> </button> <!> `, 1);
|
||||
|
||||
export default function Await_block_scope($$anchor) {
|
||||
let counter = $.proxy({ count: 0 });
|
||||
const promise = $.derived(() => Promise.resolve(counter));
|
||||
var fragment = root();
|
||||
var button = $.first_child(fragment);
|
||||
|
||||
button.__click = [increment, counter];
|
||||
|
||||
var text = $.child(button);
|
||||
|
||||
$.reset(button);
|
||||
|
||||
var node = $.sibling(button, 2);
|
||||
|
||||
$.await(node, () => $.get(promise), null, ($$anchor, counter) => {});
|
||||
|
||||
var text_1 = $.sibling(node);
|
||||
|
||||
$.template_effect(() => {
|
||||
$.set_text(text, `clicks: ${counter.count ?? ""}`);
|
||||
$.set_text(text_1, ` ${counter.count ?? ""}`);
|
||||
});
|
||||
|
||||
$.append($$anchor, fragment);
|
||||
}
|
||||
|
||||
$.delegate(["click"]);
|
@ -0,0 +1,14 @@
|
||||
import * as $ from "svelte/internal/server";
|
||||
|
||||
export default function Await_block_scope($$payload) {
|
||||
let counter = { count: 0 };
|
||||
const promise = Promise.resolve(counter);
|
||||
|
||||
function increment() {
|
||||
counter.count += 1;
|
||||
}
|
||||
|
||||
$$payload.out += `<button>clicks: ${$.escape(counter.count)}</button> <!---->`;
|
||||
$.await(promise, () => {}, (counter) => {}, () => {});
|
||||
$$payload.out += `<!----> ${$.escape(counter.count)}`;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<script>
|
||||
let counter = $state({ count: 0 });
|
||||
const promise = $derived(Promise.resolve(counter))
|
||||
|
||||
function increment() {
|
||||
counter.count += 1;
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={increment}>
|
||||
clicks: {counter.count}
|
||||
</button>
|
||||
|
||||
{#await promise then counter}{/await}
|
||||
|
||||
{counter.count}
|
Loading…
Reference in new issue