mirror of https://github.com/sveltejs/svelte
fix: don't preserve reactivity context across function boundaries (#17002)
Fixes #16809 We gotta take into account function boundaries when determining whether or not we're inside a derived (or const).pull/16960/merge
parent
f549478dd0
commit
a57868ebce
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: don't preserve reactivity context across function boundaries
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({ compileOptions: { experimental: { async: true } } });
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
import 'svelte/internal/disclose-version';
|
||||||
|
import 'svelte/internal/flags/async';
|
||||||
|
import * as $ from 'svelte/internal/client';
|
||||||
|
|
||||||
|
export default function Async_in_derived($$anchor, $$props) {
|
||||||
|
$.push($$props, true);
|
||||||
|
|
||||||
|
$.async_body($$anchor, async ($$anchor) => {
|
||||||
|
let yes1 = (await $.save($.async_derived(async () => (await $.save(1))())))();
|
||||||
|
let yes2 = (await $.save($.async_derived(async () => foo((await $.save(1))()))))();
|
||||||
|
|
||||||
|
let no1 = $.derived(async () => {
|
||||||
|
return await 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
let no2 = $.derived(() => async () => {
|
||||||
|
return await 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($.aborted()) return;
|
||||||
|
|
||||||
|
var fragment = $.comment();
|
||||||
|
var node = $.first_child(fragment);
|
||||||
|
|
||||||
|
{
|
||||||
|
var consequent = ($$anchor) => {
|
||||||
|
$.async_body($$anchor, async ($$anchor) => {
|
||||||
|
const yes1 = (await $.save($.async_derived(async () => (await $.save(1))())))();
|
||||||
|
const yes2 = (await $.save($.async_derived(async () => foo((await $.save(1))()))))();
|
||||||
|
|
||||||
|
const no1 = $.derived(() => (async () => {
|
||||||
|
return await 1;
|
||||||
|
})());
|
||||||
|
|
||||||
|
const no2 = $.derived(() => (async () => {
|
||||||
|
return await 1;
|
||||||
|
})());
|
||||||
|
|
||||||
|
if ($.aborted()) return;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$.if(node, ($$render) => {
|
||||||
|
if (true) $$render(consequent);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$.append($$anchor, fragment);
|
||||||
|
});
|
||||||
|
|
||||||
|
$.pop();
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
import 'svelte/internal/flags/async';
|
||||||
|
import * as $ from 'svelte/internal/server';
|
||||||
|
|
||||||
|
export default function Async_in_derived($$renderer, $$props) {
|
||||||
|
$$renderer.component(($$renderer) => {
|
||||||
|
$$renderer.async(async ($$renderer) => {
|
||||||
|
let yes1 = (await $.save(1))();
|
||||||
|
let yes2 = foo((await $.save(1))());
|
||||||
|
|
||||||
|
let no1 = (async () => {
|
||||||
|
return await 1;
|
||||||
|
})();
|
||||||
|
|
||||||
|
let no2 = async () => {
|
||||||
|
return await 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
$$renderer.async(async ($$renderer) => {
|
||||||
|
if (true) {
|
||||||
|
$$renderer.push('<!--[-->');
|
||||||
|
|
||||||
|
const yes1 = (await $.save(1))();
|
||||||
|
const yes2 = foo((await $.save(1))());
|
||||||
|
|
||||||
|
const no1 = (async () => {
|
||||||
|
return await 1;
|
||||||
|
})();
|
||||||
|
|
||||||
|
const no2 = (async () => {
|
||||||
|
return await 1;
|
||||||
|
})();
|
||||||
|
} else {
|
||||||
|
$$renderer.push('<!--[!-->');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$$renderer.push(`<!--]-->`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
<script>
|
||||||
|
let yes1 = $derived(await 1);
|
||||||
|
let yes2 = $derived(foo(await 1));
|
||||||
|
let no1 = $derived.by(async () => {
|
||||||
|
return await 1;
|
||||||
|
});
|
||||||
|
let no2 = $derived(async () => {
|
||||||
|
return await 1;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if true}
|
||||||
|
{@const yes1 = await 1}
|
||||||
|
{@const yes2 = foo(await 1)}
|
||||||
|
{@const no1 = (async () => {
|
||||||
|
return await 1;
|
||||||
|
})()}
|
||||||
|
{@const no2 = (async () => {
|
||||||
|
return await 1;
|
||||||
|
})()}
|
||||||
|
{/if}
|
||||||
Loading…
Reference in new issue