fix key block

pull/13292/head
Dominic Gannaway 2 years ago
parent 8213586cd9
commit e409fce8d5

@ -34,15 +34,12 @@ export function if_block(node, get_condition, consequent_fn, alternate_fn = null
/** @type {Effect | null} */
var alternate_effect = null;
/** We use a derived here to ensure stability of any depedencies due to the use of `pause_effect` */
var derived_condition = derived(() => !!get_condition());
var flags = elseif ? EFFECT_TRANSPARENT : 0;
block(() => {
// We use a derived here to ensure stability of any depedencies that are captured when we read `get_condition`.
// This is mainly because the current block effect's dependencies are only applied _after_ the effect has finished
// running, however as we're sync calling `destroy_effect` via `pause_effect` below, it might mean that our
// dependencies get lost. By having a derived already having run, those dependencies won't be affected by this
var condition = get(derived_condition);
/** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */

@ -1,7 +1,9 @@
/** @import { Effect, TemplateNode } from '#client' */
import { UNINITIALIZED } from '../../../../constants.js';
import { derived } from '../../reactivity/deriveds.js';
import { block, branch, pause_effect } from '../../reactivity/effects.js';
import { safe_not_equal } from '../../reactivity/equality.js';
import { get } from '../../runtime.js';
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
/**
@ -24,8 +26,11 @@ export function key_block(node, get_key, render_fn) {
/** @type {Effect} */
var effect;
/** We use a derived here to ensure stability of any depedencies due to the use of `pause_effect` */
var derived_key = derived(get_key);
block(() => {
if (safe_not_equal(key, (key = get_key()))) {
if (safe_not_equal(key, (key = get(derived_key)))) {
if (effect) {
pause_effect(effect);
}

@ -23,6 +23,6 @@ export default test({
button?.dispatchEvent(click);
flushSync();
assert.deepEqual(logs, ['mount', 'unmount', 'mount']);
assert.deepEqual(logs, ['mount', 'unmount']);
}
});

Loading…
Cancel
Save