fix: reuse `batch_values`

forked-derived-values
paoloricciuti 5 hours ago
parent fea81ad68a
commit 5f05884483

@ -68,14 +68,6 @@ export let previous_batch = null;
*/
export let batch_values = null;
/**
* When time travelling (i.e. working in one batch, while other batches
* still have ongoing work), we ignore the real values of affected
* signals in favour of their values within the batch
* @type {Map<Value, any> | null}
*/
export let forked_derived_values = null;
// TODO this should really be a property of `batch`
/** @type {Effect[]} */
let queued_root_effects = [];
@ -966,15 +958,14 @@ export function fork(fn) {
var batch = Batch.ensure();
batch.is_fork = true;
batch_values = new Map();
var committed = false;
var settled = batch.settled();
forked_derived_values = new Map();
flushSync(fn);
forked_derived_values = null;
batch_values = null;
// revert state changes
for (var [source, value] of batch.previous) {

@ -34,7 +34,7 @@ import { async_mode_flag, tracing_mode_flag } from '../../flags/index.js';
import { Boundary } from '../dom/blocks/boundary.js';
import { component_context } from '../context.js';
import { UNINITIALIZED } from '../../../constants.js';
import { batch_values, current_batch, forked_derived_values } from './batch.js';
import { batch_values, current_batch } from './batch.js';
import { unset_context } from './async.js';
import { deferred } from '../../shared/utils.js';
@ -360,10 +360,8 @@ export function update_derived(derived) {
// the underlying value will be updated when the fork is committed.
// otherwise, the next time we get here after a 'real world' state
// change, `derived.equals` may incorrectly return `true`
if (!forked_derived_values) {
if (!current_batch?.is_fork) {
derived.v = value;
} else {
forked_derived_values.set(derived, value);
}
derived.wv = increment_write_version();
@ -380,7 +378,7 @@ export function update_derived(derived) {
if (batch_values !== null) {
// only cache the value if we're in a tracking context, otherwise we won't
// clear the cache in `mark_reactions` when dependencies are updated
if (effect_tracking()) {
if (effect_tracking() || current_batch?.is_fork) {
batch_values.set(derived, value);
}
} else {

@ -43,13 +43,7 @@ import {
set_dev_stack
} from './context.js';
import * as w from './warnings.js';
import {
Batch,
batch_values,
flushSync,
forked_derived_values,
schedule_effect
} from './reactivity/batch.js';
import { Batch, batch_values, flushSync, schedule_effect } from './reactivity/batch.js';
import { handle_error } from './error-handling.js';
import { UNINITIALIZED } from '../../constants.js';
import { captured_signals } from './legacy.js';
@ -627,10 +621,6 @@ export function get(signal) {
if (is_updating_effect && effect_tracking() && (derived.f & CONNECTED) === 0) {
reconnect(derived);
}
if (forked_derived_values?.has(derived)) {
return forked_derived_values.get(derived);
}
}
if (batch_values?.has(signal)) {

Loading…
Cancel
Save