Skip to content

Commit 5f05884

Browse files
committed
fix: reuse batch_values
1 parent fea81ad commit 5f05884

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ export let previous_batch = null;
6868
*/
6969
export let batch_values = null;
7070

71-
/**
72-
* When time travelling (i.e. working in one batch, while other batches
73-
* still have ongoing work), we ignore the real values of affected
74-
* signals in favour of their values within the batch
75-
* @type {Map<Value, any> | null}
76-
*/
77-
export let forked_derived_values = null;
78-
7971
// TODO this should really be a property of `batch`
8072
/** @type {Effect[]} */
8173
let queued_root_effects = [];
@@ -966,15 +958,14 @@ export function fork(fn) {
966958

967959
var batch = Batch.ensure();
968960
batch.is_fork = true;
961+
batch_values = new Map();
969962

970963
var committed = false;
971964
var settled = batch.settled();
972965

973-
forked_derived_values = new Map();
974-
975966
flushSync(fn);
976967

977-
forked_derived_values = null;
968+
batch_values = null;
978969

979970
// revert state changes
980971
for (var [source, value] of batch.previous) {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { async_mode_flag, tracing_mode_flag } from '../../flags/index.js';
3434
import { Boundary } from '../dom/blocks/boundary.js';
3535
import { component_context } from '../context.js';
3636
import { UNINITIALIZED } from '../../../constants.js';
37-
import { batch_values, current_batch, forked_derived_values } from './batch.js';
37+
import { batch_values, current_batch } from './batch.js';
3838
import { unset_context } from './async.js';
3939
import { deferred } from '../../shared/utils.js';
4040

@@ -360,10 +360,8 @@ export function update_derived(derived) {
360360
// the underlying value will be updated when the fork is committed.
361361
// otherwise, the next time we get here after a 'real world' state
362362
// change, `derived.equals` may incorrectly return `true`
363-
if (!forked_derived_values) {
363+
if (!current_batch?.is_fork) {
364364
derived.v = value;
365-
} else {
366-
forked_derived_values.set(derived, value);
367365
}
368366

369367
derived.wv = increment_write_version();
@@ -380,7 +378,7 @@ export function update_derived(derived) {
380378
if (batch_values !== null) {
381379
// only cache the value if we're in a tracking context, otherwise we won't
382380
// clear the cache in `mark_reactions` when dependencies are updated
383-
if (effect_tracking()) {
381+
if (effect_tracking() || current_batch?.is_fork) {
384382
batch_values.set(derived, value);
385383
}
386384
} else {

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ import {
4343
set_dev_stack
4444
} from './context.js';
4545
import * as w from './warnings.js';
46-
import {
47-
Batch,
48-
batch_values,
49-
flushSync,
50-
forked_derived_values,
51-
schedule_effect
52-
} from './reactivity/batch.js';
46+
import { Batch, batch_values, flushSync, schedule_effect } from './reactivity/batch.js';
5347
import { handle_error } from './error-handling.js';
5448
import { UNINITIALIZED } from '../../constants.js';
5549
import { captured_signals } from './legacy.js';
@@ -627,10 +621,6 @@ export function get(signal) {
627621
if (is_updating_effect && effect_tracking() && (derived.f & CONNECTED) === 0) {
628622
reconnect(derived);
629623
}
630-
631-
if (forked_derived_values?.has(derived)) {
632-
return forked_derived_values.get(derived);
633-
}
634624
}
635625

636626
if (batch_values?.has(signal)) {

0 commit comments

Comments
 (0)