fix: invalidate `@const` tags based on visible references in legacy mode (#18041)

closes #17992
pull/18043/head
Rich Harris 3 months ago committed by GitHub
parent ff3495dc05
commit edcbb0e640
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: invalidate `@const` tags based on visible references in legacy mode

@ -10,7 +10,7 @@ export function visit_function(node, context) {
for (const [name] of context.state.scope.references) {
const binding = context.state.scope.get(name);
if (binding && binding.scope.function_depth < context.state.scope.function_depth) {
if (binding && binding.scope !== context.state.scope) {
context.state.expression.references.add(binding);
}
}

@ -0,0 +1,34 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
html: `
<input>
<p>hello</p>
<p>hello</p>
`,
ssrHtml: `
<input value="hello">
<p>hello</p>
<p>hello</p>
`,
async test({ assert, target }) {
const [input] = target.querySelectorAll('input');
flushSync(() => {
input.value = 'goodbye';
input.dispatchEvent(new InputEvent('input', { bubbles: true }));
});
assert.htmlEqual(
target.innerHTML,
`
<input>
<p>goodbye</p>
<p>goodbye</p>
`
);
}
});

@ -0,0 +1,15 @@
<svelte:options runes={false} />
<script>
let message = 'hello';
</script>
<input bind:value={message} />
{#if true}
{@const m1 = message}
{@const m2 = (() => m1)()}
<p>{m1}</p>
<p>{m2}</p>
{/if}
Loading…
Cancel
Save