mirror of https://github.com/sveltejs/svelte
fixes #14532 This removes the `reactive_declaration_non_reactive_property` warning altogether. The first version caused many false positives at compile time. The refined runtime version (introduced in #14192) was hoped to fix this, but it turns out we now get loads of false positives at runtime. The ones I've seen essentially revolve around a signal being created while reading or writing (to) something in a reactive statement, but in a matter which is harmless. For example writing to `$$props` or `$$restProps` (like `$: { if ($$restProps.foo) $$restProps.bar = 'x' }`) creates a new signal under the hood, as the props now temporarily can get out of sync, and we need a backing signal for that. For this we call the `prop` function, which in turn creates several deriveds and may also read from user-land signals that were not read previously - in other words, it's not possible to fix the problem by marking all internal signals (which would be a very very tedious undertaking). The potential benefits of this warning are vastly outnumbered by the false positives it causes, so we should just remove it.pull/14663/head
parent
a2539cfe1f
commit
196c68a16a
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: remove overzealous `reactive_declaration_non_reactive_property` warning
|
||||
@ -1,26 +0,0 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
|
||||
html: '<p>42</p><p>42</p><button>update</button><button>reset</button>',
|
||||
|
||||
test({ assert, target }) {
|
||||
const [update, reset] = target.querySelectorAll('button');
|
||||
flushSync(() => update.click());
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
'<p>42</p><p>42</p><button>update</button><button>reset</button>'
|
||||
);
|
||||
|
||||
flushSync(() => reset.click());
|
||||
},
|
||||
|
||||
warnings: [
|
||||
'A `$:` statement (main.svelte:4:1) read reactive state that was not visible to the compiler. Updates to this state will not cause the statement to re-run. The behaviour of this code will change if you migrate it to runes mode'
|
||||
]
|
||||
});
|
||||
@ -1,11 +0,0 @@
|
||||
export const obj = $state({
|
||||
prop: 42
|
||||
});
|
||||
|
||||
export function update() {
|
||||
obj.prop += 1;
|
||||
}
|
||||
|
||||
export function reset() {
|
||||
obj.prop = 42;
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
<script>
|
||||
import { obj, update, reset } from './data.svelte.js';
|
||||
|
||||
$: a = obj.prop;
|
||||
|
||||
// svelte-ignore reactive_declaration_non_reactive_property
|
||||
$: b = obj.prop;
|
||||
</script>
|
||||
|
||||
<p>{a}</p>
|
||||
<p>{b}</p>
|
||||
<button on:click={update}>update</button>
|
||||
<button on:click={reset}>reset</button>
|
||||
Loading…
Reference in new issue