mirror of https://github.com/sveltejs/svelte
fix: hoist reactive imports to the module (#12845)
* fix: hoist reactive imports to the module * fix * Update .changeset/eleven-teachers-drive.md * beef up test * unused --------- Co-authored-by: Rich Harris <rich.harris@vercel.com> Co-authored-by: Rich Harris <hello@rich-harris.dev>pull/12862/head
parent
45da5a426f
commit
03945f56b4
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: treat module-level imports as non-reactive in legacy mode
|
@ -0,0 +1,17 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
import state from './state.js';
|
||||
|
||||
export default test({
|
||||
html: '<button>0</button>',
|
||||
|
||||
before_test() {
|
||||
state.count = 0;
|
||||
},
|
||||
|
||||
test({ assert, target }) {
|
||||
const button = target.querySelector('button');
|
||||
flushSync(() => button?.click());
|
||||
assert.htmlEqual(target.innerHTML, '<button>0</button>');
|
||||
}
|
||||
});
|
@ -0,0 +1,9 @@
|
||||
<script context="module">
|
||||
import state from './state.js';
|
||||
|
||||
function update() {
|
||||
state.count += 1;
|
||||
}
|
||||
</script>
|
||||
|
||||
<button on:click={update}>{state.count}</button>
|
@ -0,0 +1,3 @@
|
||||
export default {
|
||||
count: 0
|
||||
};
|
Loading…
Reference in new issue