Skip to content

Commit 9d7d045

Browse files
committed
create separate effect type for async deriveds, as they are not blocks
1 parent ef28490 commit 9d7d045

File tree

6 files changed

+16
-10
lines changed

6 files changed

+16
-10
lines changed

packages/svelte/src/internal/client/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const EFFECT_PRESERVED = 1 << 21; // effects with this flag should not be
2323

2424
// Flags used for async
2525
export const REACTION_IS_UPDATING = 1 << 22;
26+
export const EFFECT_ASYNC = 1 << 23;
2627

2728
export const STATE_SYMBOL = Symbol('$state');
2829
export const STATE_SYMBOL_METADATA = Symbol('$state metadata');

packages/svelte/src/internal/client/dev/debug.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
CLEAN,
88
DERIVED,
99
EFFECT,
10+
EFFECT_ASYNC,
1011
MAYBE_DIRTY,
1112
RENDER_EFFECT,
1213
ROOT_EFFECT
@@ -39,6 +40,8 @@ export function log_effect_tree(effect) {
3940
label = 'boundary';
4041
} else if ((flags & BLOCK_EFFECT) !== 0) {
4142
label = 'block';
43+
} else if ((flags & EFFECT_ASYNC) !== 0) {
44+
label = 'async';
4245
} else if ((flags & BRANCH_EFFECT) !== 0) {
4346
label = 'branch';
4447
} else if ((flags & RENDER_EFFECT) !== 0) {

packages/svelte/src/internal/client/reactivity/deriveds.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
DERIVED,
66
DESTROYED,
77
DIRTY,
8+
EFFECT_ASYNC,
89
EFFECT_PRESERVED,
910
MAYBE_DIRTY,
1011
UNOWNED
@@ -22,7 +23,7 @@ import {
2223
import { equals, safe_equals } from './equality.js';
2324
import * as e from '../errors.js';
2425
import * as w from '../warnings.js';
25-
import { block, destroy_effect } from './effects.js';
26+
import { block, destroy_effect, render_effect } from './effects.js';
2627
import { inspect_effects, internal_set, set_inspect_effects, source } from './sources.js';
2728
import { get_stack } from '../dev/tracing.js';
2829
import { tracing_mode_flag } from '../../flags/index.js';
@@ -107,8 +108,7 @@ export function async_derived(fn, location) {
107108
/** @type {(() => void) | null} */
108109
var unsuspend = null;
109110

110-
// TODO this isn't a block
111-
block(() => {
111+
render_effect(() => {
112112
if (DEV) from_async_derived = active_effect;
113113
var current = (promise = fn());
114114
if (DEV) from_async_derived = null;
@@ -151,7 +151,7 @@ export function async_derived(fn, location) {
151151
}
152152
}
153153
);
154-
}, EFFECT_PRESERVED);
154+
}, EFFECT_ASYNC | EFFECT_PRESERVED);
155155

156156
return new Promise(async (fulfil) => {
157157
// if the effect re-runs before the initial promise

packages/svelte/src/internal/client/reactivity/effects.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ export function legacy_pre_effect_reset() {
335335
* @param {() => void | (() => void)} fn
336336
* @returns {Effect}
337337
*/
338-
export function render_effect(fn) {
339-
return create_effect(RENDER_EFFECT, fn, true);
338+
export function render_effect(fn, flags = 0) {
339+
return create_effect(RENDER_EFFECT | flags, fn, true);
340340
}
341341

342342
/**

packages/svelte/src/internal/client/reactivity/sources.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {
2828
UNOWNED,
2929
MAYBE_DIRTY,
3030
BLOCK_EFFECT,
31-
ROOT_EFFECT
31+
ROOT_EFFECT,
32+
EFFECT_ASYNC
3233
} from '../constants.js';
3334
import * as e from '../errors.js';
3435
import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js';
@@ -150,7 +151,7 @@ export function set(source, value) {
150151
active_reaction !== null &&
151152
!untracking &&
152153
is_runes() &&
153-
(active_reaction.f & (DERIVED | BLOCK_EFFECT)) !== 0 &&
154+
(active_reaction.f & (DERIVED | BLOCK_EFFECT | EFFECT_ASYNC)) !== 0 &&
154155
// If the source was created locally within the current derived, then
155156
// we allow the mutation.
156157
(derived_sources === null || !derived_sources.includes(source))

packages/svelte/src/internal/client/runtime.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import {
2424
LEGACY_DERIVED_PROP,
2525
DISCONNECTED,
2626
BOUNDARY_EFFECT,
27-
REACTION_IS_UPDATING
27+
REACTION_IS_UPDATING,
28+
EFFECT_ASYNC
2829
} from './constants.js';
2930
import {
3031
flush_idle_tasks,
@@ -820,7 +821,7 @@ function process_effects(effect, effects = [], boundary) {
820821
var sibling = current_effect.next;
821822

822823
if (!is_skippable_branch && (flags & INERT) === 0) {
823-
if (boundary !== undefined && (flags & (BLOCK_EFFECT | BRANCH_EFFECT)) === 0) {
824+
if (boundary !== undefined && (flags & (BLOCK_EFFECT | BRANCH_EFFECT | EFFECT_ASYNC)) === 0) {
824825
// Inside a boundary, defer everything except block/branch effects
825826
boundary.add_effect(current_effect);
826827
} else if ((flags & BOUNDARY_EFFECT) !== 0) {

0 commit comments

Comments
 (0)