OpenAPI: fix effect cleanup

This commit is contained in:
Fuma Nama
2026-02-10 22:43:07 +08:00
parent 3e8efb05b1
commit 7872e27faa
4 changed files with 19 additions and 11 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'fumadocs-openapi': patch
'@fumari/stf': patch
---
fix change detector
+4 -3
View File
@@ -229,9 +229,10 @@ export default function PlaygroundClient({
});
useEffect(() => {
return () => {
stf.dataEngine.reset(defaultValues);
};
// same object reference = unchanged
if (stf.dataEngine.getData() === defaultValues) return;
stf.dataEngine.reset(defaultValues);
// eslint-disable-next-line react-hooks/exhaustive-deps -- ignore other parts
}, [defaultValues]);
@@ -47,7 +47,7 @@ export function UsageTabsProvider({
() => ({
example,
route,
setExample: (newKey: string) => {
setExample(newKey: string) {
const example = examples.find((example) => example.id === newKey);
if (!example) return;
+8 -7
View File
@@ -36,12 +36,12 @@ interface OnUpdateContext {
}
class ListenerManager {
private readonly listeners = new Set<DataEngineListener>();
private readonly unindexed = new Set<DataEngineListener>();
private readonly indexed = new Map<string, Set<DataEngineListener>>();
add(listener: DataEngineListener) {
if (!listener.field) {
this.listeners.add(listener);
this.unindexed.add(listener);
return;
}
const key = stringifyFieldKey(listener.field);
@@ -52,14 +52,14 @@ class ListenerManager {
remove(listener: DataEngineListener) {
if (!listener.field) {
this.listeners.delete(listener);
this.unindexed.delete(listener);
} else {
this.indexed.get(stringifyFieldKey(listener.field))?.delete(listener);
}
}
onUpdate(field: FieldKey, ctx: OnUpdateContext) {
for (const v of this.listeners) v.onUpdate?.(field, ctx);
for (const v of this.unindexed) v.onUpdate?.(field, ctx);
const updatedKey = stringifyFieldKey(field);
if (ctx.swallow) {
@@ -67,20 +67,21 @@ class ListenerManager {
if (set) for (const v of set) v.onUpdate?.(field, ctx);
} else {
for (const [k, listeners] of this.indexed.entries()) {
if (k !== updatedKey && !k.startsWith(updatedKey + '.')) continue;
if (updatedKey.length !== 0 && k !== updatedKey && !k.startsWith(updatedKey + '.'))
continue;
for (const v of listeners) v.onUpdate?.(field, ctx);
}
}
}
onInit(field: FieldKey) {
for (const v of this.listeners) v.onInit?.(field);
for (const v of this.unindexed) v.onInit?.(field);
const set = this.indexed.get(stringifyFieldKey(field));
if (set) for (const v of set) v.onInit?.(field);
}
onDelete(field: FieldKey) {
for (const v of this.listeners) v.onDelete?.(field);
for (const v of this.unindexed) v.onDelete?.(field);
const set = this.indexed.get(stringifyFieldKey(field));
if (set) for (const v of set) v.onDelete?.(field);
}