-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix: address runtime effect issues #9417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1e81913
e264f61
6b7501b
c2edadf
5843a55
358b5ea
8ea82ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: tighten up signals implementation |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
html: `<button>10</button>`, | ||
ssrHtml: `<button>0</button>`, | ||
|
||
async test({ assert, target }) { | ||
flushSync(); | ||
|
||
assert.htmlEqual(target.innerHTML, `<button>10</button>`); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script> | ||
class Counter { | ||
count = $state(0); | ||
|
||
constructor() { | ||
$effect(() => { | ||
this.count = 10; | ||
}); | ||
} | ||
} | ||
const counter = new Counter(); | ||
</script> | ||
|
||
<button on:click={() => counter.count++}>{counter.count}</button> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
html: `<button>10</button>`, | ||
ssrHtml: `<button>0</button>`, | ||
|
||
async test({ assert, target }) { | ||
flushSync(); | ||
|
||
assert.htmlEqual(target.innerHTML, `<button>10</button>`); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<script> | ||
class Counter { | ||
#count = $state(0); | ||
|
||
constructor() { | ||
$effect(() => { | ||
this.#count = 10; | ||
}); | ||
} | ||
|
||
getCount() { | ||
return this.#count; | ||
} | ||
|
||
increment() { | ||
this.#count++; | ||
} | ||
} | ||
const counter = new Counter(); | ||
</script> | ||
|
||
<button on:click={() => counter.increment()}>{counter.getCount()}</button> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { test } from '../../test'; | ||
import { flushSync } from 'svelte'; | ||
|
||
export default test({ | ||
get props() { | ||
return { log: [] }; | ||
}, | ||
|
||
async test({ assert, target, component }) { | ||
const [b1] = target.querySelectorAll('button'); | ||
flushSync(() => { | ||
b1.click(); | ||
}); | ||
flushSync(() => { | ||
b1.click(); | ||
}); | ||
assert.deepEqual(component.log, ['init 0', 'cleanup 2', 'init 2', 'cleanup 4', 'init 4']); | ||
gtm-nayan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script> | ||
const {log} = $props(); | ||
|
||
let count = $state(0); | ||
|
||
$effect(() => { | ||
let double = $derived(count * 2) | ||
|
||
log.push('init ' + double); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test can move into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It matches the other tests inside the directory that checks logging order? It seems related to Svelte runtime too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which other tests are you talking about? Maybe those other tests need to move into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried, but I now get test failures accessing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what test failures about accessing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test suite setup is different I guess? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I've done some digging and ultimately I don't think these are signals tests and they shouldn't be coupled with being so. Signal tests should be agnostic of Svelte's components. However, these cases come from bug reports where users have created components that demonstrate ordering issues or timing issues that are relevant to their components. This is important as the signals tests also demonstrate unowned signals – which mean they are independent of components too, not to mention how this all fits into equality. Let's merge this PR and create a separate issue on how we can unify the semantics around signals - vs - component state semantics, as I think there needs to be a distinction and having one is important. For example, our current signals tests are all wrapped with a render effect, which is likely wrong too. They shouldn't be, signals should be agnostic of effects. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea of wrapping them is to simulate this being run inside a component context, which is why I was so confused why it wouldn't work when having them in that test suite |
||
|
||
return () => { | ||
log.push('cleanup ' + double); | ||
}; | ||
}) | ||
</script> | ||
|
||
<button on:click={() => count++ }>Click</button> |
Uh oh!
There was an error while loading. Please reload this page.