@decocms/tanstack 8.1.0-next.0 → 8.5.1
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/README.md +79 -0
- package/dist/draft.d.ts +33 -0
- package/dist/draft.d.ts.map +1 -0
- package/dist/draft.js +41 -0
- package/dist/draft.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/react/DecoDocument.d.ts +61 -0
- package/dist/react/DecoDocument.d.ts.map +1 -0
- package/dist/react/DecoDocument.js +96 -0
- package/dist/react/DecoDocument.js.map +1 -0
- package/dist/react/Image.d.ts +96 -0
- package/dist/react/Image.d.ts.map +1 -0
- package/dist/react/Image.js +79 -0
- package/dist/react/Image.js.map +1 -0
- package/dist/react/index.d.ts +7 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +7 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/pageValues.d.ts +10 -0
- package/dist/react/pageValues.d.ts.map +1 -0
- package/dist/react/pageValues.js +29 -0
- package/dist/react/pageValues.js.map +1 -0
- package/dist/react/scripts.d.ts +14 -0
- package/dist/react/scripts.d.ts.map +1 -0
- package/dist/react/scripts.js +96 -0
- package/dist/react/scripts.js.map +1 -0
- package/dist/router/index.d.ts +38 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +60 -0
- package/dist/router/index.js.map +1 -0
- package/dist/scope/browser.d.ts +11 -0
- package/dist/scope/browser.d.ts.map +1 -0
- package/dist/scope/browser.js +8 -0
- package/dist/scope/browser.js.map +1 -0
- package/dist/scope/server.d.ts +13 -0
- package/dist/scope/server.d.ts.map +1 -0
- package/dist/scope/server.js +26 -0
- package/dist/scope/server.js.map +1 -0
- package/dist/server/index.d.ts +27 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +31 -0
- package/dist/server/index.js.map +1 -0
- package/dist/shared.d.ts +26 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +26 -0
- package/dist/shared.js.map +1 -0
- package/dist/start/index.d.ts +9 -0
- package/dist/start/index.d.ts.map +1 -0
- package/dist/start/index.js +33 -0
- package/dist/start/index.js.map +1 -0
- package/dist/studio.d.ts +28 -0
- package/dist/studio.d.ts.map +1 -0
- package/dist/studio.js +53 -0
- package/dist/studio.js.map +1 -0
- package/dist/vite/index.d.ts +15 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +95 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/worker/cacheProfiles.d.ts +43 -0
- package/dist/worker/cacheProfiles.d.ts.map +1 -0
- package/dist/worker/cacheProfiles.js +162 -0
- package/dist/worker/cacheProfiles.js.map +1 -0
- package/dist/worker/cookies.d.ts +20 -0
- package/dist/worker/cookies.d.ts.map +1 -0
- package/dist/worker/cookies.js +69 -0
- package/dist/worker/cookies.js.map +1 -0
- package/dist/worker/drafts.d.ts +59 -0
- package/dist/worker/drafts.d.ts.map +1 -0
- package/dist/worker/drafts.js +140 -0
- package/dist/worker/drafts.js.map +1 -0
- package/dist/worker/index.d.ts +111 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +618 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/security.d.ts +14 -0
- package/dist/worker/security.d.ts.map +1 -0
- package/dist/worker/security.js +48 -0
- package/dist/worker/security.js.map +1 -0
- package/dist/worker/segment.d.ts +21 -0
- package/dist/worker/segment.d.ts.map +1 -0
- package/dist/worker/segment.js +43 -0
- package/dist/worker/segment.js.map +1 -0
- package/package.json +85 -37
- package/src/draft.ts +43 -0
- package/src/index.ts +8 -61
- package/src/react/DecoDocument.tsx +234 -0
- package/src/react/Image.tsx +213 -0
- package/src/react/index.ts +24 -0
- package/src/react/pageValues.ts +35 -0
- package/src/react/scripts.ts +98 -0
- package/src/router/index.ts +80 -0
- package/src/scope/browser.ts +18 -0
- package/src/scope/server.ts +37 -0
- package/src/server/index.ts +43 -0
- package/src/shared.ts +29 -0
- package/src/start/index.ts +31 -0
- package/src/studio.ts +52 -0
- package/src/vite/index.ts +105 -0
- package/src/worker/cacheProfiles.ts +180 -0
- package/src/worker/cookies.ts +65 -0
- package/src/worker/drafts.ts +157 -0
- package/src/worker/index.ts +784 -0
- package/src/worker/security.ts +63 -0
- package/src/worker/segment.ts +49 -0
- package/src/__conformance__/observability.test.ts +0 -221
- package/src/cms/kvBlockSource.test.ts +0 -82
- package/src/cms/kvBlockSource.ts +0 -68
- package/src/daemon/auth.ts +0 -204
- package/src/daemon/fs.ts +0 -238
- package/src/daemon/index.ts +0 -8
- package/src/daemon/middleware.ts +0 -156
- package/src/daemon/tunnel.ts +0 -129
- package/src/daemon/volumes.ts +0 -366
- package/src/daemon/watch.ts +0 -272
- package/src/hooks/CdnSegmentMarker.tsx +0 -38
- package/src/hooks/DecoPageRenderer.tsx +0 -750
- package/src/hooks/DecoRootLayout.tsx +0 -192
- package/src/hooks/DraftPreviewIndicator.test.tsx +0 -60
- package/src/hooks/DraftPreviewIndicator.tsx +0 -64
- package/src/hooks/NavigationProgress.test.tsx +0 -58
- package/src/hooks/NavigationProgress.tsx +0 -63
- package/src/hooks/PreviewProviders.test.tsx +0 -42
- package/src/hooks/PreviewProviders.tsx +0 -45
- package/src/hooks/StableOutlet.tsx +0 -30
- package/src/hooks/deferredObserverTiming.test.tsx +0 -91
- package/src/hooks/index.ts +0 -10
- package/src/routes/adminRoutes.test.ts +0 -99
- package/src/routes/adminRoutes.ts +0 -153
- package/src/routes/cmsRoute.test.ts +0 -267
- package/src/routes/cmsRoute.ts +0 -1053
- package/src/routes/components.tsx +0 -57
- package/src/routes/index.ts +0 -24
- package/src/routes/pageUrl.test.ts +0 -70
- package/src/routes/pageUrl.ts +0 -55
- package/src/routes/withSiteGlobals.test.ts +0 -243
- package/src/routes/withSiteGlobals.ts +0 -243
- package/src/sdk/backgroundTasks.test.ts +0 -68
- package/src/sdk/backgroundTasks.ts +0 -38
- package/src/sdk/cdnSegment.test.ts +0 -67
- package/src/sdk/cdnSegment.ts +0 -71
- package/src/sdk/cookiePassthrough.ts +0 -58
- package/src/sdk/createInvoke.ts +0 -77
- package/src/sdk/deferredSectionLoader.test.ts +0 -94
- package/src/sdk/deferredSectionLoader.ts +0 -46
- package/src/sdk/draft.test.ts +0 -341
- package/src/sdk/draft.ts +0 -277
- package/src/sdk/draftShared.ts +0 -16
- package/src/sdk/kvHydration.test.ts +0 -371
- package/src/sdk/kvHydration.ts +0 -263
- package/src/sdk/kvRedirects.test.ts +0 -132
- package/src/sdk/kvRedirects.ts +0 -125
- package/src/sdk/outboundHeaders.test.ts +0 -113
- package/src/sdk/outboundHeaders.ts +0 -81
- package/src/sdk/router.ts +0 -101
- package/src/sdk/serverFnFetch.ts +0 -59
- package/src/sdk/speculationRules.test.ts +0 -82
- package/src/sdk/speculationRules.ts +0 -136
- package/src/sdk/startEntry.ts +0 -31
- package/src/sdk/useHydrated.ts +0 -19
- package/src/sdk/workerEntry.cacheStorage.test.ts +0 -147
- package/src/sdk/workerEntry.test.ts +0 -1033
- package/src/sdk/workerEntry.trackingCache.test.ts +0 -328
- package/src/sdk/workerEntry.ts +0 -3154
- package/src/setupFastDeploy.ts +0 -13
- package/src/v8/__conformance__/delivery.test.ts +0 -100
- package/src/v8/binding.ts +0 -70
- package/src/v8/kvLoader.bundle.test.ts +0 -42
- package/src/v8/kvLoader.test.ts +0 -74
- package/src/v8/kvLoader.ts +0 -43
- package/src/vite/plugin-scaffold-gen.test.js +0 -106
- package/src/vite/plugin.js +0 -1022
- package/src/vite/plugin.test.js +0 -238
- package/src/vite/plugin.test.ts +0 -176
- package/tsconfig.json +0 -7
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Link } from "@tanstack/react-router";
|
|
2
|
-
import type { DeferredSection, ResolvedSection } from "@decocms/blocks/cms";
|
|
3
|
-
import { DecoPageRenderer } from "../hooks/DecoPageRenderer";
|
|
4
|
-
import type { Device } from "@decocms/blocks/sdk/useDevice";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Default CMS page component. Renders all resolved sections.
|
|
8
|
-
* Sites can use this directly or build their own.
|
|
9
|
-
*/
|
|
10
|
-
export function CmsPage({
|
|
11
|
-
sections,
|
|
12
|
-
deferredSections,
|
|
13
|
-
deferredPromises,
|
|
14
|
-
pagePath,
|
|
15
|
-
pageUrl,
|
|
16
|
-
device,
|
|
17
|
-
}: {
|
|
18
|
-
sections: ResolvedSection[];
|
|
19
|
-
deferredSections?: DeferredSection[];
|
|
20
|
-
deferredPromises?: Record<string, Promise<ResolvedSection | null>>;
|
|
21
|
-
pagePath?: string;
|
|
22
|
-
pageUrl?: string;
|
|
23
|
-
/** Server-resolved device from the page loader — keeps useDevice() hydration-stable. */
|
|
24
|
-
device?: Device;
|
|
25
|
-
}) {
|
|
26
|
-
return (
|
|
27
|
-
<div>
|
|
28
|
-
<DecoPageRenderer
|
|
29
|
-
sections={sections}
|
|
30
|
-
deferredSections={deferredSections}
|
|
31
|
-
deferredPromises={deferredPromises}
|
|
32
|
-
pagePath={pagePath}
|
|
33
|
-
pageUrl={pageUrl}
|
|
34
|
-
device={device}
|
|
35
|
-
/>
|
|
36
|
-
</div>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Default 404 page for CMS routes.
|
|
42
|
-
* Sites can override with their own branded version.
|
|
43
|
-
*/
|
|
44
|
-
export function NotFoundPage() {
|
|
45
|
-
return (
|
|
46
|
-
<div className="min-h-screen flex items-center justify-center">
|
|
47
|
-
<div className="text-center">
|
|
48
|
-
<h1 className="text-6xl font-bold text-base-content/20 mb-4">404</h1>
|
|
49
|
-
<h2 className="text-2xl font-bold mb-2">Page Not Found</h2>
|
|
50
|
-
<p className="text-base-content/60 mb-6">No CMS page block matches this URL.</p>
|
|
51
|
-
<Link to="/" className="btn btn-primary">
|
|
52
|
-
Go Home
|
|
53
|
-
</Link>
|
|
54
|
-
</div>
|
|
55
|
-
</div>
|
|
56
|
-
);
|
|
57
|
-
}
|
package/src/routes/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export type { PageSeo } from "@decocms/blocks/cms";
|
|
2
|
-
export type { Device } from "@decocms/blocks/sdk/useDevice";
|
|
3
|
-
export {
|
|
4
|
-
decoInvokeRouteConfig,
|
|
5
|
-
decoMetaRouteConfig,
|
|
6
|
-
decoRenderRouteConfig,
|
|
7
|
-
} from "./adminRoutes";
|
|
8
|
-
export {
|
|
9
|
-
CmsPagePendingFallback,
|
|
10
|
-
type CmsRouteOptions,
|
|
11
|
-
cmsHomeRouteConfig,
|
|
12
|
-
cmsRouteConfig,
|
|
13
|
-
loadCmsHomePage,
|
|
14
|
-
loadCmsPage,
|
|
15
|
-
loadDeferredSection,
|
|
16
|
-
setSectionChunkMap,
|
|
17
|
-
} from "./cmsRoute";
|
|
18
|
-
export { deferredSectionLoader } from "../sdk/deferredSectionLoader";
|
|
19
|
-
export { CmsPage, NotFoundPage } from "./components";
|
|
20
|
-
export {
|
|
21
|
-
resolveSiteGlobals,
|
|
22
|
-
type SiteGlobalsLoaderData,
|
|
23
|
-
withSiteGlobals,
|
|
24
|
-
} from "./withSiteGlobals";
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { derivePageUrl, isClientNavigation } from "./pageUrl";
|
|
3
|
-
|
|
4
|
-
describe("derivePageUrl (#280 — client-nav request URL)", () => {
|
|
5
|
-
it("SSR real page without query: rebuilds from fullPath", () => {
|
|
6
|
-
expect(
|
|
7
|
-
derivePageUrl("/acme/produto", new URL("https://o.com/acme/produto")),
|
|
8
|
-
).toBe("https://o.com/acme/produto");
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it("SSR real page preserves duplicate query params from the server URL", () => {
|
|
12
|
-
// The TanStack search record collapses dup params; the server URL keeps them.
|
|
13
|
-
expect(
|
|
14
|
-
derivePageUrl(
|
|
15
|
-
"/c/shoes?filter.category-1=a",
|
|
16
|
-
new URL("https://o.com/c/shoes?filter.category-1=a&filter.category-1=b"),
|
|
17
|
-
),
|
|
18
|
-
).toBe("https://o.com/c/shoes?filter.category-1=a&filter.category-1=b");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("client nav without query: rebuilds from fullPath, NOT the /_serverFn URL", () => {
|
|
22
|
-
// The regression guard: getRequestUrl() is the serverFn endpoint here.
|
|
23
|
-
const serverUrl = new URL(
|
|
24
|
-
"https://o.com/_serverFn/loadCmsPage?payload=%2Facme%2Fproduto",
|
|
25
|
-
);
|
|
26
|
-
expect(derivePageUrl("/acme/produto", serverUrl)).toBe(
|
|
27
|
-
"https://o.com/acme/produto",
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("client nav with query: rebuilds path+search from fullPath", () => {
|
|
32
|
-
const serverUrl = new URL("https://o.com/_serverFn/loadCmsPage?payload=x");
|
|
33
|
-
expect(derivePageUrl("/s?q=foo", serverUrl)).toBe("https://o.com/s?q=foo");
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("home '/' on client nav: rebuilds to '/', not the /_serverFn URL", () => {
|
|
37
|
-
// basePath '/' is a prefix of every path; the old startsWith check would
|
|
38
|
-
// have returned the serverFn URL here.
|
|
39
|
-
const serverUrl = new URL("https://o.com/_serverFn/loadCmsPage?payload=x");
|
|
40
|
-
expect(derivePageUrl("/", serverUrl)).toBe("https://o.com/");
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe("isClientNavigation (SPA vs SSR detection)", () => {
|
|
45
|
-
it("SSR real page (path matches): false", () => {
|
|
46
|
-
expect(
|
|
47
|
-
isClientNavigation("/c/shoes?q=a", new URL("https://o.com/c/shoes?q=a")),
|
|
48
|
-
).toBe(false);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("SSR real page without query (path matches): false", () => {
|
|
52
|
-
expect(
|
|
53
|
-
isClientNavigation("/acme/produto", new URL("https://o.com/acme/produto")),
|
|
54
|
-
).toBe(false);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("client nav (server fn endpoint): true", () => {
|
|
58
|
-
const serverUrl = new URL("https://o.com/_serverFn/loadCmsPage?payload=x");
|
|
59
|
-
expect(isClientNavigation("/c/shoes", serverUrl)).toBe(true);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("home '/' on client nav: true", () => {
|
|
63
|
-
const serverUrl = new URL("https://o.com/_serverFn/loadCmsPage?payload=x");
|
|
64
|
-
expect(isClientNavigation("/", serverUrl)).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("home '/' on SSR: false", () => {
|
|
68
|
-
expect(isClientNavigation("/", new URL("https://o.com/"))).toBe(false);
|
|
69
|
-
});
|
|
70
|
-
});
|
package/src/routes/pageUrl.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Derive the real page URL for a CMS page load.
|
|
3
|
-
*
|
|
4
|
-
* On client-side (SPA) navigation the CMS server function runs at a
|
|
5
|
-
* `/_serverFn/<hash>?payload=...` URL — that's what `getRequestUrl()` returns,
|
|
6
|
-
* and it is NOT the page the router is navigating to. In that case we rebuild
|
|
7
|
-
* the URL from `fullPath` (the page's path + search). On a real page request
|
|
8
|
-
* (SSR / full reload) the server URL's path equals the page path, and we prefer
|
|
9
|
-
* it because it preserves duplicate query params (e.g.
|
|
10
|
-
* `filter.category-1=a&filter.category-1=b`) that the TanStack Router search
|
|
11
|
-
* object — a plain `Record<string,string>` — would collapse.
|
|
12
|
-
*
|
|
13
|
-
* Keeping the derived `__pageUrl` consistent with `__pagePath` is what makes
|
|
14
|
-
* URL/slug-keyed loaders resolve identically on SSR and SPA navigation (#280).
|
|
15
|
-
* The previous logic compared with `startsWith` and fell back to the serverFn
|
|
16
|
-
* URL when `fullPath` had no query string, leaking `/_serverFn/...` into
|
|
17
|
-
* `matcherCtx.url` on client nav.
|
|
18
|
-
*
|
|
19
|
-
* @param fullPath page path + optional search, e.g. `/c/shoes?q=foo`
|
|
20
|
-
* @param serverUrl URL returned by `getRequestUrl()` (real page URL on SSR,
|
|
21
|
-
* `/_serverFn/...` on client nav)
|
|
22
|
-
*/
|
|
23
|
-
export function derivePageUrl(fullPath: string, serverUrl: URL): string {
|
|
24
|
-
const [basePath] = fullPath.split("?");
|
|
25
|
-
// Trust the server URL (to keep duplicate query params) only when its path
|
|
26
|
-
// IS the page being loaded — i.e. a real page request. On client nav the
|
|
27
|
-
// path is `/_serverFn/...`, so we rebuild from `fullPath` instead.
|
|
28
|
-
return serverUrl.pathname === basePath && serverUrl.search
|
|
29
|
-
? serverUrl.toString()
|
|
30
|
-
: new URL(fullPath, serverUrl.origin).toString();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* True when the page load came from a client-side (SPA) navigation via
|
|
35
|
-
* TanStack `<Link>`: the CMS server function runs at `/_serverFn/<hash>`, so
|
|
36
|
-
* `serverUrl.pathname` is NOT the page path. On a real document request (SSR /
|
|
37
|
-
* full reload, including bots) `serverUrl.pathname === basePath`.
|
|
38
|
-
*
|
|
39
|
-
* This does NOT gate section deferral: a client nav gets the same eager/deferred
|
|
40
|
-
* split as SSR, because the route loader is blocking and awaiting the below-fold
|
|
41
|
-
* sections freezes the transition. Callers use it to rebuild the real page URL
|
|
42
|
-
* (`derivePageUrl`) and to tell a SPA nav apart from a genuine AJAX consumer
|
|
43
|
-
* (`isProgrammaticFetch`) — both send `Sec-Fetch-Dest: empty`.
|
|
44
|
-
*
|
|
45
|
-
* Mirrors the `serverUrl.pathname === basePath` comparison `derivePageUrl`
|
|
46
|
-
* already relies on, so the two stay consistent and we avoid hardcoding the
|
|
47
|
-
* internal `/_serverFn` path.
|
|
48
|
-
*
|
|
49
|
-
* @param fullPath page path + optional search, e.g. `/c/shoes?q=foo`
|
|
50
|
-
* @param serverUrl URL returned by `getRequestUrl()`
|
|
51
|
-
*/
|
|
52
|
-
export function isClientNavigation(fullPath: string, serverUrl: URL): boolean {
|
|
53
|
-
const [basePath] = fullPath.split("?");
|
|
54
|
-
return serverUrl.pathname !== basePath;
|
|
55
|
-
}
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
|
|
3
|
-
const { onChangeListeners } = vi.hoisted(() => ({
|
|
4
|
-
onChangeListeners: [] as Array<() => void>,
|
|
5
|
-
}));
|
|
6
|
-
|
|
7
|
-
vi.mock("@decocms/blocks/cms", () => ({
|
|
8
|
-
loadBlocks: vi.fn(),
|
|
9
|
-
onChange: vi.fn((listener: () => void) => {
|
|
10
|
-
onChangeListeners.push(listener);
|
|
11
|
-
}),
|
|
12
|
-
resolvePageSections: vi.fn(),
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
import { loadBlocks, resolvePageSections } from "@decocms/blocks/cms";
|
|
16
|
-
import {
|
|
17
|
-
__resetSiteGlobalsCache,
|
|
18
|
-
dedupeGlobals,
|
|
19
|
-
resolveSiteGlobals,
|
|
20
|
-
withSiteGlobals,
|
|
21
|
-
} from "./withSiteGlobals";
|
|
22
|
-
|
|
23
|
-
const mockedLoadBlocks = loadBlocks as unknown as ReturnType<typeof vi.fn>;
|
|
24
|
-
const mockedResolvePageSections = resolvePageSections as unknown as ReturnType<typeof vi.fn>;
|
|
25
|
-
|
|
26
|
-
describe("withSiteGlobals", () => {
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
__resetSiteGlobalsCache();
|
|
29
|
-
mockedLoadBlocks.mockReset();
|
|
30
|
-
mockedResolvePageSections.mockReset();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe("resolveSiteGlobals", () => {
|
|
34
|
-
it("returns empty when there is no Site block", async () => {
|
|
35
|
-
mockedLoadBlocks.mockReturnValue({});
|
|
36
|
-
const result = await resolveSiteGlobals();
|
|
37
|
-
expect(result.resolvedSections).toEqual([]);
|
|
38
|
-
expect(result.rawRefs).toEqual([]);
|
|
39
|
-
expect(mockedResolvePageSections).not.toHaveBeenCalled();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("returns empty when Site block has no globals", async () => {
|
|
43
|
-
mockedLoadBlocks.mockReturnValue({ site: { seo: { title: "x" } } });
|
|
44
|
-
const result = await resolveSiteGlobals();
|
|
45
|
-
expect(result.resolvedSections).toEqual([]);
|
|
46
|
-
expect(result.rawRefs).toEqual([]);
|
|
47
|
-
expect(mockedResolvePageSections).not.toHaveBeenCalled();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("gathers theme + global + pageSections in order", async () => {
|
|
51
|
-
mockedLoadBlocks.mockReturnValue({
|
|
52
|
-
site: {
|
|
53
|
-
theme: { __resolveType: "Theme" },
|
|
54
|
-
global: [{ __resolveType: "Analytics" }, { __resolveType: "WishlistProvider" }],
|
|
55
|
-
pageSections: [{ __resolveType: "Session" }],
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
const resolved = [
|
|
59
|
-
{ component: "Theme.tsx", props: {}, key: "k0" },
|
|
60
|
-
{ component: "Analytics.tsx", props: {}, key: "k1" },
|
|
61
|
-
{ component: "Wishlist.tsx", props: {}, key: "k2" },
|
|
62
|
-
{ component: "Session.tsx", props: {}, key: "k3" },
|
|
63
|
-
];
|
|
64
|
-
mockedResolvePageSections.mockResolvedValue(resolved);
|
|
65
|
-
|
|
66
|
-
const result = await resolveSiteGlobals();
|
|
67
|
-
|
|
68
|
-
expect(result.rawRefs).toEqual([
|
|
69
|
-
{ __resolveType: "Theme" },
|
|
70
|
-
{ __resolveType: "Analytics" },
|
|
71
|
-
{ __resolveType: "WishlistProvider" },
|
|
72
|
-
{ __resolveType: "Session" },
|
|
73
|
-
]);
|
|
74
|
-
expect(result.resolvedSections).toEqual(resolved);
|
|
75
|
-
expect(mockedResolvePageSections).toHaveBeenCalledTimes(1);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("accepts both `site` (lowercase) and `Site` (PascalCase) block keys", async () => {
|
|
79
|
-
mockedLoadBlocks.mockReturnValue({
|
|
80
|
-
Site: { theme: { __resolveType: "Theme" } },
|
|
81
|
-
});
|
|
82
|
-
mockedResolvePageSections.mockResolvedValue([
|
|
83
|
-
{ component: "Theme.tsx", props: {}, key: "k0" },
|
|
84
|
-
]);
|
|
85
|
-
const result = await resolveSiteGlobals();
|
|
86
|
-
expect(result.rawRefs).toEqual([{ __resolveType: "Theme" }]);
|
|
87
|
-
expect(result.resolvedSections).toHaveLength(1);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("dedupes inflight requests (single resolvePageSections call for parallel callers)", async () => {
|
|
91
|
-
mockedLoadBlocks.mockReturnValue({
|
|
92
|
-
site: { global: [{ __resolveType: "Analytics" }] },
|
|
93
|
-
});
|
|
94
|
-
let resolveFn!: (v: unknown[]) => void;
|
|
95
|
-
mockedResolvePageSections.mockImplementation(
|
|
96
|
-
() =>
|
|
97
|
-
new Promise((res) => {
|
|
98
|
-
resolveFn = res as any;
|
|
99
|
-
}),
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
const a = resolveSiteGlobals();
|
|
103
|
-
const b = resolveSiteGlobals();
|
|
104
|
-
resolveFn([{ component: "A.tsx", props: {}, key: "k0" }]);
|
|
105
|
-
const [ra, rb] = await Promise.all([a, b]);
|
|
106
|
-
|
|
107
|
-
expect(ra).toEqual(rb);
|
|
108
|
-
expect(mockedResolvePageSections).toHaveBeenCalledTimes(1);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("caches across calls within TTL", async () => {
|
|
112
|
-
mockedLoadBlocks.mockReturnValue({
|
|
113
|
-
site: { global: [{ __resolveType: "Analytics" }] },
|
|
114
|
-
});
|
|
115
|
-
mockedResolvePageSections.mockResolvedValue([{ component: "A.tsx", props: {}, key: "k0" }]);
|
|
116
|
-
|
|
117
|
-
await resolveSiteGlobals();
|
|
118
|
-
await resolveSiteGlobals();
|
|
119
|
-
await resolveSiteGlobals();
|
|
120
|
-
|
|
121
|
-
expect(mockedResolvePageSections).toHaveBeenCalledTimes(1);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("threads matcherCtx to resolvePageSections", async () => {
|
|
125
|
-
mockedLoadBlocks.mockReturnValue({
|
|
126
|
-
site: { global: [{ __resolveType: "Alert" }] },
|
|
127
|
-
});
|
|
128
|
-
mockedResolvePageSections.mockResolvedValue([{ component: "A.tsx", props: {}, key: "k0" }]);
|
|
129
|
-
|
|
130
|
-
const ctx = { path: "/farm-etc" } as any;
|
|
131
|
-
await resolveSiteGlobals(ctx);
|
|
132
|
-
|
|
133
|
-
expect(mockedResolvePageSections).toHaveBeenCalledWith(
|
|
134
|
-
[{ __resolveType: "Alert" }],
|
|
135
|
-
ctx,
|
|
136
|
-
);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("caches per path — different routes don't share a matched variant", async () => {
|
|
140
|
-
mockedLoadBlocks.mockReturnValue({
|
|
141
|
-
site: { global: [{ __resolveType: "Alert" }] },
|
|
142
|
-
});
|
|
143
|
-
mockedResolvePageSections
|
|
144
|
-
.mockResolvedValueOnce([{ component: "EtcAlert.tsx", props: {}, key: "etc" }])
|
|
145
|
-
.mockResolvedValueOnce([{ component: "HomeAlert.tsx", props: {}, key: "home" }]);
|
|
146
|
-
|
|
147
|
-
const etc = await resolveSiteGlobals({ path: "/farm-etc" } as any);
|
|
148
|
-
const home = await resolveSiteGlobals({ path: "/" } as any);
|
|
149
|
-
|
|
150
|
-
// Distinct paths resolve independently (no cross-route leak)...
|
|
151
|
-
expect(etc.resolvedSections[0].key).toBe("etc");
|
|
152
|
-
expect(home.resolvedSections[0].key).toBe("home");
|
|
153
|
-
expect(mockedResolvePageSections).toHaveBeenCalledTimes(2);
|
|
154
|
-
|
|
155
|
-
// ...and the same path is still served from cache.
|
|
156
|
-
const etcAgain = await resolveSiteGlobals({ path: "/farm-etc" } as any);
|
|
157
|
-
expect(etcAgain.resolvedSections[0].key).toBe("etc");
|
|
158
|
-
expect(mockedResolvePageSections).toHaveBeenCalledTimes(2);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("invalidates cache when onChange fires", async () => {
|
|
162
|
-
mockedLoadBlocks.mockReturnValue({
|
|
163
|
-
site: { global: [{ __resolveType: "Analytics" }] },
|
|
164
|
-
});
|
|
165
|
-
mockedResolvePageSections.mockResolvedValue([{ component: "A.tsx", props: {}, key: "k0" }]);
|
|
166
|
-
|
|
167
|
-
await resolveSiteGlobals();
|
|
168
|
-
expect(mockedResolvePageSections).toHaveBeenCalledTimes(1);
|
|
169
|
-
|
|
170
|
-
// Simulate a CMS reload
|
|
171
|
-
for (const listener of onChangeListeners) listener();
|
|
172
|
-
|
|
173
|
-
await resolveSiteGlobals();
|
|
174
|
-
expect(mockedResolvePageSections).toHaveBeenCalledTimes(2);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("does not cache failures (next call retries)", async () => {
|
|
178
|
-
mockedLoadBlocks.mockReturnValue({
|
|
179
|
-
site: { global: [{ __resolveType: "Analytics" }] },
|
|
180
|
-
});
|
|
181
|
-
mockedResolvePageSections
|
|
182
|
-
.mockRejectedValueOnce(new Error("boom"))
|
|
183
|
-
.mockResolvedValueOnce([{ component: "A.tsx", props: {}, key: "k0" }]);
|
|
184
|
-
|
|
185
|
-
const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
186
|
-
const first = await resolveSiteGlobals();
|
|
187
|
-
expect(first.resolvedSections).toEqual([]);
|
|
188
|
-
|
|
189
|
-
const second = await resolveSiteGlobals();
|
|
190
|
-
expect(second.resolvedSections).toHaveLength(1);
|
|
191
|
-
expect(mockedResolvePageSections).toHaveBeenCalledTimes(2);
|
|
192
|
-
errSpy.mockRestore();
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
describe("withSiteGlobals (deprecated no-op)", () => {
|
|
197
|
-
// Site globals merging moved into the `loadCmsPage` server function so SSR
|
|
198
|
-
// and SPA navigations both go through the same server-side path (#233).
|
|
199
|
-
// The wrapper is now a passthrough kept only for backward compatibility.
|
|
200
|
-
it("is an identity wrapper — returns the route config unchanged", () => {
|
|
201
|
-
const baseLoader = vi.fn().mockResolvedValue({ resolvedSections: [] });
|
|
202
|
-
const input = { loader: baseLoader, otherField: "kept" } as any;
|
|
203
|
-
const cfg = withSiteGlobals(input);
|
|
204
|
-
expect(cfg).toBe(input);
|
|
205
|
-
expect(cfg.loader).toBe(baseLoader);
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
describe("dedupeGlobals", () => {
|
|
210
|
-
it("returns empty when globals is empty", () => {
|
|
211
|
-
expect(
|
|
212
|
-
dedupeGlobals(
|
|
213
|
-
[],
|
|
214
|
-
[{ component: "Header.tsx", props: {}, key: "p0" }],
|
|
215
|
-
),
|
|
216
|
-
).toEqual([]);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("drops globals whose component already appears in existing", () => {
|
|
220
|
-
const globals = [
|
|
221
|
-
{ component: "Theme.tsx", props: {}, key: "g0" },
|
|
222
|
-
{ component: "Session.tsx", props: {}, key: "g1" },
|
|
223
|
-
];
|
|
224
|
-
const existing = [
|
|
225
|
-
{ component: "Session.tsx", props: { fromPage: true }, key: "p0" },
|
|
226
|
-
];
|
|
227
|
-
|
|
228
|
-
const result = dedupeGlobals(globals, existing);
|
|
229
|
-
// Session dropped (already on page); Theme kept.
|
|
230
|
-
expect(result.map((s) => s.component)).toEqual(["Theme.tsx"]);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it("dedupes within globals (first-wins)", () => {
|
|
234
|
-
const globals = [
|
|
235
|
-
{ component: "Session.tsx", props: { from: "global" }, key: "g0" },
|
|
236
|
-
{ component: "Session.tsx", props: { from: "pageSections" }, key: "g1" },
|
|
237
|
-
];
|
|
238
|
-
const result = dedupeGlobals(globals, []);
|
|
239
|
-
expect(result).toHaveLength(1);
|
|
240
|
-
expect(result[0].props.from).toBe("global");
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
});
|