@decocms/tanstack 8.15.0 → 8.16.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/dist/react/DecoDocument.d.ts.map +1 -1
- package/dist/react/DecoDocument.js +5 -1
- package/dist/react/DecoDocument.js.map +1 -1
- package/dist/react/StudioRefresh.d.ts +2 -0
- package/dist/react/StudioRefresh.d.ts.map +1 -0
- package/dist/react/StudioRefresh.js +66 -0
- package/dist/react/StudioRefresh.js.map +1 -0
- package/dist/studio.d.ts +5 -0
- package/dist/studio.d.ts.map +1 -1
- package/dist/studio.js +5 -0
- package/dist/studio.js.map +1 -1
- package/package.json +2 -2
- package/src/react/DecoDocument.tsx +5 -0
- package/src/react/StudioRefresh.ts +66 -0
- package/src/studio.ts +6 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecoDocument.d.ts","sourceRoot":"","sources":["../../src/react/DecoDocument.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DecoDocument.d.ts","sourceRoot":"","sources":["../../src/react/DecoDocument.tsx"],"names":[],"mappings":"AAgCA,OAAO,EAAE,KAAK,SAAS,EAA+B,MAAM,OAAO,CAAC;AAOpE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB;CACF;AAED,MAAM,WAAW,uBAAuB;IACtC,2FAA2F;IAC3F,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,EACjC,KAAsD,GACvD,EAAE,uBAAuB,sCAmBzB;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,gCAa3B;AAqDD,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,gBAAgB,+BAsBzF;AAED,MAAM,WAAW,iBAAiB;IAChC,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0GAA0G;IAC1G,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACxB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,IAAW,EACX,aAA+C,EAC/C,OAAY,EACZ,UAAgB,EAChB,MAAe,EACf,YAAY,EACZ,KAAK,EACL,aAAa,EACb,QAAQ,GACT,EAAE,iBAAiB,+BA8CnB"}
|
|
@@ -16,6 +16,9 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
16
16
|
* (only on a draft page outside Studio's frame), from
|
|
17
17
|
* `@decocms/blocks/preview`. The worker adds the same origins to the
|
|
18
18
|
* page's CSP `script-src` and `frame-ancestors`;
|
|
19
|
+
* - `StudioRefresh`: after a save, Studio shows the new content by rerunning
|
|
20
|
+
* the loaders (`router.invalidate()`), with React still attached, instead
|
|
21
|
+
* of replacing the document;
|
|
19
22
|
* - v7's "." edit shortcut (`../studioShortcut.ts`: outside Studio's frame,
|
|
20
23
|
* "." opens the page in Studio's editor, with the page's `pathTemplate`
|
|
21
24
|
* from the route's loader data). v8 only: v7's framed handler
|
|
@@ -32,6 +35,7 @@ import { useEffect, useRef, useState } from "react";
|
|
|
32
35
|
import { studioOrigins } from "../studio.js";
|
|
33
36
|
import { StudioShortcut } from "../studioShortcut.js";
|
|
34
37
|
import { pageValues, publishScript } from "./pageValues.js";
|
|
38
|
+
import { StudioRefresh } from "./StudioRefresh.js";
|
|
35
39
|
import { DATA_EVENT_OBSERVER, eventsBootstrap, PROGRESS_CSS } from "./scripts.js";
|
|
36
40
|
/** A loading bar at the top of the page during client-side navigation. */
|
|
37
41
|
export function NavigationProgress({ color = "var(--color-brand-primary-500, currentColor)", }) {
|
|
@@ -76,7 +80,7 @@ function StudioPieces({ site, editShortcut, nonce, studioOrigins: origins, draft
|
|
|
76
80
|
// Two primitives, so a navigation that keeps the page doesn't re-render the document.
|
|
77
81
|
const pathTemplate = useRouterState({ select: (s) => studioPageOf(s.matches)?.pathTemplate });
|
|
78
82
|
const pageId = useRouterState({ select: (s) => studioPageOf(s.matches)?.id });
|
|
79
|
-
return (_jsxs(_Fragment, { children: [_jsx(StudioShortcut, { site: site, editShortcut: editShortcut, page: { pathTemplate, id: pageId }, nonce: nonce }), _jsx(StudioChannel, { studioOrigins: studioOrigins(origins), nonce: nonce }), _jsx(DraftBadge, { pointer: draft ?? null, unavailable: draftUnavailable })] }));
|
|
83
|
+
return (_jsxs(_Fragment, { children: [_jsx(StudioShortcut, { site: site, editShortcut: editShortcut, page: { pathTemplate, id: pageId }, nonce: nonce }), _jsx(StudioChannel, { studioOrigins: studioOrigins(origins), nonce: nonce }), _jsx(StudioRefresh, {}), _jsx(DraftBadge, { pointer: draft ?? null, unavailable: draftUnavailable })] }));
|
|
80
84
|
}
|
|
81
85
|
/**
|
|
82
86
|
* What `DecoDocument` mounts for Studio and draft previews, for a site that
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecoDocument.js","sourceRoot":"","sources":["../../src/react/DecoDocument.tsx"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"DecoDocument.js","sourceRoot":"","sources":["../../src/react/DecoDocument.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,EAAkB,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAalF,0EAA0E;AAC1E,MAAM,UAAU,kBAAkB,CAAC,EACjC,KAAK,GAAG,8CAA8C,GAC9B;IACxB,MAAM,SAAS,GAAG,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;IACjE,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAC5B,OAAO,CACL,eACE,SAAS,EAAC,yDAAyD,EACnE,KAAK,EAAE,EAAE,KAAK,EAAE,EAChB,IAAI,EAAC,aAAa,gBACP,wBAAmB,aAE9B,gBAAO,uBAAuB,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAI,EAE5D,cAAK,SAAS,E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AC3D,2BACE,KAAC,WAAW,KAAG,EACd,OAAO,IAAI,CACV,iBACE,KAAK,EAAE,KAAK,EACZ,wBAAwB,QACxB,uBAAuB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,GAC5C,CACH,IACI,EACP,gBAAM,SAAS,EAAE,aAAa,EAAE,wBAAwB,mBACtD,KAAC,UAAU,cAAE,eAAe,CAAC,OAAO,CAAC,GAAc,EACnD,KAAC,kBAAkB,KAAG,EACtB,KAAC,KAAK,cACJ,KAAC,YAAY,KAAG,GACV,EACP,QAAQ,EACT,KAAC,YAAY,IACX,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,GACzC,EACF,KAAC,UAAU,cAAE,mBAAmB,GAAc,EAC9C,KAAC,OAAO,KAAG,IACN,IACF,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StudioRefresh.d.ts","sourceRoot":"","sources":["../../src/react/StudioRefresh.ts"],"names":[],"mappings":"AAyBA,wBAAgB,aAAa,IAAI,IAAI,CAwCpC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's own refresh for Studio's HTML swap (`STUDIO_PAGE_REFRESH` of
|
|
3
|
+
* `@decocms/blocks/protocol`): after a save, Studio asks the page to show its
|
|
4
|
+
* new content. Replacing the document would leave React holding the old nodes,
|
|
5
|
+
* so every client component would stop at its server markup. Here the router
|
|
6
|
+
* does it instead and stays attached: `router.invalidate()` reruns the loaders
|
|
7
|
+
* and resolves once the page shows their data.
|
|
8
|
+
*
|
|
9
|
+
* A new URL of the page (a save moved the draft pointer in `?__draft=`) first
|
|
10
|
+
* goes to the worker as a document request, only for its draft cookie: the
|
|
11
|
+
* loaders' server-function calls carry the cookie, not the page's query. Then
|
|
12
|
+
* the router moves to the URL. A route whose loader deps include `__draft`
|
|
13
|
+
* loads again on that move; only the matches it didn't load are invalidated,
|
|
14
|
+
* so the page renders the save once.
|
|
15
|
+
*
|
|
16
|
+
* Set on every page, framed or not: Studio's module is the only caller, and
|
|
17
|
+
* comparing the window with its parent here is what a test runner's
|
|
18
|
+
* frame-busting rewrite matches (`tests/studio-shortcut.test.ts`).
|
|
19
|
+
*/
|
|
20
|
+
import { useRouter } from "@tanstack/react-router";
|
|
21
|
+
import { useEffect } from "react";
|
|
22
|
+
import { STUDIO_PAGE_REFRESH } from "../studio.js";
|
|
23
|
+
export function StudioRefresh() {
|
|
24
|
+
const router = useRouter();
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const refresh = async (url) => {
|
|
27
|
+
const target = new URL(url, location.href);
|
|
28
|
+
if (target.origin !== location.origin) {
|
|
29
|
+
throw new Error(`Not this page's origin: ${target.origin}`);
|
|
30
|
+
}
|
|
31
|
+
let loadedSince = null;
|
|
32
|
+
if (target.href !== location.href) {
|
|
33
|
+
const res = await fetch(target.href, {
|
|
34
|
+
headers: { accept: "text/html" },
|
|
35
|
+
credentials: "same-origin",
|
|
36
|
+
cache: "no-store",
|
|
37
|
+
});
|
|
38
|
+
await res.body?.cancel();
|
|
39
|
+
if (!res.ok)
|
|
40
|
+
throw new Error(`The page answered ${res.status}`);
|
|
41
|
+
loadedSince = Date.now();
|
|
42
|
+
await router.navigate({
|
|
43
|
+
href: `${target.pathname}${target.search}${target.hash}`,
|
|
44
|
+
replace: true,
|
|
45
|
+
resetScroll: false,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (loadedSince === null)
|
|
49
|
+
return router.invalidate();
|
|
50
|
+
const since = loadedSince;
|
|
51
|
+
const stale = router.state.matches.filter((m) => m.updatedAt < since);
|
|
52
|
+
if (stale.length === 0)
|
|
53
|
+
return;
|
|
54
|
+
const ids = new Set(stale.map((m) => m.id));
|
|
55
|
+
await router.invalidate({ filter: (m) => ids.has(m.id) });
|
|
56
|
+
};
|
|
57
|
+
const slot = window;
|
|
58
|
+
slot[STUDIO_PAGE_REFRESH] = refresh;
|
|
59
|
+
return () => {
|
|
60
|
+
if (slot[STUDIO_PAGE_REFRESH] === refresh)
|
|
61
|
+
delete slot[STUDIO_PAGE_REFRESH];
|
|
62
|
+
};
|
|
63
|
+
}, [router]);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=StudioRefresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StudioRefresh.js","sourceRoot":"","sources":["../../src/react/StudioRefresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAInD,MAAM,UAAU,aAAa;IAC3B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAsB,KAAK,EAAE,GAAG,EAAE,EAAE;YAC/C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;gBACtC,MAAM,IAAI,KAAK,CAAC,2BAA2B,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;YAC9D,CAAC;YACD,IAAI,WAAW,GAAkB,IAAI,CAAC;YACtC,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAClC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE;oBACnC,OAAO,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE;oBAChC,WAAW,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,CAAC,mBAAmB,CAAC,KAAK,OAAO;gBAAE,OAAO,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC9E,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/studio.d.ts
CHANGED
|
@@ -26,6 +26,11 @@ export declare const STUDIO_ORIGIN = "https://studio.decocms.com";
|
|
|
26
26
|
* staging origins. No wildcard: each one is compared exactly.
|
|
27
27
|
*/
|
|
28
28
|
export declare const DEFAULT_STUDIO_ORIGINS: readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
* Where `StudioRefresh` puts the page's own refresh for Studio's HTML swap
|
|
31
|
+
* (`STUDIO_PAGE_REFRESH` of `@decocms/blocks/protocol`, held equal by a test).
|
|
32
|
+
*/
|
|
33
|
+
export declare const STUDIO_PAGE_REFRESH = "__decoStudioRefresh";
|
|
29
34
|
/**
|
|
30
35
|
* The Studio origins the page trusts: the Studio channel accepts messages and
|
|
31
36
|
* modules from them, and the binding adds them to the page's CSP `script-src`
|
package/dist/studio.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../src/studio.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAK1C,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAIlD,CAAC;AAEH,kCAAkC;AAClC,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAGlD,CAAC;
|
|
1
|
+
{"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../src/studio.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAK1C,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAIlD,CAAC;AAEH,kCAAkC;AAClC,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAGlD,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAkBzD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE,CAK3E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAazE"}
|
package/dist/studio.js
CHANGED
|
@@ -38,6 +38,11 @@ export const DEFAULT_STUDIO_ORIGINS = Object.freeze([
|
|
|
38
38
|
STUDIO_ORIGIN,
|
|
39
39
|
"https://studio-stg.decocms.com",
|
|
40
40
|
]);
|
|
41
|
+
/**
|
|
42
|
+
* Where `StudioRefresh` puts the page's own refresh for Studio's HTML swap
|
|
43
|
+
* (`STUDIO_PAGE_REFRESH` of `@decocms/blocks/protocol`, held equal by a test).
|
|
44
|
+
*/
|
|
45
|
+
export const STUDIO_PAGE_REFRESH = "__decoStudioRefresh";
|
|
41
46
|
/** `value` as an exact http(s) origin (`https://host[:port]`, a trailing `/` dropped; no wildcard), or `""`. */
|
|
42
47
|
function asOrigin(value) {
|
|
43
48
|
if (typeof value !== "string")
|
package/dist/studio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studio.js","sourceRoot":"","sources":["../src/studio.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB,MAAM,CAAC,MAAM,CAAC;IAC7D,4BAA4B;IAC5B,gCAAgC;IAChC,qBAAqB;IACrB,uBA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K,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC;IAC/E,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAAiC;IAC9D,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IAC9D,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IACD,8EAA8E;IAC9E,yBAAyB;IACzB,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IACxF,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC;IAC1B,OAAO,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;AACjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/tanstack",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.16.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24"
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
|
-
"@decocms/blocks": "8.
|
|
97
|
+
"@decocms/blocks": "8.16.0",
|
|
98
98
|
"@tanstack/react-router": "1.170.39",
|
|
99
99
|
"@tanstack/react-start": "1.168.58",
|
|
100
100
|
"@types/react": "^19.0.0",
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
* (only on a draft page outside Studio's frame), from
|
|
16
16
|
* `@decocms/blocks/preview`. The worker adds the same origins to the
|
|
17
17
|
* page's CSP `script-src` and `frame-ancestors`;
|
|
18
|
+
* - `StudioRefresh`: after a save, Studio shows the new content by rerunning
|
|
19
|
+
* the loaders (`router.invalidate()`), with React still attached, instead
|
|
20
|
+
* of replacing the document;
|
|
18
21
|
* - v7's "." edit shortcut (`../studioShortcut.ts`: outside Studio's frame,
|
|
19
22
|
* "." opens the page in Studio's editor, with the page's `pathTemplate`
|
|
20
23
|
* from the route's loader data). v8 only: v7's framed handler
|
|
@@ -31,6 +34,7 @@ import { type ReactNode, useEffect, useRef, useState } from "react";
|
|
|
31
34
|
import { studioOrigins } from "../studio.ts";
|
|
32
35
|
import { StudioShortcut } from "../studioShortcut.ts";
|
|
33
36
|
import { pageValues, publishScript } from "./pageValues.ts";
|
|
37
|
+
import { StudioRefresh } from "./StudioRefresh.ts";
|
|
34
38
|
import { DATA_EVENT_OBSERVER, eventsBootstrap, PROGRESS_CSS } from "./scripts.ts";
|
|
35
39
|
|
|
36
40
|
declare global {
|
|
@@ -129,6 +133,7 @@ function StudioPieces({
|
|
|
129
133
|
nonce={nonce}
|
|
130
134
|
/>
|
|
131
135
|
<StudioChannel studioOrigins={studioOrigins(origins)} nonce={nonce} />
|
|
136
|
+
<StudioRefresh />
|
|
132
137
|
<DraftBadge pointer={draft ?? null} unavailable={draftUnavailable} />
|
|
133
138
|
</>
|
|
134
139
|
);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's own refresh for Studio's HTML swap (`STUDIO_PAGE_REFRESH` of
|
|
3
|
+
* `@decocms/blocks/protocol`): after a save, Studio asks the page to show its
|
|
4
|
+
* new content. Replacing the document would leave React holding the old nodes,
|
|
5
|
+
* so every client component would stop at its server markup. Here the router
|
|
6
|
+
* does it instead and stays attached: `router.invalidate()` reruns the loaders
|
|
7
|
+
* and resolves once the page shows their data.
|
|
8
|
+
*
|
|
9
|
+
* A new URL of the page (a save moved the draft pointer in `?__draft=`) first
|
|
10
|
+
* goes to the worker as a document request, only for its draft cookie: the
|
|
11
|
+
* loaders' server-function calls carry the cookie, not the page's query. Then
|
|
12
|
+
* the router moves to the URL. A route whose loader deps include `__draft`
|
|
13
|
+
* loads again on that move; only the matches it didn't load are invalidated,
|
|
14
|
+
* so the page renders the save once.
|
|
15
|
+
*
|
|
16
|
+
* Set on every page, framed or not: Studio's module is the only caller, and
|
|
17
|
+
* comparing the window with its parent here is what a test runner's
|
|
18
|
+
* frame-busting rewrite matches (`tests/studio-shortcut.test.ts`).
|
|
19
|
+
*/
|
|
20
|
+
import { useRouter } from "@tanstack/react-router";
|
|
21
|
+
import { useEffect } from "react";
|
|
22
|
+
import { STUDIO_PAGE_REFRESH } from "../studio.ts";
|
|
23
|
+
|
|
24
|
+
type StudioPageRefresh = (url: string) => Promise<void>;
|
|
25
|
+
|
|
26
|
+
export function StudioRefresh(): null {
|
|
27
|
+
const router = useRouter();
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const refresh: StudioPageRefresh = async (url) => {
|
|
31
|
+
const target = new URL(url, location.href);
|
|
32
|
+
if (target.origin !== location.origin) {
|
|
33
|
+
throw new Error(`Not this page's origin: ${target.origin}`);
|
|
34
|
+
}
|
|
35
|
+
let loadedSince: number | null = null;
|
|
36
|
+
if (target.href !== location.href) {
|
|
37
|
+
const res = await fetch(target.href, {
|
|
38
|
+
headers: { accept: "text/html" },
|
|
39
|
+
credentials: "same-origin",
|
|
40
|
+
cache: "no-store",
|
|
41
|
+
});
|
|
42
|
+
await res.body?.cancel();
|
|
43
|
+
if (!res.ok) throw new Error(`The page answered ${res.status}`);
|
|
44
|
+
loadedSince = Date.now();
|
|
45
|
+
await router.navigate({
|
|
46
|
+
href: `${target.pathname}${target.search}${target.hash}`,
|
|
47
|
+
replace: true,
|
|
48
|
+
resetScroll: false,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (loadedSince === null) return router.invalidate();
|
|
52
|
+
const since = loadedSince;
|
|
53
|
+
const stale = router.state.matches.filter((m) => m.updatedAt < since);
|
|
54
|
+
if (stale.length === 0) return;
|
|
55
|
+
const ids = new Set(stale.map((m) => m.id));
|
|
56
|
+
await router.invalidate({ filter: (m) => ids.has(m.id) });
|
|
57
|
+
};
|
|
58
|
+
const slot = window as unknown as Record<string, unknown>;
|
|
59
|
+
slot[STUDIO_PAGE_REFRESH] = refresh;
|
|
60
|
+
return () => {
|
|
61
|
+
if (slot[STUDIO_PAGE_REFRESH] === refresh) delete slot[STUDIO_PAGE_REFRESH];
|
|
62
|
+
};
|
|
63
|
+
}, [router]);
|
|
64
|
+
|
|
65
|
+
return null;
|
|
66
|
+
}
|
package/src/studio.ts
CHANGED
|
@@ -43,6 +43,12 @@ export const DEFAULT_STUDIO_ORIGINS: readonly string[] = Object.freeze([
|
|
|
43
43
|
"https://studio-stg.decocms.com",
|
|
44
44
|
]);
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Where `StudioRefresh` puts the page's own refresh for Studio's HTML swap
|
|
48
|
+
* (`STUDIO_PAGE_REFRESH` of `@decocms/blocks/protocol`, held equal by a test).
|
|
49
|
+
*/
|
|
50
|
+
export const STUDIO_PAGE_REFRESH = "__decoStudioRefresh";
|
|
51
|
+
|
|
46
52
|
/** `value` as an exact http(s) origin (`https://host[:port]`, a trailing `/` dropped; no wildcard), or `""`. */
|
|
47
53
|
function asOrigin(value: unknown): string {
|
|
48
54
|
if (typeof value !== "string") return "";
|