pull/15844/head
Rich Harris 2 months ago
parent ab48be1046
commit f4055960c5

@ -1,17 +1,12 @@
/** @import { ComponentContext, DevStackEntry } from '#client' */ /** @import { ComponentContext, DevStackEntry, Effect } from '#client' */
import { DEV } from 'esm-env'; import { DEV } from 'esm-env';
import { lifecycle_outside_component } from '../shared/errors.js'; import { lifecycle_outside_component } from '../shared/errors.js';
import * as e from './errors.js'; import * as e from './errors.js';
import { import { active_effect, active_reaction } from './runtime.js';
active_effect, import { create_user_effect } from './reactivity/effects.js';
active_reaction,
set_active_effect,
set_active_reaction
} from './runtime.js';
import { create_user_effect, teardown } from './reactivity/effects.js';
import { async_mode_flag, legacy_mode_flag } from '../flags/index.js'; import { async_mode_flag, legacy_mode_flag } from '../flags/index.js';
import { FILENAME } from '../../constants.js'; import { FILENAME } from '../../constants.js';
import { BRANCH_EFFECT, EFFECT_RAN } from './constants.js';
/** @type {ComponentContext | null} */ /** @type {ComponentContext | null} */
export let component_context = null; export let component_context = null;
@ -105,7 +100,10 @@ export function setContext(key, context) {
const context_map = get_or_init_context_map('setContext'); const context_map = get_or_init_context_map('setContext');
if (async_mode_flag) { if (async_mode_flag) {
if (/** @type {ComponentContext} */ (component_context).m) { var flags = /** @type {Effect} */ (active_effect).f;
var valid = !active_reaction && (flags & BRANCH_EFFECT) !== 0 && (flags & EFFECT_RAN) === 0;
if (!valid) {
e.set_context_after_init(); e.set_context_after_init();
} }
} }
@ -150,7 +148,6 @@ export function push(props, runes = false, fn) {
p: component_context, p: component_context,
c: null, c: null,
e: null, e: null,
m: false,
s: props, s: props,
x: null, x: null,
l: legacy_mode_flag && !runes ? { s: null, u: null, $: [] } : null l: legacy_mode_flag && !runes ? { s: null, u: null, $: [] } : null
@ -184,8 +181,6 @@ export function pop(component) {
context.x = component; context.x = component;
} }
context.m = true;
component_context = context.p; component_context = context.p;
if (DEV) { if (DEV) {

@ -16,8 +16,6 @@ export type ComponentContext = {
c: null | Map<unknown, unknown>; c: null | Map<unknown, unknown>;
/** deferred effects */ /** deferred effects */
e: null | Array<() => void | (() => void)>; e: null | Array<() => void | (() => void)>;
/** mounted */
m: boolean;
/** /**
* props needed for legacy mode lifecycle functions, and for `createEventDispatcher` * props needed for legacy mode lifecycle functions, and for `createEventDispatcher`
* @deprecated remove in 6.0 * @deprecated remove in 6.0

Loading…
Cancel
Save