always bind effects to parents

blockless
Rich Harris 2 years ago
parent 66f2e95feb
commit 75d7ca850c

@ -6,6 +6,7 @@ import {
} from '../../hydration.js';
import { remove } from '../../reconciler.js';
import { pause_effect, render_effect, resume_effect } from '../../reactivity/computations.js';
import { current_effect } from '../../runtime.js';
/**
* @param {Comment} anchor_node

@ -83,9 +83,7 @@ function internal_create_effect(type, fn, sync, block, schedule) {
signal.x = current_component_context;
if (current_effect !== null) {
signal.l = current_effect.l + 1;
if ((type & MANAGED) === 0) {
push_reference(current_effect, signal);
}
push_reference(current_effect, signal);
}
if (schedule) {
schedule_effect(signal, sync);
@ -309,7 +307,7 @@ function pause_children(effect, transitions) {
/**
* @param {import('../types.js').ComputationSignal} effect
*/
function destroy_effect(effect) {
export function destroy_effect(effect) {
// TODO distinguish between 'block effects' (?) which own their own DOM
// and other render effects
if (effect.dom) {

@ -58,7 +58,8 @@ import {
derived,
pre_effect,
user_effect,
pause_effect
pause_effect,
destroy_effect
} from './reactivity/computations.js';
import {
current_hydration_fragment,
@ -2460,7 +2461,6 @@ export function hydrate(component, options) {
function _mount(Component, options) {
const registered_events = new Set();
const container = options.target;
const block = create_root_block(options.intro || false);
run_transitions = options.intro ?? false;
@ -2489,10 +2489,10 @@ function _mount(Component, options) {
pop();
}
},
block,
{},
true
);
block.e = effect;
const bound_event_listener = handle_event_propagation.bind(null, container);
const bound_document_event_listener = handle_event_propagation.bind(null, document);
@ -2530,6 +2530,7 @@ function _mount(Component, options) {
}
}
};
event_handle(array_from(all_registerd_events));
root_event_handles.add(event_handle);
@ -2537,12 +2538,10 @@ function _mount(Component, options) {
for (const event_name of registered_events) {
container.removeEventListener(event_name, bound_event_listener);
}
root_event_handles.delete(event_handle);
const dom = block.d;
if (dom !== null) {
remove(dom);
}
destroy_signal(/** @type {import('./types.js').EffectSignal} */ (block.e));
destroy_effect(effect);
});
return component;

Loading…
Cancel
Save