-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure await block scope transforms are isolated (#13622)
- Loading branch information
Showing
8 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: ensure await block scope transforms are isolated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
<div title="preserve"></div> | ||
<input type="text" /> | ||
<hr /> | ||
<f:table></f:table> | ||
<f:table></f:table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ | |
child | ||
</Output_1> | ||
<Output_1></Output_1> | ||
{/if} | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ | |
child | ||
</Output> | ||
<Output></Output> | ||
{/if} | ||
{/if} |
36 changes: 36 additions & 0 deletions
36
packages/svelte/tests/snapshot/samples/await-block-scope/_expected/client/index.svelte.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"]); |
14 changes: 14 additions & 0 deletions
14
packages/svelte/tests/snapshot/samples/await-block-scope/_expected/server/index.svelte.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)}`; | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/svelte/tests/snapshot/samples/await-block-scope/index.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |