-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: run blocks eagerly during flush #16631
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
66396f3
2048f5d
acc7bb3
f89e355
12ceae1
d5ba21f
c9b2654
87e5d00
8e2cc02
5d6b081
e7cc0e0
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 | ||
--- | ||
|
||
perf: run blocks eagerly during flush instead of aborting |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ import * as e from '../errors.js'; | |
import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js'; | ||
import { get_stack, tag_proxy } from '../dev/tracing.js'; | ||
import { component_context, is_runes } from '../context.js'; | ||
import { Batch, schedule_effect } from './batch.js'; | ||
import { Batch, eager_block_effects, schedule_effect } from './batch.js'; | ||
import { proxy } from '../proxy.js'; | ||
import { execute_derived } from './deriveds.js'; | ||
|
||
|
@@ -334,6 +334,12 @@ function mark_reactions(signal, status) { | |
if ((flags & DERIVED) !== 0) { | ||
mark_reactions(/** @type {Derived} */ (reaction), MAYBE_DIRTY); | ||
} else if (not_dirty) { | ||
if ((flags & BLOCK_EFFECT) !== 0) { | ||
if (eager_block_effects !== null) { | ||
eager_block_effects.push(/** @type {Effect} */ (reaction)); | ||
} | ||
} | ||
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. My guess for why this is necessary is that in the next batch that was scheduled due to this we need it for traversal of the graph. |
||
|
||
schedule_effect(/** @type {Effect} */ (reaction)); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script> | ||
let { children } = $props(); | ||
|
||
let inited = $state(false); | ||
|
||
$effect(() => { | ||
inited = true; | ||
}); | ||
</script> | ||
|
||
{#if inited} | ||
<span>{@render children()}</span> | ||
{/if} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { flushSync } from 'svelte'; | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
async test({ assert, target }) { | ||
const [button] = target.querySelectorAll('button'); | ||
|
||
assert.doesNotThrow(() => { | ||
flushSync(() => button.click()); | ||
}); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script> | ||
import Child from './Child.svelte'; | ||
|
||
let show = $state(false); | ||
</script> | ||
|
||
<button onclick={() => show = !show}> | ||
toggle | ||
</button> | ||
|
||
{#if show} | ||
{#each { length: 1234 } as i} | ||
<Child>{i}</Child> | ||
{/each} | ||
{/if} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the correct place since it's equivalent timing to before: previously you would bail the loop and start a new flush. That means you ended up at the end of the
flush_effects
loop where we also callclear()
, and then did another flush.I have some nagging doubts if the logic in general for this is sound but we can tackle that later.