fix for dropdown

This commit is contained in:
Nicolas Bayet
2025-09-28 14:57:49 +02:00
parent 4385969e2e
commit 0c1f9f3ffa
2 changed files with 14 additions and 5 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ export { Component } from "./component";
export type { ComponentConstructor } from "./component";
export { useComponent, useState } from "./component_node";
export { status } from "./status";
export { reactive, markRaw, toRaw } from "./reactivity";
export { reactive, markRaw, toRaw, effect } from "./reactivity";
export { useEffect, useEnv, useExternalListener, useRef, useChildSubEnv, useSubEnv } from "./hooks";
export { batched, EventBus, htmlEscape, whenReady, loadFile, markup } from "./utils";
export {
+13 -4
View File
@@ -131,6 +131,11 @@ function processSignals() {
[...scheduledSignals.values()].map((s) => [...s.executionContexts]).flat()
);
// schedule before context.update in case there is write operations during update
// todo: add a test in case there is write operations during update the test
// will break is scheduledSignals.clear(); is called after context.update();
// that writes
scheduledSignals.clear();
for (const ctx of [...scheduledContexts]) {
removeSignalsFromContext(ctx);
// custom unsubscribe depending on the context.
@@ -146,7 +151,6 @@ function processSignals() {
popExecutionContext();
}
}
scheduledSignals.clear();
}
/**
@@ -263,7 +267,11 @@ function unsubscribeChildEffect(
executionContext.meta.children.length = 0;
}
export function effect(fn: Function) {
const parent = getExecutionContext();
let parent = getExecutionContext();
// todo: is it useful?
if (parent && !parent?.meta.children) {
parent = undefined!;
}
const executionContext: ExecutionContext = {
unsubcribe: (scheduledContexts: Set<ExecutionContext>) => {
unsubscribeChildEffect(executionContext, scheduledContexts);
@@ -277,12 +285,13 @@ export function effect(fn: Function) {
},
signals: new Set(),
meta: {
parent: getExecutionContext(),
parent: parent,
children: [],
},
};
if (parent) {
parent.meta.children.push(executionContext);
// todo: is it useful?
parent.meta.children?.push?.(executionContext);
}
pushExecutionContext(executionContext);
try {