pull/16197/head
Rich Harris 7 months ago
parent e49f81f409
commit e0e48b392a

@ -41,7 +41,7 @@ import { get_next_sibling } from '../dom/operations.js';
import { async_derived, derived } from './deriveds.js'; import { async_derived, derived } from './deriveds.js';
import { capture } from '../dom/blocks/boundary.js'; import { capture } from '../dom/blocks/boundary.js';
import { component_context, dev_current_component_function } from '../context.js'; import { component_context, dev_current_component_function } from '../context.js';
import { active_fork } from './forks.js'; import { active_fork, Fork } from './forks.js';
/** /**
* @param {'$effect' | '$effect.pre' | '$inspect'} rune * @param {'$effect' | '$effect.pre' | '$inspect'} rune
@ -234,6 +234,7 @@ export function inspect_effect(fn) {
* @returns {() => void} * @returns {() => void}
*/ */
export function effect_root(fn) { export function effect_root(fn) {
Fork.ensure();
const effect = create_effect(ROOT_EFFECT, fn, true); const effect = create_effect(ROOT_EFFECT, fn, true);
return () => { return () => {
@ -247,6 +248,7 @@ export function effect_root(fn) {
* @returns {(options?: { outro?: boolean }) => Promise<void>} * @returns {(options?: { outro?: boolean }) => Promise<void>}
*/ */
export function component_root(fn) { export function component_root(fn) {
Fork.ensure();
const effect = create_effect(ROOT_EFFECT, fn, true); const effect = create_effect(ROOT_EFFECT, fn, true);
return (options = {}) => { return (options = {}) => {

@ -206,8 +206,6 @@ function _mount(Component, { target, anchor, props = {}, events, context, intro
// @ts-expect-error will be defined because the render effect runs synchronously // @ts-expect-error will be defined because the render effect runs synchronously
var component = undefined; var component = undefined;
Fork.ensure();
var unmount = component_root(() => { var unmount = component_root(() => {
var anchor_node = anchor ?? target.appendChild(create_text()); var anchor_node = anchor ?? target.appendChild(create_text());

@ -684,6 +684,11 @@ function infinite_loop_guard() {
function flush_queued_root_effects() { function flush_queued_root_effects() {
var was_updating_effect = is_updating_effect; var was_updating_effect = is_updating_effect;
// TODO it should be impossible to get here without an active fork
if (!active_fork && queued_root_effects.length > 0) {
console.trace('here');
}
try { try {
var flush_count = 0; var flush_count = 0;
is_updating_effect = true; is_updating_effect = true;
@ -901,6 +906,8 @@ function process_effects(root, async_effects, render_effects, effects) {
export function flushSync(fn) { export function flushSync(fn) {
var result; var result;
Fork.ensure();
if (fn) { if (fn) {
is_flushing = true; is_flushing = true;
flush_queued_root_effects(); flush_queued_root_effects();

Loading…
Cancel
Save