@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,99 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
|
|
3
|
-
vi.mock("@decocms/blocks-admin", () => ({
|
|
4
|
-
corsHeaders: vi.fn(() => ({})),
|
|
5
|
-
handleInvoke: vi.fn(),
|
|
6
|
-
handleMeta: vi.fn(),
|
|
7
|
-
handleRender: vi.fn(),
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
vi.mock("@decocms/blocks/middleware/observability", () => ({
|
|
11
|
-
withTracing: vi.fn((_name: string, fn: () => unknown) => fn()),
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
import * as adminRoutes from "./adminRoutes";
|
|
15
|
-
import { decoInvokeRouteConfig, decoMetaRouteConfig, decoRenderRouteConfig } from "./adminRoutes";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Regression guard for the dev-HMR brick:
|
|
19
|
-
*
|
|
20
|
-
* TanStack router-core's `BaseRoute.update()` mutates the options object it
|
|
21
|
-
* is handed (`Object.assign(this.options, options)` — injecting `id`/`path`).
|
|
22
|
-
* Before 7.10.0 this module exported shared module-scope literals
|
|
23
|
-
* (`decoMetaRoute`/`decoRenderRoute`/`decoInvokeRoute`); a site passing one
|
|
24
|
-
* by reference polluted it on first execution, and on any HMR re-execution
|
|
25
|
-
* the route constructor threw
|
|
26
|
-
* `Route cannot have both an 'id' and a 'path' option` — every route 500ed
|
|
27
|
-
* until dev restart.
|
|
28
|
-
*
|
|
29
|
-
* The `*RouteConfig()` factories must therefore return a FRESH object on
|
|
30
|
-
* every call, and the shared literals must never be (re-)exported.
|
|
31
|
-
*/
|
|
32
|
-
describe("admin route config factories", () => {
|
|
33
|
-
const cases = [
|
|
34
|
-
{
|
|
35
|
-
name: "decoMetaRouteConfig",
|
|
36
|
-
factory: decoMetaRouteConfig,
|
|
37
|
-
methods: ["GET", "OPTIONS"],
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: "decoRenderRouteConfig",
|
|
41
|
-
factory: decoRenderRouteConfig,
|
|
42
|
-
methods: ["GET", "POST", "OPTIONS"],
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
name: "decoInvokeRouteConfig",
|
|
46
|
-
factory: decoInvokeRouteConfig,
|
|
47
|
-
methods: ["GET", "POST", "OPTIONS"],
|
|
48
|
-
},
|
|
49
|
-
] as const;
|
|
50
|
-
|
|
51
|
-
for (const { name, factory, methods } of cases) {
|
|
52
|
-
describe(name, () => {
|
|
53
|
-
it("returns a new object on every call", () => {
|
|
54
|
-
expect(factory()).not.toBe(factory());
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("returns structurally equal configs across calls", () => {
|
|
58
|
-
expect(factory()).toEqual(factory());
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it(`exposes server handlers for ${methods.join("/")}`, () => {
|
|
62
|
-
const config = factory() as {
|
|
63
|
-
server: { handlers: Record<string, unknown> };
|
|
64
|
-
};
|
|
65
|
-
expect(Object.keys(config.server.handlers).sort()).toEqual([...methods].sort());
|
|
66
|
-
for (const method of methods) {
|
|
67
|
-
expect(config.server.handlers[method]).toBeTypeOf("function");
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("survives router-core-style mutation without polluting later calls", () => {
|
|
72
|
-
// Simulate BaseRoute.update(): Object.assign(this.options, options)
|
|
73
|
-
// pollutes whatever object createFileRoute was handed.
|
|
74
|
-
const options = factory() as Record<string, unknown>;
|
|
75
|
-
Object.assign(options, { id: "/deco/x", path: "/deco/x" });
|
|
76
|
-
|
|
77
|
-
// The next module execution (HMR) gets a clean object again.
|
|
78
|
-
const next = factory();
|
|
79
|
-
expect(next).not.toHaveProperty("id");
|
|
80
|
-
expect(next).not.toHaveProperty("path");
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
it("does NOT export the removed pre-7.10.0 literals (dev-HMR footgun)", () => {
|
|
86
|
-
// The shared module-scope literals were removed in 7.10.0. Re-exporting
|
|
87
|
-
// them would reintroduce the HMR brick for any site passing them by
|
|
88
|
-
// reference to createFileRoute.
|
|
89
|
-
const removed = ["decoMetaRoute", "decoRenderRoute", "decoInvokeRoute"];
|
|
90
|
-
for (const name of removed) {
|
|
91
|
-
expect(adminRoutes, `"${name}" must not be exported`).not.toHaveProperty(name);
|
|
92
|
-
}
|
|
93
|
-
expect(Object.keys(adminRoutes).sort()).toEqual([
|
|
94
|
-
"decoInvokeRouteConfig",
|
|
95
|
-
"decoMetaRouteConfig",
|
|
96
|
-
"decoRenderRouteConfig",
|
|
97
|
-
]);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Admin Route Helpers
|
|
3
|
-
*
|
|
4
|
-
* Pre-built server handler config factories for the Deco admin protocol
|
|
5
|
-
* routes. Sites call these in their `createFileRoute` definitions to avoid
|
|
6
|
-
* repeating the same CORS + handler boilerplate.
|
|
7
|
-
*
|
|
8
|
-
* @example Site's `src/routes/deco/meta.ts`:
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { createFileRoute } from "@tanstack/react-router";
|
|
11
|
-
* import { decoMetaRouteConfig } from "@decocms/tanstack";
|
|
12
|
-
*
|
|
13
|
-
* export const Route = createFileRoute("/deco/meta")(decoMetaRouteConfig());
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* ## Why factories and not shared config objects? (dev-HMR footgun)
|
|
17
|
-
*
|
|
18
|
-
* TanStack router-core's `BaseRoute.update()` MUTATES the options object it
|
|
19
|
-
* receives (`Object.assign(this.options, options)` — injecting `id` and
|
|
20
|
-
* `path`). Before 7.10.0 this module exported the configs as module-scope
|
|
21
|
-
* LITERALS (`decoMetaRoute` / `decoRenderRoute` / `decoInvokeRoute`); a site
|
|
22
|
-
* passing one by reference (`createFileRoute("/deco/meta")(decoMetaRoute)`)
|
|
23
|
-
* polluted the shared literal on first execution, and any dev-server HMR
|
|
24
|
-
* partial re-execution then re-ran the route file against the still-cached,
|
|
25
|
-
* now-polluted literal — the route constructor threw
|
|
26
|
-
* `Route cannot have both an 'id' and a 'path' option` and every route 500ed
|
|
27
|
-
* until the dev server restarted. The factories hand each `createFileRoute`
|
|
28
|
-
* call its own fresh object, so the mutation is harmless. The base configs
|
|
29
|
-
* below are module-private and deliberately NOT exported.
|
|
30
|
-
*/
|
|
31
|
-
import { corsHeaders, handleInvoke, handleMeta, handleRender } from "@decocms/blocks-admin";
|
|
32
|
-
import { withTracing } from "@decocms/blocks/middleware/observability";
|
|
33
|
-
|
|
34
|
-
function invokeAttrs(request: Request): Record<string, string | boolean> {
|
|
35
|
-
const url = new URL(request.url);
|
|
36
|
-
const invokeKey = url.pathname.split("/deco/invoke/")[1] ?? "";
|
|
37
|
-
return {
|
|
38
|
-
"invoke.key": invokeKey || "(batch)",
|
|
39
|
-
"invoke.batch": invokeKey === "",
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function renderAttrs(request: Request): Record<string, string> {
|
|
44
|
-
const url = new URL(request.url);
|
|
45
|
-
const pathComponent = url.pathname.split("/deco/render/")[1] ?? "";
|
|
46
|
-
return { "cms.component": pathComponent || "(page)" };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
type HandlerFn = (ctx: { request: Request }) => Promise<Response> | Response;
|
|
50
|
-
|
|
51
|
-
function withCors(handler: HandlerFn): HandlerFn {
|
|
52
|
-
return async (ctx) => {
|
|
53
|
-
const response = await handler(ctx);
|
|
54
|
-
const headers = new Headers(response.headers);
|
|
55
|
-
for (const [k, v] of Object.entries(corsHeaders(ctx.request))) {
|
|
56
|
-
headers.set(k, v);
|
|
57
|
-
}
|
|
58
|
-
return new Response(response.body, {
|
|
59
|
-
status: response.status,
|
|
60
|
-
headers,
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function optionsHandler(ctx: { request: Request }): Response {
|
|
66
|
-
return new Response(null, {
|
|
67
|
-
status: 204,
|
|
68
|
-
headers: corsHeaders(ctx.request),
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// ---------------------------------------------------------------------------
|
|
73
|
-
// Base configs — module-PRIVATE. Never export these: router-core's update()
|
|
74
|
-
// mutates whatever object createFileRoute is handed (injects id/path), so a
|
|
75
|
-
// shared exported literal bricks dev HMR (see module doc above). Sites get
|
|
76
|
-
// fresh copies via the *RouteConfig() factories below.
|
|
77
|
-
// ---------------------------------------------------------------------------
|
|
78
|
-
|
|
79
|
-
/** Base config for `/deco/meta` — serves JSON Schema + manifest. */
|
|
80
|
-
const decoMetaRoute = {
|
|
81
|
-
server: {
|
|
82
|
-
handlers: {
|
|
83
|
-
GET: withCors(({ request }) =>
|
|
84
|
-
withTracing("deco.admin.meta", async () => handleMeta(request)),
|
|
85
|
-
),
|
|
86
|
-
OPTIONS: optionsHandler,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
/** Base config for `/deco/render` — section/page preview in iframe. */
|
|
92
|
-
const decoRenderRoute = {
|
|
93
|
-
server: {
|
|
94
|
-
handlers: {
|
|
95
|
-
GET: withCors(({ request }) =>
|
|
96
|
-
withTracing(
|
|
97
|
-
"deco.admin.render",
|
|
98
|
-
() => Promise.resolve(handleRender(request)),
|
|
99
|
-
renderAttrs(request),
|
|
100
|
-
),
|
|
101
|
-
),
|
|
102
|
-
POST: withCors(({ request }) =>
|
|
103
|
-
withTracing(
|
|
104
|
-
"deco.admin.render",
|
|
105
|
-
() => Promise.resolve(handleRender(request)),
|
|
106
|
-
renderAttrs(request),
|
|
107
|
-
),
|
|
108
|
-
),
|
|
109
|
-
OPTIONS: optionsHandler,
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
/** Base config for `/deco/invoke/$` — loader/action execution. */
|
|
115
|
-
const decoInvokeRoute = {
|
|
116
|
-
server: {
|
|
117
|
-
handlers: {
|
|
118
|
-
GET: withCors(({ request }) =>
|
|
119
|
-
withTracing("deco.admin.invoke", () => handleInvoke(request), invokeAttrs(request)),
|
|
120
|
-
),
|
|
121
|
-
POST: withCors(({ request }) =>
|
|
122
|
-
withTracing("deco.admin.invoke", () => handleInvoke(request), invokeAttrs(request)),
|
|
123
|
-
),
|
|
124
|
-
OPTIONS: optionsHandler,
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// ---------------------------------------------------------------------------
|
|
130
|
-
// Factories — dev-HMR-safe route configs (fresh object per call)
|
|
131
|
-
// ---------------------------------------------------------------------------
|
|
132
|
-
// Mirrors the `cmsRouteConfig()` / `cmsHomeRouteConfig()` convention in
|
|
133
|
-
// cmsRoute.ts: a function returning a fresh options object, so router-core's
|
|
134
|
-
// mutating `update()` can never pollute shared module state across HMR
|
|
135
|
-
// re-executions.
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Returns a fresh route config for `/deco/meta` — serves JSON Schema + manifest.
|
|
139
|
-
* Use as `createFileRoute("/deco/meta")(decoMetaRouteConfig())`.
|
|
140
|
-
*/
|
|
141
|
-
export const decoMetaRouteConfig = () => ({ ...decoMetaRoute });
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Returns a fresh route config for `/deco/render` — section/page preview in iframe.
|
|
145
|
-
* Use as `createFileRoute("/deco/render")(decoRenderRouteConfig())`.
|
|
146
|
-
*/
|
|
147
|
-
export const decoRenderRouteConfig = () => ({ ...decoRenderRoute });
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Returns a fresh route config for `/deco/invoke/$` — loader/action execution.
|
|
151
|
-
* Use as `createFileRoute("/deco/invoke/$")(decoInvokeRouteConfig())`.
|
|
152
|
-
*/
|
|
153
|
-
export const decoInvokeRouteConfig = () => ({ ...decoInvokeRoute });
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
registerCacheableSections,
|
|
3
|
-
registerSectionLoader,
|
|
4
|
-
runSectionLoaders,
|
|
5
|
-
} from "@decocms/blocks/cms";
|
|
6
|
-
import type { ResolvedSection } from "@decocms/blocks/cms";
|
|
7
|
-
import { describe, expect, it } from "vitest";
|
|
8
|
-
import {
|
|
9
|
-
CmsPagePendingFallback,
|
|
10
|
-
cmsHomeRouteConfig,
|
|
11
|
-
cmsRouteConfig,
|
|
12
|
-
parseLoadCmsHomePageInput,
|
|
13
|
-
parseLoadCmsPageInput,
|
|
14
|
-
enrichGlobals,
|
|
15
|
-
runSectionLoadersWithSeo,
|
|
16
|
-
} from "./cmsRoute";
|
|
17
|
-
|
|
18
|
-
describe("parseLoadCmsPageInput (#292)", () => {
|
|
19
|
-
it("treats a bare string as the path with resolveGlobals defaulting to true (back-compat)", () => {
|
|
20
|
-
expect(parseLoadCmsPageInput("/produto/tenis")).toEqual({
|
|
21
|
-
path: "/produto/tenis",
|
|
22
|
-
resolveGlobals: true,
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("accepts { path, resolveGlobals } and preserves an explicit false", () => {
|
|
27
|
-
expect(parseLoadCmsPageInput({ path: "/produto/tenis", resolveGlobals: false })).toEqual({
|
|
28
|
-
path: "/produto/tenis",
|
|
29
|
-
resolveGlobals: false,
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("defaults resolveGlobals to true when omitted from the object form", () => {
|
|
34
|
-
expect(parseLoadCmsPageInput({ path: "/produto/tenis" })).toEqual({
|
|
35
|
-
path: "/produto/tenis",
|
|
36
|
-
resolveGlobals: true,
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe("parseLoadCmsHomePageInput (#292)", () => {
|
|
42
|
-
it("defaults resolveGlobals to true when called with no data (back-compat)", () => {
|
|
43
|
-
expect(parseLoadCmsHomePageInput(undefined)).toEqual({ resolveGlobals: true });
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("preserves an explicit resolveGlobals: false", () => {
|
|
47
|
-
expect(parseLoadCmsHomePageInput({ resolveGlobals: false })).toEqual({ resolveGlobals: false });
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Regression guard for #355: body sections and the SEO section used to be
|
|
53
|
-
* resolved sequentially (`runSectionLoaders` for the body, then a separate
|
|
54
|
-
* `runSingleSectionLoader` call for the SEO section inside `buildPageSeo`).
|
|
55
|
-
* On a PDP, both commonly resolve the SAME product via the SAME commerce
|
|
56
|
-
* loader — sequential calls always missed the fetch-cache layer's in-flight
|
|
57
|
-
* dedup (the body call had already completed by the time the SEO call
|
|
58
|
-
* started). Batching them into one `runSectionLoaders` call (this file's
|
|
59
|
-
* `runSectionLoadersWithSeo`) lets identical concurrent requests share one
|
|
60
|
-
* origin round-trip.
|
|
61
|
-
*
|
|
62
|
-
* This test proves the batching by registering a *cacheable* section loader
|
|
63
|
-
* (the same SWR + in-flight-dedup mechanism real commerce loaders use) and
|
|
64
|
-
* asserting it's invoked only once when the body section and SEO section
|
|
65
|
-
* share the same component + props.
|
|
66
|
-
*/
|
|
67
|
-
describe("runSectionLoadersWithSeo (#355)", () => {
|
|
68
|
-
it("dedupes a same-component/same-props SEO section against a body section via the cacheable-section in-flight cache", async () => {
|
|
69
|
-
const component = `test/sections/DedupCheck-${Date.now()}.tsx`;
|
|
70
|
-
let calls = 0;
|
|
71
|
-
|
|
72
|
-
registerCacheableSections({ [component]: { maxAge: 60_000 } });
|
|
73
|
-
registerSectionLoader(component, async (props) => {
|
|
74
|
-
calls++;
|
|
75
|
-
await new Promise((r) => setTimeout(r, 5));
|
|
76
|
-
return { ...props, loaded: true };
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const bodySection: ResolvedSection = { component, props: { sku: "123" }, key: component, index: 0 };
|
|
80
|
-
const seoSection: ResolvedSection = { component, props: { sku: "123" }, key: `${component}-seo`, index: -1 };
|
|
81
|
-
|
|
82
|
-
const request = new Request("https://store.com/produto/123");
|
|
83
|
-
const { enrichedSections, enrichedSeoSection } = await runSectionLoadersWithSeo(
|
|
84
|
-
[bodySection],
|
|
85
|
-
seoSection,
|
|
86
|
-
request,
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
expect(calls).toBe(1);
|
|
90
|
-
expect((enrichedSections[0].props as any).loaded).toBe(true);
|
|
91
|
-
expect((enrichedSeoSection?.props as any).loaded).toBe(true);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("runs plain runSectionLoaders when there is no SEO section", async () => {
|
|
95
|
-
const component = `test/sections/NoSeo-${Date.now()}.tsx`;
|
|
96
|
-
registerSectionLoader(component, async (props) => ({ ...props, loaded: true }));
|
|
97
|
-
|
|
98
|
-
const bodySection: ResolvedSection = { component, props: {}, key: component, index: 0 };
|
|
99
|
-
const { enrichedSections, enrichedSeoSection } = await runSectionLoadersWithSeo(
|
|
100
|
-
[bodySection],
|
|
101
|
-
null,
|
|
102
|
-
new Request("https://store.com/"),
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
expect((enrichedSections[0].props as any).loaded).toBe(true);
|
|
106
|
-
expect(enrichedSeoSection).toBeNull();
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Regression guard: `site.global` / `site.pageSections` entries never went
|
|
112
|
-
* through `runSectionLoaders`. `resolveSiteGlobals()` resolves only their
|
|
113
|
-
* *props* (and SWR-caches that across visitors for 5 minutes), so a global
|
|
114
|
-
* section's `loader` export simply never ran — the component rendered with
|
|
115
|
-
* raw CMS props and every loader-derived field was `undefined`.
|
|
116
|
-
*
|
|
117
|
-
* The visible symptom on a real storefront: an analytics global that has to
|
|
118
|
-
* emit its event inline, in document order (before the page-view global's
|
|
119
|
-
* script), could not do so at all. Rewriting it as a client-side `useQuery`
|
|
120
|
-
* moved the event to after hydration, which reorders the dataLayer.
|
|
121
|
-
*/
|
|
122
|
-
describe("enrichGlobals — site.global loaders run per request", () => {
|
|
123
|
-
it("runs a global section's loader with the real request", async () => {
|
|
124
|
-
const component = `test/sections/GlobalLoader-${Date.now()}.tsx`;
|
|
125
|
-
const seen: string[] = [];
|
|
126
|
-
registerSectionLoader(component, async (props, req) => {
|
|
127
|
-
seen.push(req.headers.get("cookie") ?? "");
|
|
128
|
-
return { ...props, loaded: true };
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const global: ResolvedSection = { component, props: {}, key: component, index: 0 };
|
|
132
|
-
const request = new Request("https://store.com/", { headers: { cookie: "sid=abc" } });
|
|
133
|
-
|
|
134
|
-
const result = await enrichGlobals([global], [], request);
|
|
135
|
-
|
|
136
|
-
expect((result[0].props as any).loaded).toBe(true);
|
|
137
|
-
expect(seen).toEqual(["sid=abc"]);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("dedupes before running loaders — a page-overridden global never pays for its loader", async () => {
|
|
141
|
-
const component = `test/sections/GlobalDedupe-${Date.now()}.tsx`;
|
|
142
|
-
let calls = 0;
|
|
143
|
-
registerSectionLoader(component, async (props) => {
|
|
144
|
-
calls++;
|
|
145
|
-
return props;
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
const global: ResolvedSection = { component, props: {}, key: component, index: 0 };
|
|
149
|
-
const pageSection: ResolvedSection = { component, props: {}, key: `${component}-page`, index: 1 };
|
|
150
|
-
|
|
151
|
-
const result = await enrichGlobals([global], [pageSection], new Request("https://store.com/"));
|
|
152
|
-
|
|
153
|
-
expect(result).toEqual([]);
|
|
154
|
-
expect(calls).toBe(0);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it("preserves global order and passes through globals with no registered loader", async () => {
|
|
158
|
-
const withLoader = `test/sections/GlobalA-${Date.now()}.tsx`;
|
|
159
|
-
const withoutLoader = `test/sections/GlobalB-${Date.now()}.tsx`;
|
|
160
|
-
registerSectionLoader(withLoader, async (props) => ({ ...props, loaded: true }));
|
|
161
|
-
|
|
162
|
-
const globals: ResolvedSection[] = [
|
|
163
|
-
{ component: withLoader, props: {}, key: withLoader, index: 0 },
|
|
164
|
-
{ component: withoutLoader, props: { raw: 1 }, key: withoutLoader, index: 1 },
|
|
165
|
-
];
|
|
166
|
-
|
|
167
|
-
const result = await enrichGlobals(globals, [], new Request("https://store.com/"));
|
|
168
|
-
|
|
169
|
-
expect(result.map((s) => s.component)).toEqual([withLoader, withoutLoader]);
|
|
170
|
-
expect((result[0].props as any).loaded).toBe(true);
|
|
171
|
-
expect((result[1].props as any).raw).toBe(1);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("is a no-op when every global is deduped away", async () => {
|
|
175
|
-
expect(await enrichGlobals([], [], new Request("https://store.com/"))).toEqual([]);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Both call sites dedupe against the page's RAW sections so the globals'
|
|
180
|
-
* loaders can run concurrently with the page's instead of behind them. That
|
|
181
|
-
* is only sound while `runSectionLoaders` leaves `section.component`
|
|
182
|
-
* untouched — `dedupeGlobals` reads nothing else. If a future change makes a
|
|
183
|
-
* loader rewrite `component` (or add/drop sections), the two dedupe targets
|
|
184
|
-
* stop agreeing and an overridden global would render twice. Lock it here.
|
|
185
|
-
*/
|
|
186
|
-
it("dedupes identically against raw and loader-enriched page sections", async () => {
|
|
187
|
-
const shared = `test/sections/GlobalInvariant-${Date.now()}.tsx`;
|
|
188
|
-
const globalOnly = `test/sections/GlobalOnly-${Date.now()}.tsx`;
|
|
189
|
-
registerSectionLoader(shared, async (props) => ({ ...props, loaded: true }));
|
|
190
|
-
registerSectionLoader(globalOnly, async (props) => ({ ...props, loaded: true }));
|
|
191
|
-
|
|
192
|
-
const globals: ResolvedSection[] = [
|
|
193
|
-
{ component: globalOnly, props: {}, key: globalOnly, index: 0 },
|
|
194
|
-
{ component: shared, props: {}, key: shared, index: 1 },
|
|
195
|
-
];
|
|
196
|
-
const rawPageSections: ResolvedSection[] = [
|
|
197
|
-
{ component: shared, props: { sku: "1" }, key: `${shared}-page`, index: 0 },
|
|
198
|
-
];
|
|
199
|
-
|
|
200
|
-
const request = new Request("https://store.com/");
|
|
201
|
-
const enrichedPageSections = await runSectionLoaders(rawPageSections, request);
|
|
202
|
-
|
|
203
|
-
// The loader must not have touched `component` — the whole premise.
|
|
204
|
-
expect(enrichedPageSections.map((s) => s.component)).toEqual(
|
|
205
|
-
rawPageSections.map((s) => s.component),
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
const viaRaw = await enrichGlobals(globals, rawPageSections, request);
|
|
209
|
-
const viaEnriched = await enrichGlobals(globals, enrichedPageSections, request);
|
|
210
|
-
|
|
211
|
-
expect(viaRaw.map((s) => s.component)).toEqual([globalOnly]);
|
|
212
|
-
expect(viaRaw.map((s) => s.component)).toEqual(viaEnriched.map((s) => s.component));
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
// ---------------------------------------------------------------------------
|
|
217
|
-
// Pending UI defaults
|
|
218
|
-
// ---------------------------------------------------------------------------
|
|
219
|
-
//
|
|
220
|
-
// There is deliberately NO default pendingComponent. Setting one turns every
|
|
221
|
-
// navigation slower than `pendingMs` (200ms) into a page → skeleton → page swap
|
|
222
|
-
// held for at least `pendingMinMs` (300ms). Deferral pulls most navigations into
|
|
223
|
-
// the 200–600ms band, i.e. exactly the window where that swap costs more than it
|
|
224
|
-
// buys, and this is a catch-all route, so one skeleton shape would have to serve
|
|
225
|
-
// PDP, PLP, search, and institutional pages alike. Keeping the previous page on
|
|
226
|
-
// screen until the new one commits is the better default; a site that wants a
|
|
227
|
-
// skeleton opts in per-shape.
|
|
228
|
-
//
|
|
229
|
-
// `pendingMs`/`pendingMinMs` DO keep defaults — they are inert without a
|
|
230
|
-
// pendingComponent, and they also govern a site-provided one.
|
|
231
|
-
|
|
232
|
-
describe("cmsRouteConfig / cmsHomeRouteConfig — pending UI defaults", () => {
|
|
233
|
-
const base = { siteName: "Loja", defaultTitle: "Loja" };
|
|
234
|
-
|
|
235
|
-
it("ships NO default pendingComponent — the previous page stays until commit", () => {
|
|
236
|
-
expect("pendingComponent" in cmsRouteConfig(base)).toBe(false);
|
|
237
|
-
expect("pendingComponent" in cmsHomeRouteConfig({ defaultTitle: "Loja" })).toBe(false);
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it("honors a site-provided pendingComponent on both route configs", () => {
|
|
241
|
-
const custom = () => null;
|
|
242
|
-
expect(cmsRouteConfig({ ...base, pendingComponent: custom }).pendingComponent).toBe(custom);
|
|
243
|
-
expect(
|
|
244
|
-
cmsHomeRouteConfig({ defaultTitle: "Loja", pendingComponent: custom }).pendingComponent,
|
|
245
|
-
).toBe(custom);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it("treats an explicit null the same as omitting it", () => {
|
|
249
|
-
expect("pendingComponent" in cmsRouteConfig({ ...base, pendingComponent: null })).toBe(false);
|
|
250
|
-
expect(
|
|
251
|
-
"pendingComponent" in cmsHomeRouteConfig({ defaultTitle: "Loja", pendingComponent: null }),
|
|
252
|
-
).toBe(false);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it("still exports CmsPagePendingFallback as an opt-in starting point", () => {
|
|
256
|
-
expect(typeof CmsPagePendingFallback).toBe("function");
|
|
257
|
-
expect(
|
|
258
|
-
cmsRouteConfig({ ...base, pendingComponent: CmsPagePendingFallback }).pendingComponent,
|
|
259
|
-
).toBe(CmsPagePendingFallback);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it("keeps the documented pendingMs / pendingMinMs defaults", () => {
|
|
263
|
-
const cfg = cmsRouteConfig(base);
|
|
264
|
-
expect(cfg.pendingMs).toBe(200);
|
|
265
|
-
expect(cfg.pendingMinMs).toBe(300);
|
|
266
|
-
});
|
|
267
|
-
});
|