feat: implement new feature for enhanced user experience

This commit is contained in:
2026-05-17 14:19:45 +00:00
parent db968ab318
commit f332c707b7
214 changed files with 424 additions and 2562 deletions
+44
View File
@@ -88,6 +88,50 @@ function ssrRequest(cacheKey, endpoint, query, options) {
// @ts-ignore
context.ssrDeps[collectionName + ":*"] = true
}
// --- EXTENSION: Track dependencies from lookup and aggregate ---
// Both `lookup` and `aggregate` parameters can inject data from other collections.
// We must invalidate the SSR cache if any of those referenced collections change.
if (options && options.lookup) {
const lookups = typeof options.lookup === "string" ? options.lookup.split(",") : [];
for (const l of lookups) {
// format: "fieldPath:collectionName"
const parts = l.split(":");
if (parts.length > 1) {
const targetCollection = parts[parts.length - 1];
// @ts-ignore
context.ssrDeps[targetCollection + ":*"] = true;
}
}
}
if (options && options.params && options.params.aggregate) {
const aggregates = typeof options.params.aggregate === "string"
? options.params.aggregate.split(",")
: [];
for (const a of aggregates) {
// simple format: "collectionName:foreignField:..."
// json format: '{"collection":"comments",...}'
try {
if (a.startsWith("{")) {
const parsed = JSON.parse(a);
if (parsed && parsed.collection) {
// @ts-ignore
context.ssrDeps[parsed.collection + ":*"] = true;
}
} else {
const parts = a.split(":");
if (parts.length > 0) {
const targetCollection = parts[0];
// @ts-ignore
context.ssrDeps[targetCollection + ":*"] = true;
}
}
} catch (e) {
// silently ignore parse errors here
}
}
}
// --- END EXTENSION ---
}
// @ts-ignore