@decocms/tanstack 7.7.0 → 7.8.0
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.
|
|
3
|
+
"version": "7.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deco framework binding for TanStack Start + Cloudflare Workers",
|
|
6
6
|
"repository": {
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"./vite": "./src/vite/plugin.js",
|
|
15
15
|
"./daemon": "./src/daemon/index.ts",
|
|
16
16
|
"./sdk/createInvoke": "./src/sdk/createInvoke.ts",
|
|
17
|
-
"./sdk/cookiePassthrough": "./src/sdk/cookiePassthrough.ts"
|
|
17
|
+
"./sdk/cookiePassthrough": "./src/sdk/cookiePassthrough.ts",
|
|
18
|
+
"./sdk/deferredSectionLoader": "./src/sdk/deferredSectionLoader.ts"
|
|
18
19
|
},
|
|
19
20
|
"scripts": {
|
|
20
21
|
"build": "tsc",
|
|
@@ -23,9 +24,9 @@
|
|
|
23
24
|
"lint:unused": "knip"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@decocms/blocks": "7.
|
|
27
|
-
"@decocms/blocks-admin": "7.
|
|
28
|
-
"@decocms/blocks-cli": "7.
|
|
27
|
+
"@decocms/blocks": "7.8.0",
|
|
28
|
+
"@decocms/blocks-admin": "7.8.0",
|
|
29
|
+
"@decocms/blocks-cli": "7.8.0",
|
|
29
30
|
"@deco-cx/warp-node": "^0.3.16",
|
|
30
31
|
"fast-json-patch": "^3.1.0",
|
|
31
32
|
"ws": "^8.18.0"
|
package/src/routes/cmsRoute.ts
CHANGED
|
@@ -340,35 +340,6 @@ export const loadDeferredSection = createServerFn({ method: "POST" })
|
|
|
340
340
|
return normalizeUrlsInObject(enriched);
|
|
341
341
|
});
|
|
342
342
|
|
|
343
|
-
// ---------------------------------------------------------------------------
|
|
344
|
-
// Pre-wrapped deferred section loader for IntersectionObserver-based rendering
|
|
345
|
-
// ---------------------------------------------------------------------------
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Convenience wrapper around `loadDeferredSection` that matches the
|
|
349
|
-
* `loadDeferredSectionFn` prop signature of `DecoPageRenderer`.
|
|
350
|
-
*
|
|
351
|
-
* Pass this directly to `<DecoPageRenderer loadDeferredSectionFn={deferredSectionLoader} />`
|
|
352
|
-
* to enable IntersectionObserver-based lazy loading of deferred sections.
|
|
353
|
-
*/
|
|
354
|
-
export const deferredSectionLoader = async ({
|
|
355
|
-
component,
|
|
356
|
-
rawProps,
|
|
357
|
-
pagePath,
|
|
358
|
-
pageUrl,
|
|
359
|
-
index,
|
|
360
|
-
}: {
|
|
361
|
-
component: string;
|
|
362
|
-
rawProps?: Record<string, unknown>;
|
|
363
|
-
pagePath: string;
|
|
364
|
-
pageUrl?: string;
|
|
365
|
-
index?: number;
|
|
366
|
-
}): Promise<ResolvedSection | null> => {
|
|
367
|
-
return loadDeferredSection({
|
|
368
|
-
data: { component, rawProps, pagePath, pageUrl, index },
|
|
369
|
-
});
|
|
370
|
-
};
|
|
371
|
-
|
|
372
343
|
// ---------------------------------------------------------------------------
|
|
373
344
|
// Default pending component — shown during SPA navigation while loader runs
|
|
374
345
|
// ---------------------------------------------------------------------------
|
package/src/routes/index.ts
CHANGED
|
@@ -10,12 +10,12 @@ export {
|
|
|
10
10
|
type CmsRouteOptions,
|
|
11
11
|
cmsHomeRouteConfig,
|
|
12
12
|
cmsRouteConfig,
|
|
13
|
-
deferredSectionLoader,
|
|
14
13
|
loadCmsHomePage,
|
|
15
14
|
loadCmsPage,
|
|
16
15
|
loadDeferredSection,
|
|
17
16
|
setSectionChunkMap,
|
|
18
17
|
} from "./cmsRoute";
|
|
18
|
+
export { deferredSectionLoader } from "../sdk/deferredSectionLoader";
|
|
19
19
|
export { CmsPage, NotFoundPage } from "./components";
|
|
20
20
|
export {
|
|
21
21
|
resolveSiteGlobals,
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract test for the public `deferredSectionLoader` wrapper
|
|
3
|
+
* (`@decocms/tanstack/sdk/deferredSectionLoader`).
|
|
4
|
+
*
|
|
5
|
+
* Before 7.7 this wrapper was unreachable from any public subpath, so
|
|
6
|
+
* migrated sites (lebiscuit, miess, granadobr, casaevideo) each carried a
|
|
7
|
+
* byte-identical local shim wrapping the public `loadDeferredSection`
|
|
8
|
+
* export. The cases below are derived from how those sites call it: it is
|
|
9
|
+
* passed verbatim as `<DecoPageRenderer loadDeferredSectionFn={...} />`,
|
|
10
|
+
* so it must (a) accept the renderer's flat argument object, (b) wrap it
|
|
11
|
+
* into the server function's `{ data }` envelope, and (c) pass the result
|
|
12
|
+
* (section or null) straight through.
|
|
13
|
+
*/
|
|
14
|
+
import type { ComponentProps } from "react";
|
|
15
|
+
import { beforeEach, describe, expect, expectTypeOf, it, vi } from "vitest";
|
|
16
|
+
|
|
17
|
+
vi.mock("../routes/cmsRoute", () => ({
|
|
18
|
+
loadDeferredSection: vi.fn(),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
import type { DecoPageRenderer } from "../hooks/DecoPageRenderer";
|
|
22
|
+
import { loadDeferredSection } from "../routes/cmsRoute";
|
|
23
|
+
import { deferredSectionLoader } from "./deferredSectionLoader";
|
|
24
|
+
|
|
25
|
+
const mockedLoad = loadDeferredSection as unknown as ReturnType<typeof vi.fn>;
|
|
26
|
+
|
|
27
|
+
describe("deferredSectionLoader", () => {
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
mockedLoad.mockReset();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("wraps the flat argument object into the server function's { data } envelope", async () => {
|
|
33
|
+
const section = { component: "site/sections/Newsletter.tsx", props: {} };
|
|
34
|
+
mockedLoad.mockResolvedValue(section);
|
|
35
|
+
|
|
36
|
+
const result = await deferredSectionLoader({
|
|
37
|
+
component: "site/sections/Newsletter.tsx",
|
|
38
|
+
rawProps: { title: "Hi" },
|
|
39
|
+
pagePath: "/",
|
|
40
|
+
pageUrl: "https://example.com/?utm=x",
|
|
41
|
+
index: 4,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(mockedLoad).toHaveBeenCalledTimes(1);
|
|
45
|
+
expect(mockedLoad).toHaveBeenCalledWith({
|
|
46
|
+
data: {
|
|
47
|
+
component: "site/sections/Newsletter.tsx",
|
|
48
|
+
rawProps: { title: "Hi" },
|
|
49
|
+
pagePath: "/",
|
|
50
|
+
pageUrl: "https://example.com/?utm=x",
|
|
51
|
+
index: 4,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
expect(result).toBe(section);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("accepts the minimal call shape (component + pagePath only)", async () => {
|
|
58
|
+
mockedLoad.mockResolvedValue(null);
|
|
59
|
+
|
|
60
|
+
await deferredSectionLoader({
|
|
61
|
+
component: "site/sections/Footer.tsx",
|
|
62
|
+
pagePath: "/collections/sale",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(mockedLoad).toHaveBeenCalledWith({
|
|
66
|
+
data: {
|
|
67
|
+
component: "site/sections/Footer.tsx",
|
|
68
|
+
rawProps: undefined,
|
|
69
|
+
pagePath: "/collections/sale",
|
|
70
|
+
pageUrl: undefined,
|
|
71
|
+
index: undefined,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("passes a null resolution (cache miss / unresolvable section) straight through", async () => {
|
|
77
|
+
mockedLoad.mockResolvedValue(null);
|
|
78
|
+
|
|
79
|
+
const result = await deferredSectionLoader({
|
|
80
|
+
component: "site/sections/Missing.tsx",
|
|
81
|
+
pagePath: "/",
|
|
82
|
+
index: 0,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
expect(result).toBeNull();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("matches DecoPageRenderer's loadDeferredSectionFn prop signature", () => {
|
|
89
|
+
// The whole point of the export: sites pass it verbatim as
|
|
90
|
+
// `<DecoPageRenderer loadDeferredSectionFn={deferredSectionLoader} />`.
|
|
91
|
+
type LoadFn = NonNullable<ComponentProps<typeof DecoPageRenderer>["loadDeferredSectionFn"]>;
|
|
92
|
+
expectTypeOf(deferredSectionLoader).toExtend<LoadFn>();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-wrapped deferred section loader for IntersectionObserver-based
|
|
3
|
+
* rendering.
|
|
4
|
+
*
|
|
5
|
+
* Convenience wrapper around `loadDeferredSection` (the POST server
|
|
6
|
+
* function defined in `../routes/cmsRoute.ts`) that matches the
|
|
7
|
+
* `loadDeferredSectionFn` prop signature of `DecoPageRenderer`.
|
|
8
|
+
*
|
|
9
|
+
* Pass this directly to
|
|
10
|
+
* `<DecoPageRenderer loadDeferredSectionFn={deferredSectionLoader} />`
|
|
11
|
+
* to enable IntersectionObserver-based lazy loading of deferred sections.
|
|
12
|
+
*
|
|
13
|
+
* Publicly exported at `@decocms/tanstack/sdk/deferredSectionLoader`.
|
|
14
|
+
* Before 7.7 this wrapper existed only inside the package (exported from
|
|
15
|
+
* the internal `./routes` barrel but reachable from no public subpath), so
|
|
16
|
+
* migrated sites each carried a byte-identical local shim re-implementing
|
|
17
|
+
* it against the public `loadDeferredSection` export. Those shims can be
|
|
18
|
+
* deleted in favor of this subpath.
|
|
19
|
+
*
|
|
20
|
+
* @example Site's `src/routes/$.tsx`:
|
|
21
|
+
* ```tsx
|
|
22
|
+
* import { deferredSectionLoader } from "@decocms/tanstack/sdk/deferredSectionLoader";
|
|
23
|
+
*
|
|
24
|
+
* <DecoPageRenderer loadDeferredSectionFn={deferredSectionLoader} />
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import type { ResolvedSection } from "@decocms/blocks/cms";
|
|
28
|
+
import { loadDeferredSection } from "../routes/cmsRoute";
|
|
29
|
+
|
|
30
|
+
export const deferredSectionLoader = async ({
|
|
31
|
+
component,
|
|
32
|
+
rawProps,
|
|
33
|
+
pagePath,
|
|
34
|
+
pageUrl,
|
|
35
|
+
index,
|
|
36
|
+
}: {
|
|
37
|
+
component: string;
|
|
38
|
+
rawProps?: Record<string, unknown>;
|
|
39
|
+
pagePath: string;
|
|
40
|
+
pageUrl?: string;
|
|
41
|
+
index?: number;
|
|
42
|
+
}): Promise<ResolvedSection | null> => {
|
|
43
|
+
return loadDeferredSection({
|
|
44
|
+
data: { component, rawProps, pagePath, pageUrl, index },
|
|
45
|
+
});
|
|
46
|
+
};
|