@decocms/tanstack 7.86.5 → 7.86.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/tanstack",
|
|
3
|
-
"version": "7.86.
|
|
3
|
+
"version": "7.86.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deco framework binding for TanStack Start + Cloudflare Workers",
|
|
6
6
|
"repository": {
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"lint:unused": "knip"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@decocms/blocks": "7.86.
|
|
30
|
-
"@decocms/blocks-admin": "7.86.
|
|
31
|
-
"@decocms/blocks-cli": "7.86.
|
|
29
|
+
"@decocms/blocks": "7.86.6",
|
|
30
|
+
"@decocms/blocks-admin": "7.86.6",
|
|
31
|
+
"@decocms/blocks-cli": "7.86.6"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@tanstack/react-query": ">=5.0.0",
|
|
@@ -108,6 +108,31 @@ describe("withSiteGlobals", () => {
|
|
|
108
108
|
expect(mockedResolvePageSections).toHaveBeenCalledTimes(1);
|
|
109
109
|
});
|
|
110
110
|
|
|
111
|
+
it("a joiner does not hang when the owner request was cancelled", async () => {
|
|
112
|
+
// Workers cancels the owner request's I/O and timers when its client
|
|
113
|
+
// disconnects: the shared flight never settles. The joiner must give up
|
|
114
|
+
// on it after its own timer and resolve on its own.
|
|
115
|
+
vi.useFakeTimers();
|
|
116
|
+
try {
|
|
117
|
+
mockedLoadBlocks.mockReturnValue({
|
|
118
|
+
site: { global: [{ __resolveType: "Analytics" }] },
|
|
119
|
+
});
|
|
120
|
+
mockedResolvePageSections
|
|
121
|
+
.mockImplementationOnce(() => new Promise(() => {}))
|
|
122
|
+
.mockResolvedValue([{ component: "A.tsx", props: {}, key: "k0" }]);
|
|
123
|
+
|
|
124
|
+
void resolveSiteGlobals();
|
|
125
|
+
const joiner = resolveSiteGlobals();
|
|
126
|
+
await vi.advanceTimersByTimeAsync(10_000);
|
|
127
|
+
const r = await joiner;
|
|
128
|
+
|
|
129
|
+
expect(r.resolvedSections).toEqual([{ component: "A.tsx", props: {}, key: "k0" }]);
|
|
130
|
+
expect(mockedResolvePageSections).toHaveBeenCalledTimes(2);
|
|
131
|
+
} finally {
|
|
132
|
+
vi.useRealTimers();
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
111
136
|
it("caches across calls within TTL", async () => {
|
|
112
137
|
mockedLoadBlocks.mockReturnValue({
|
|
113
138
|
site: { global: [{ __resolveType: "Analytics" }] },
|
|
@@ -130,10 +155,7 @@ describe("withSiteGlobals", () => {
|
|
|
130
155
|
const ctx = { path: "/farm-etc" } as any;
|
|
131
156
|
await resolveSiteGlobals(ctx);
|
|
132
157
|
|
|
133
|
-
expect(mockedResolvePageSections).toHaveBeenCalledWith(
|
|
134
|
-
[{ __resolveType: "Alert" }],
|
|
135
|
-
ctx,
|
|
136
|
-
);
|
|
158
|
+
expect(mockedResolvePageSections).toHaveBeenCalledWith([{ __resolveType: "Alert" }], ctx);
|
|
137
159
|
});
|
|
138
160
|
|
|
139
161
|
it("caches per path — different routes don't share a matched variant", async () => {
|
|
@@ -208,12 +230,7 @@ describe("withSiteGlobals", () => {
|
|
|
208
230
|
|
|
209
231
|
describe("dedupeGlobals", () => {
|
|
210
232
|
it("returns empty when globals is empty", () => {
|
|
211
|
-
expect(
|
|
212
|
-
dedupeGlobals(
|
|
213
|
-
[],
|
|
214
|
-
[{ component: "Header.tsx", props: {}, key: "p0" }],
|
|
215
|
-
),
|
|
216
|
-
).toEqual([]);
|
|
233
|
+
expect(dedupeGlobals([], [{ component: "Header.tsx", props: {}, key: "p0" }])).toEqual([]);
|
|
217
234
|
});
|
|
218
235
|
|
|
219
236
|
it("drops globals whose component already appears in existing", () => {
|
|
@@ -221,9 +238,7 @@ describe("withSiteGlobals", () => {
|
|
|
221
238
|
{ component: "Theme.tsx", props: {}, key: "g0" },
|
|
222
239
|
{ component: "Session.tsx", props: {}, key: "g1" },
|
|
223
240
|
];
|
|
224
|
-
const existing = [
|
|
225
|
-
{ component: "Session.tsx", props: { fromPage: true }, key: "p0" },
|
|
226
|
-
];
|
|
241
|
+
const existing = [{ component: "Session.tsx", props: { fromPage: true }, key: "p0" }];
|
|
227
242
|
|
|
228
243
|
const result = dedupeGlobals(globals, existing);
|
|
229
244
|
// Session dropped (already on page); Theme kept.
|
|
@@ -27,7 +27,12 @@
|
|
|
27
27
|
|
|
28
28
|
import type { MatcherContext, ResolvedSection } from "@decocms/blocks/cms";
|
|
29
29
|
import { loadBlocks, onChange, resolvePageSections } from "@decocms/blocks/cms";
|
|
30
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
cacheBackground,
|
|
32
|
+
createCacheStore,
|
|
33
|
+
getCacheStorageContext,
|
|
34
|
+
} from "@decocms/blocks/sdk/cacheStorage";
|
|
35
|
+
import { joinInflight } from "@decocms/blocks/sdk/inflightTimeout";
|
|
31
36
|
|
|
32
37
|
// ---------------------------------------------------------------------------
|
|
33
38
|
// Types
|
|
@@ -133,7 +138,19 @@ export async function resolveSiteGlobals(matcherCtx?: MatcherContext): Promise<{
|
|
|
133
138
|
: cache.get(cacheKey);
|
|
134
139
|
if (cached && cached.expiresAt > now) return cached;
|
|
135
140
|
const inflightEntry = inflight.get(cacheKey);
|
|
136
|
-
if (inflightEntry)
|
|
141
|
+
if (inflightEntry) {
|
|
142
|
+
// Bounded by THIS request's timer: if the owner request was cancelled, its
|
|
143
|
+
// I/O and timers died with it and the slot never settles (see joinInflight).
|
|
144
|
+
return joinInflight(
|
|
145
|
+
inflightEntry,
|
|
146
|
+
() => {
|
|
147
|
+
if (inflight.get(cacheKey) === inflightEntry) inflight.delete(cacheKey);
|
|
148
|
+
return resolveSiteGlobals(matcherCtx);
|
|
149
|
+
},
|
|
150
|
+
undefined,
|
|
151
|
+
`siteGlobals ${cacheKey}`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
137
154
|
|
|
138
155
|
const site = readSiteBlock();
|
|
139
156
|
if (!site) {
|
|
@@ -152,7 +169,9 @@ export async function resolveSiteGlobals(matcherCtx?: MatcherContext): Promise<{
|
|
|
152
169
|
return empty;
|
|
153
170
|
}
|
|
154
171
|
|
|
155
|
-
|
|
172
|
+
// Cleanup lives in an outer `.finally` (always async) so it can compare by
|
|
173
|
+
// identity: a stale owner must not evict a newer flight a joiner published.
|
|
174
|
+
const p: Promise<CacheEntry> = (async () => {
|
|
156
175
|
try {
|
|
157
176
|
const resolvedSections = await resolvePageSections(rawRefs, matcherCtx);
|
|
158
177
|
const entry: CacheEntry = {
|
|
@@ -166,11 +185,13 @@ export async function resolveSiteGlobals(matcherCtx?: MatcherContext): Promise<{
|
|
|
166
185
|
console.error("[site-globals] failed to resolve:", err);
|
|
167
186
|
// Don't cache failures — let the next request retry.
|
|
168
187
|
return { resolvedSections: [], rawRefs, expiresAt: 0 };
|
|
169
|
-
} finally {
|
|
170
|
-
inflight.delete(cacheKey);
|
|
171
188
|
}
|
|
172
|
-
})()
|
|
189
|
+
})().finally(() => {
|
|
190
|
+
if (inflight.get(cacheKey) === p) inflight.delete(cacheKey);
|
|
191
|
+
});
|
|
173
192
|
|
|
193
|
+
// Keep the shared work alive past its owner request so joiners get it.
|
|
194
|
+
cacheBackground(p);
|
|
174
195
|
inflight.set(cacheKey, p);
|
|
175
196
|
return p;
|
|
176
197
|
}
|