@decocms/tanstack 8.16.0 → 8.16.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.
@@ -1 +1 @@
1
- {"version":3,"file":"StudioRefresh.d.ts","sourceRoot":"","sources":["../../src/react/StudioRefresh.ts"],"names":[],"mappings":"AAyBA,wBAAgB,aAAa,IAAI,IAAI,CAwCpC"}
1
+ {"version":3,"file":"StudioRefresh.d.ts","sourceRoot":"","sources":["../../src/react/StudioRefresh.ts"],"names":[],"mappings":"AAsDA,wBAAgB,aAAa,IAAI,IAAI,CA0CpC"}
@@ -13,6 +13,13 @@
13
13
  * loads again on that move; only the matches it didn't load are invalidated,
14
14
  * so the page renders the save once.
15
15
  *
16
+ * The page keeps its scroll position. After every load the router restores
17
+ * the position saved for the URL or scrolls to the top, and `invalidate()`
18
+ * takes no `resetScroll`, so an editor working on the footer was sent back
19
+ * up on every save. While a refresh runs, `scrollRestoration` is a function
20
+ * that answers `false`, which the router reads as "leave the scroll alone";
21
+ * the site's own setting is back two frames after the last render.
22
+ *
16
23
  * Set on every page, framed or not: Studio's module is the only caller, and
17
24
  * comparing the window with its parent here is what a test runner's
18
25
  * frame-busting rewrite matches (`tests/studio-shortcut.test.ts`).
@@ -20,10 +27,32 @@
20
27
  import { useRouter } from "@tanstack/react-router";
21
28
  import { useEffect } from "react";
22
29
  import { STUDIO_PAGE_REFRESH } from "../studio.js";
30
+ const nextFrame = () => new Promise((resolve) => requestAnimationFrame(() => resolve()));
31
+ /** Runs `work` with the router's scroll restoration off; overlapping calls share one override. */
32
+ function keepScroll(router) {
33
+ let depth = 0;
34
+ let saved;
35
+ return async (work) => {
36
+ if (depth++ === 0) {
37
+ saved = router.options.scrollRestoration;
38
+ router.options.scrollRestoration = () => false;
39
+ }
40
+ try {
41
+ return await work();
42
+ }
43
+ finally {
44
+ await nextFrame();
45
+ await nextFrame();
46
+ if (--depth === 0)
47
+ router.options.scrollRestoration = saved;
48
+ }
49
+ };
50
+ }
23
51
  export function StudioRefresh() {
24
52
  const router = useRouter();
25
53
  useEffect(() => {
26
- const refresh = async (url) => {
54
+ const inPlace = keepScroll(router);
55
+ const show = async (url) => {
27
56
  const target = new URL(url, location.href);
28
57
  if (target.origin !== location.origin) {
29
58
  throw new Error(`Not this page's origin: ${target.origin}`);
@@ -54,6 +83,7 @@ export function StudioRefresh() {
54
83
  const ids = new Set(stale.map((m) => m.id));
55
84
  await router.invalidate({ filter: (m) => ids.has(m.id) });
56
85
  };
86
+ const refresh = (url) => inPlace(() => show(url));
57
87
  const slot = window;
58
88
  slot[STUDIO_PAGE_REFRESH] = refresh;
59
89
  return () => {
@@ -1 +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,MA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
95
  },
96
96
  "devDependencies": {
97
- "@decocms/blocks": "8.16.0",
97
+ "@decocms/blocks": "8.16.1",
98
98
  "@tanstack/react-router": "1.170.39",
99
99
  "@tanstack/react-start": "1.168.58",
100
100
  "@types/react": "^19.0.0",
@@ -13,6 +13,13 @@
13
13
  * loads again on that move; only the matches it didn't load are invalidated,
14
14
  * so the page renders the save once.
15
15
  *
16
+ * The page keeps its scroll position. After every load the router restores
17
+ * the position saved for the URL or scrolls to the top, and `invalidate()`
18
+ * takes no `resetScroll`, so an editor working on the footer was sent back
19
+ * up on every save. While a refresh runs, `scrollRestoration` is a function
20
+ * that answers `false`, which the router reads as "leave the scroll alone";
21
+ * the site's own setting is back two frames after the last render.
22
+ *
16
23
  * Set on every page, framed or not: Studio's module is the only caller, and
17
24
  * comparing the window with its parent here is what a test runner's
18
25
  * frame-busting rewrite matches (`tests/studio-shortcut.test.ts`).
@@ -22,12 +29,35 @@ import { useEffect } from "react";
22
29
  import { STUDIO_PAGE_REFRESH } from "../studio.ts";
23
30
 
24
31
  type StudioPageRefresh = (url: string) => Promise<void>;
32
+ type Router = ReturnType<typeof useRouter>;
33
+
34
+ const nextFrame = () => new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
35
+
36
+ /** Runs `work` with the router's scroll restoration off; overlapping calls share one override. */
37
+ function keepScroll(router: Router) {
38
+ let depth = 0;
39
+ let saved: Router["options"]["scrollRestoration"];
40
+ return async <T>(work: () => Promise<T>): Promise<T> => {
41
+ if (depth++ === 0) {
42
+ saved = router.options.scrollRestoration;
43
+ router.options.scrollRestoration = () => false;
44
+ }
45
+ try {
46
+ return await work();
47
+ } finally {
48
+ await nextFrame();
49
+ await nextFrame();
50
+ if (--depth === 0) router.options.scrollRestoration = saved;
51
+ }
52
+ };
53
+ }
25
54
 
26
55
  export function StudioRefresh(): null {
27
56
  const router = useRouter();
28
57
 
29
58
  useEffect(() => {
30
- const refresh: StudioPageRefresh = async (url) => {
59
+ const inPlace = keepScroll(router);
60
+ const show = async (url: string) => {
31
61
  const target = new URL(url, location.href);
32
62
  if (target.origin !== location.origin) {
33
63
  throw new Error(`Not this page's origin: ${target.origin}`);
@@ -55,6 +85,7 @@ export function StudioRefresh(): null {
55
85
  const ids = new Set(stale.map((m) => m.id));
56
86
  await router.invalidate({ filter: (m) => ids.has(m.id) });
57
87
  };
88
+ const refresh: StudioPageRefresh = (url) => inPlace(() => show(url));
58
89
  const slot = window as unknown as Record<string, unknown>;
59
90
  slot[STUDIO_PAGE_REFRESH] = refresh;
60
91
  return () => {