8000 fix: stable attachments by Rich-Harris · Pull Request #15961 · sveltejs/svelte · GitHub
[go: up one dir, main page]

Skip to content

fix: stable attachments #15961

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

Merged
merged 17 commits into from
May 28, 2025
Prev Previous commit
Next Next commit
merge main, add a test
  • Loading branch information
Rich-Harris committed May 24, 2025
commit d5d9593940898f6b99e3783bf89e7434b4eea809
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { block, branch, effect, destroy_effect } from '../../reactivity/effects.
* @param {() => (node: Element) => void} get_fn
*/
export function attach(node, get_fn) {
return effect(() => {
const fn = get_fn();
/** @type {false | undefined | ((node: Element) => void)} */
var fn = undefined;

/** @type {Effect | null} */
var e;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
let props = $props();
</script>

<p {...props}>hello</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
test({ assert, target, logs }) {
assert.deepEqual(logs, ['up']);

const button = target.querySelector('button');

flushSync(() => button?.click());
assert.deepEqual(logs, ['up']);

flushSync(() => button?.click());
assert.deepEqual(logs, ['up', 'down']);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script>
import Component from './Component.svelte';

let count = $state(0);
</script>

<button onclick={() => count++}>{count}</button>

{#if count < 2}
<Component
data-count={count}
{@attach () => {
console.log('up');
return () => console.log('down');
}}
/>
{/if}
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.
0