forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: beforeUpdate called twice with bound reference
Fixes: sveltejs#6016 Fixes: sveltejs#3290
- Loading branch information
1 parent
883c47b
commit 7891d4b
Showing
5 changed files
with
127 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
test/runtime/samples/lifecycle-render-order-for-children-with-binding/Item.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<script> | ||
import { onMount, beforeUpdate, afterUpdate } from 'svelte'; | ||
import order from './order.js'; | ||
let i; | ||
export let index; | ||
export let id; | ||
export let name; | ||
function logRender () { | ||
order.push(`${index}: render`); | ||
return index; | ||
} | ||
beforeUpdate(() => { | ||
order.push(`${index}: beforeUpdate`); | ||
}); | ||
afterUpdate(() => { | ||
order.push(`${index}: afterUpdate`); | ||
}); | ||
onMount(() => { | ||
order.push(`${index}: onMount`); | ||
}); | ||
</script> | ||
|
||
<li bind:this={i}> | ||
{logRender()} | ||
</li> |
49 changes: 49 additions & 0 deletions
49
test/runtime/samples/lifecycle-render-order-for-children-with-binding/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import order from './order.js'; | ||
|
||
export default { | ||
skip_if_ssr: true, | ||
before_test() { | ||
order.length = 0; | ||
}, | ||
test({ assert, compileOptions }) { | ||
if (compileOptions.hydratable) { | ||
assert.deepEqual(order, [ | ||
'0: beforeUpdate', | ||
'0: render', | ||
'1: beforeUpdate', | ||
'1: render', | ||
'2: beforeUpdate', | ||
'2: render', | ||
'3: beforeUpdate', | ||
'3: render', | ||
'1: onMount', | ||
'1: afterUpdate', | ||
'2: onMount', | ||
'2: afterUpdate', | ||
'3: onMount', | ||
'3: afterUpdate', | ||
'0: onMount', | ||
'0: afterUpdate' | ||
]); | ||
} else { | ||
assert.deepEqual(order, [ | ||
'0: beforeUpdate', | ||
'0: render', | ||
'1: beforeUpdate', | ||
'2: beforeUpdate', | ||
'3: beforeUpdate', | ||
'1: render', | ||
'2: render', | ||
'3: render', | ||
'1: onMount', | ||
'1: afterUpdate', | ||
'2: onMount', | ||
'2: afterUpdate', | ||
'3: onMount', | ||
'3: afterUpdate', | ||
'0: onMount', | ||
'0: afterUpdate' | ||
]); | ||
} | ||
} | ||
}; |
34 changes: 34 additions & 0 deletions
34
test/runtime/samples/lifecycle-render-order-for-children-with-binding/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<script> | ||
import { onMount, beforeUpdate, afterUpdate } from 'svelte'; | ||
import order from './order.js'; | ||
import Item from './Item.svelte'; | ||
const parentIndex = 0; | ||
let ul; | ||
let ulW; | ||
function logRender () { | ||
order.push(`${parentIndex}: render`); | ||
return parentIndex; | ||
} | ||
beforeUpdate(() => { | ||
order.push(`${parentIndex}: beforeUpdate`); | ||
}); | ||
afterUpdate(() => { | ||
order.push(`${parentIndex}: afterUpdate`); | ||
}); | ||
onMount(() => { | ||
order.push(`${parentIndex}: onMount`); | ||
}) | ||
</script> | ||
|
||
{logRender()} | ||
<ul bind:this={ul} bind:clientWidth={ulW}> | ||
{#each [1,2,3] as index} | ||
<Item {index} /> | ||
{/each} | ||
</ul> | ||
|
||
|
1 change: 1 addition & 0 deletions
1
test/runtime/samples/lifecycle-render-order-for-children-with-binding/order.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default []; |