mirror of https://github.com/sveltejs/svelte
fix: ensure function calls to identifiers are made reactive (#13264)
* fix: ensure function calls to identifiers are made reactive * update test * we have has_local at home * add note * make it a TODO * Update .changeset/red-ladybugs-turn.md --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/13257/head
parent
9864138022
commit
3c97c0a1a1
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: treat pure call expressions as potentially reactive if they reference local bindings
|
@ -1,3 +1,3 @@
|
|||||||
<script module>
|
<script module>
|
||||||
let foo = true;
|
let foo = true;
|
||||||
</script>
|
</script>
|
@ -0,0 +1 @@
|
|||||||
|
export let obj = $state({ a: 1, b: 2 });
|
@ -0,0 +1,11 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [b1] = target.querySelectorAll('button');
|
||||||
|
b1.click();
|
||||||
|
flushSync();
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>Replace</button>\n9,10,11`);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,11 @@
|
|||||||
|
<script>
|
||||||
|
import { obj } from "./Data.svelte.js";
|
||||||
|
|
||||||
|
function replaceProp() {
|
||||||
|
Object.assign(obj, {a:9, b:10, c:11});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={replaceProp}>Replace</button>
|
||||||
|
|
||||||
|
{Object.values(obj)}
|
@ -1,12 +1,7 @@
|
|||||||
import * as $ from "svelte/internal/server";
|
import * as $ from "svelte/internal/server";
|
||||||
|
|
||||||
export default function Purity($$payload) {
|
export default function Purity($$payload) {
|
||||||
let min = 0;
|
$$payload.out += `<p>${$.escape(Math.max(0, Math.min(0, 100)))}</p> <p>${$.escape(location.href)}</p> `;
|
||||||
let max = 100;
|
Child($$payload, { prop: encodeURIComponent('hello') });
|
||||||
let number = 50;
|
|
||||||
let value = 'hello';
|
|
||||||
|
|
||||||
$$payload.out += `<p>${$.escape(Math.max(min, Math.min(max, number)))}</p> <p>${$.escape(location.href)}</p> `;
|
|
||||||
Child($$payload, { prop: encodeURIComponent(value) });
|
|
||||||
$$payload.out += `<!---->`;
|
$$payload.out += `<!---->`;
|
||||||
}
|
}
|
@ -1,12 +1,4 @@
|
|||||||
<script>
|
<p>{Math.max(0, Math.min(0, 100))}</p>
|
||||||
let min = 0;
|
|
||||||
let max = 100;
|
|
||||||
let number = 50;
|
|
||||||
|
|
||||||
let value = 'hello';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<p>{Math.max(min, Math.min(max, number))}</p>
|
|
||||||
<p>{location.href}</p>
|
<p>{location.href}</p>
|
||||||
|
|
||||||
<Child prop={encodeURIComponent(value)} />
|
<Child prop={encodeURIComponent('hello')} />
|
||||||
|
Loading…
Reference in new issue