@decocms/tanstack 7.56.0 → 7.57.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 +5 -4
- package/src/sdk/startEntry.ts +31 -0
- package/src/sdk/workerEntry.test.ts +50 -0
- package/src/sdk/workerEntry.ts +14 -9
- package/src/vite/plugin.js +27 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/tanstack",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.57.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deco framework binding for TanStack Start + Cloudflare Workers",
|
|
6
6
|
"repository": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"./sdk/cookiePassthrough": "./src/sdk/cookiePassthrough.ts",
|
|
18
18
|
"./sdk/deferredSectionLoader": "./src/sdk/deferredSectionLoader.ts",
|
|
19
19
|
"./sdk/serverFnFetch": "./src/sdk/serverFnFetch.ts",
|
|
20
|
+
"./sdk/startEntry": "./src/sdk/startEntry.ts",
|
|
20
21
|
"./sdk/cdnSegment": "./src/sdk/cdnSegment.ts"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
@@ -26,9 +27,9 @@
|
|
|
26
27
|
"lint:unused": "knip"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"@decocms/blocks": "7.
|
|
30
|
-
"@decocms/blocks-admin": "7.
|
|
31
|
-
"@decocms/blocks-cli": "7.
|
|
30
|
+
"@decocms/blocks": "7.57.0",
|
|
31
|
+
"@decocms/blocks-admin": "7.57.0",
|
|
32
|
+
"@decocms/blocks-cli": "7.57.0",
|
|
32
33
|
"@deco-cx/warp-node": "^0.3.16",
|
|
33
34
|
"fast-json-patch": "^3.1.0",
|
|
34
35
|
"ws": "^8.18.0"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default TanStack Start entry, supplied by the framework when a site doesn't
|
|
3
|
+
* have its own `src/start.ts`.
|
|
4
|
+
*
|
|
5
|
+
* It exists so that CDN caching of `/_serverFn` is something a site gets from a
|
|
6
|
+
* version bump instead of a per-site PR. The only thing it wires is
|
|
7
|
+
* `decoServerFnFetch`, which appends the cache segment to server-function URLs
|
|
8
|
+
* — see `./cdnSegment` for why that is what makes the CDN key match the
|
|
9
|
+
* Worker's.
|
|
10
|
+
*
|
|
11
|
+
* A site that declares its own `src/start.ts` keeps it: `decoVitePlugin` only
|
|
12
|
+
* aliases this module in when that file is absent. Such a site opts into the
|
|
13
|
+
* CDN behaviour by composing `decoServerFnFetch` itself:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { decoServerFnFetch } from "@decocms/tanstack/sdk/serverFnFetch";
|
|
17
|
+
* export const startInstance = createStart(() => ({
|
|
18
|
+
* serverFns: { fetch: decoServerFnFetch },
|
|
19
|
+
* }));
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* The export name is load-bearing: `@tanstack/start-client-core`'s
|
|
23
|
+
* `hydrateStart` does `import { startInstance } from "#tanstack-start-entry"`.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { createStart } from "@tanstack/react-start";
|
|
27
|
+
import { decoServerFnFetch } from "./serverFnFetch";
|
|
28
|
+
|
|
29
|
+
export const startInstance = createStart(() => ({
|
|
30
|
+
serverFns: { fetch: decoServerFnFetch },
|
|
31
|
+
}));
|
|
@@ -838,6 +838,56 @@ describe('cdnCacheControl: "serverfn-segment"', () => {
|
|
|
838
838
|
});
|
|
839
839
|
});
|
|
840
840
|
|
|
841
|
+
describe("cdnCacheControl default", () => {
|
|
842
|
+
const BUILD_D = "abc123";
|
|
843
|
+
|
|
844
|
+
// The default flipped from "no-store" to "serverfn-segment". That is only
|
|
845
|
+
// safe because it is inert until a verified marker arrives — these two tests
|
|
846
|
+
// are what make that claim checkable rather than asserted in a comment.
|
|
847
|
+
it("is inert for a client that never sends a marker", async () => {
|
|
848
|
+
const w = createDecoWorkerEntry(MOCK_SERVER_ENTRY, {
|
|
849
|
+
observability: false,
|
|
850
|
+
buildSegment: () => ({ device: "desktop" as const }),
|
|
851
|
+
});
|
|
852
|
+
const html = await w.fetch(new Request("https://example.com/"), { BUILD_HASH: BUILD_D }, MOCK_CTX);
|
|
853
|
+
expect(html.headers.get("CDN-Cache-Control")).toBe("no-store");
|
|
854
|
+
|
|
855
|
+
const sfn = await w.fetch(
|
|
856
|
+
new Request("https://example.com/_serverFn/loadCmsPage"),
|
|
857
|
+
{ BUILD_HASH: BUILD_D },
|
|
858
|
+
MOCK_CTX,
|
|
859
|
+
);
|
|
860
|
+
expect(sfn.headers.get("CDN-Cache-Control")).toBe("no-store");
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
it("engages once the client sends a valid marker, with no site config", async () => {
|
|
864
|
+
const w = createDecoWorkerEntry(MOCK_SERVER_ENTRY, {
|
|
865
|
+
observability: false,
|
|
866
|
+
buildSegment: () => ({ device: "desktop" as const }),
|
|
867
|
+
});
|
|
868
|
+
const res = await w.fetch(
|
|
869
|
+
new Request(`https://example.com/_serverFn/loadCmsPage?__cseg=desktop.${BUILD_D}`),
|
|
870
|
+
{ BUILD_HASH: BUILD_D },
|
|
871
|
+
MOCK_CTX,
|
|
872
|
+
);
|
|
873
|
+
expect(res.headers.get("CDN-Cache-Control")).toMatch(/^public, max-age=\d+$/);
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
it('still honours an explicit opt-out with "no-store"', async () => {
|
|
877
|
+
const w = createDecoWorkerEntry(MOCK_SERVER_ENTRY, {
|
|
878
|
+
observability: false,
|
|
879
|
+
cdnCacheControl: "no-store",
|
|
880
|
+
buildSegment: () => ({ device: "desktop" as const }),
|
|
881
|
+
});
|
|
882
|
+
const res = await w.fetch(
|
|
883
|
+
new Request(`https://example.com/_serverFn/loadCmsPage?__cseg=desktop.${BUILD_D}`),
|
|
884
|
+
{ BUILD_HASH: BUILD_D },
|
|
885
|
+
MOCK_CTX,
|
|
886
|
+
);
|
|
887
|
+
expect(res.headers.get("CDN-Cache-Control")).toBe("no-store");
|
|
888
|
+
});
|
|
889
|
+
});
|
|
890
|
+
|
|
841
891
|
describe("CDN-Cache-Control at the single response exit", () => {
|
|
842
892
|
it("defaults to no-store on early returns that never reach dressResponse", async () => {
|
|
843
893
|
// `?asJson` returns the fully resolved page — loaders run with the caller's
|
package/src/sdk/workerEntry.ts
CHANGED
|
@@ -508,13 +508,18 @@ export interface DecoWorkerEntryOptions {
|
|
|
508
508
|
* desktop HTML to mobile, one region's to another, or a crawler's eager
|
|
509
509
|
* render to humans.
|
|
510
510
|
*
|
|
511
|
-
* - `"
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
*
|
|
511
|
+
* - `"serverfn-segment"` (default): allow CDN caching for `/_serverFn`
|
|
512
|
+
* requests whose URL carries a verified `__cseg` marker (see
|
|
513
|
+
* `./cdnSegment` and `decoServerFnFetch`). The marker makes the CDN's key
|
|
514
|
+
* equivalent to the Worker's. HTML documents keep `no-store` — the initial
|
|
515
|
+
* navigation is a browser request with no client hook to attach a marker.
|
|
516
|
+
*
|
|
517
|
+
* This is the default because it is inert until a marker actually arrives:
|
|
518
|
+
* a client that never sends `__cseg` keeps getting `no-store`, so enabling
|
|
519
|
+
* it cannot change behaviour on its own. That is what lets a site pick the
|
|
520
|
+
* feature up from a version bump rather than a per-site change.
|
|
521
|
+
* - `"no-store"`: the CDN never caches; every request invokes the Worker.
|
|
522
|
+
* Always correct, never fast. Set this to opt OUT.
|
|
518
523
|
* - `"match-profile"`: mirror the profile's `edge.fresh` as a CDN TTL. Sound
|
|
519
524
|
* ONLY when the cache key is the raw URL — no `buildSegment`,
|
|
520
525
|
* `deviceSpecificKeys: false`, `geoCacheKey: "off"`. Since
|
|
@@ -528,7 +533,7 @@ export interface DecoWorkerEntryOptions {
|
|
|
528
533
|
* whatever sits in front of the Worker has to reproduce the key above, and
|
|
529
534
|
* the initial navigation has no client hook to attach a marker to.
|
|
530
535
|
*
|
|
531
|
-
* @default "
|
|
536
|
+
* @default "serverfn-segment"
|
|
532
537
|
*/
|
|
533
538
|
cdnCacheControl?:
|
|
534
539
|
| "no-store"
|
|
@@ -995,7 +1000,7 @@ export function createDecoWorkerEntry(
|
|
|
995
1000
|
geoCacheKey: geoCacheKeyOpt = "auto",
|
|
996
1001
|
safeCookies: safeCookiesOpt = DEFAULT_SAFE_COOKIES,
|
|
997
1002
|
staticPaths: staticPathsOpt = DEFAULT_STATIC_PATHS,
|
|
998
|
-
cdnCacheControl: cdnCacheControlOpt = "
|
|
1003
|
+
cdnCacheControl: cdnCacheControlOpt = "serverfn-segment",
|
|
999
1004
|
observability: observabilityOpt,
|
|
1000
1005
|
outboundUserAgent: outboundUserAgentOpt,
|
|
1001
1006
|
speculationRules: speculationRulesOpt,
|
package/src/vite/plugin.js
CHANGED
|
@@ -690,6 +690,33 @@ export function decoVitePlugin() {
|
|
|
690
690
|
/** @type {import("vite").UserConfig} */
|
|
691
691
|
const cfg = {};
|
|
692
692
|
|
|
693
|
+
// Supply a default TanStack Start entry when the site has none.
|
|
694
|
+
//
|
|
695
|
+
// `#tanstack-start-entry` is a subpath import of
|
|
696
|
+
// @tanstack/start-client-core; with no `src/start.ts` it resolves to a
|
|
697
|
+
// fake entry exporting `startInstance = undefined`, and the site gets no
|
|
698
|
+
// `serverFns.fetch` hook. That hook is what appends the cache segment to
|
|
699
|
+
// `/_serverFn` URLs (see sdk/cdnSegment), so without it CDN caching of
|
|
700
|
+
// SPA navigation can never engage.
|
|
701
|
+
//
|
|
702
|
+
// Aliasing it here means a site gets that from a version bump instead of
|
|
703
|
+
// a per-site PR. Strictly conditional on the file being absent: a site
|
|
704
|
+
// that owns its `src/start.ts` must keep it, since ours would otherwise
|
|
705
|
+
// silently replace whatever else it configures.
|
|
706
|
+
const siteStartEntry = ["ts", "tsx", "js", "jsx"]
|
|
707
|
+
.map((ext) => path.join(process.cwd(), "src", `start.${ext}`))
|
|
708
|
+
.find((f) => existsSync(f));
|
|
709
|
+
|
|
710
|
+
if (!siteStartEntry) {
|
|
711
|
+
cfg.resolve = {
|
|
712
|
+
...cfg.resolve,
|
|
713
|
+
alias: {
|
|
714
|
+
...cfg.resolve?.alias,
|
|
715
|
+
"#tanstack-start-entry": "@decocms/tanstack/sdk/startEntry",
|
|
716
|
+
},
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
693
720
|
// Allow tunnel domains through Vite's host check.
|
|
694
721
|
// .deco.studio is the new admin frontend; both real-world Deco sites
|
|
695
722
|
// (casaevideo-storefront, baggagio-tanstack) duplicated this list to
|