always bind effects to parents

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

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

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

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

Loading…
Cancel
Save