@decocms/tanstack 7.55.0 → 7.55.2
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/tanstack",
|
|
3
|
-
"version": "7.55.
|
|
3
|
+
"version": "7.55.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deco framework binding for TanStack Start + Cloudflare Workers",
|
|
6
6
|
"repository": {
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"lint:unused": "knip"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@decocms/blocks": "7.55.
|
|
28
|
-
"@decocms/blocks-admin": "7.55.
|
|
29
|
-
"@decocms/blocks-cli": "7.55.
|
|
27
|
+
"@decocms/blocks": "7.55.2",
|
|
28
|
+
"@decocms/blocks-admin": "7.55.2",
|
|
29
|
+
"@decocms/blocks-cli": "7.55.2",
|
|
30
30
|
"@deco-cx/warp-node": "^0.3.16",
|
|
31
31
|
"fast-json-patch": "^3.1.0",
|
|
32
32
|
"ws": "^8.18.0"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { useRouter } from "@tanstack/react-router";
|
|
3
|
+
import { renderToString } from "react-dom/server";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
import PreviewProviders from "./PreviewProviders";
|
|
7
|
+
|
|
8
|
+
// A section that reads React Query at render time — the exact shape that made
|
|
9
|
+
// the /live/previews in-place render throw "No QueryClient set" for commerce
|
|
10
|
+
// sections (e.g. Carousel.tsx) before PreviewProviders provided a client.
|
|
11
|
+
function SectionUsingQuery() {
|
|
12
|
+
const { data } = useQuery({ queryKey: ["preview-probe"], queryFn: () => "loaded" });
|
|
13
|
+
return <div data-testid="section">{data ?? "loading"}</div>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function SectionUsingRouter() {
|
|
17
|
+
const router = useRouter();
|
|
18
|
+
return <div data-testid="router">{router ? "has-router" : "no-router"}</div>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe("PreviewProviders", () => {
|
|
22
|
+
it("renders a section that calls useQuery without throwing", () => {
|
|
23
|
+
const html = renderToString(
|
|
24
|
+
<PreviewProviders>
|
|
25
|
+
<SectionUsingQuery />
|
|
26
|
+
</PreviewProviders>,
|
|
27
|
+
);
|
|
28
|
+
// No QueryClient error, and the section renders its pending state (static
|
|
29
|
+
// preview render — the query never resolves during renderToString).
|
|
30
|
+
expect(html).toContain("loading");
|
|
31
|
+
expect(html).not.toContain("No QueryClient");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("still provides the TanStack Router context", () => {
|
|
35
|
+
const html = renderToString(
|
|
36
|
+
<PreviewProviders>
|
|
37
|
+
<SectionUsingRouter />
|
|
38
|
+
</PreviewProviders>,
|
|
39
|
+
);
|
|
40
|
+
expect(html).toContain("has-router");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
1
2
|
import {
|
|
2
3
|
createMemoryHistory,
|
|
3
4
|
createRootRoute,
|
|
@@ -16,11 +17,29 @@ const previewRouter = createRouter({
|
|
|
16
17
|
history: createMemoryHistory({ initialEntries: ["/"] }),
|
|
17
18
|
});
|
|
18
19
|
|
|
20
|
+
// A dedicated QueryClient for preview renders. Sections that call useQuery /
|
|
21
|
+
// useQueryClient at render time (e.g. commerce shelves, carousels) would
|
|
22
|
+
// otherwise throw "No QueryClient set" during the admin's isolated
|
|
23
|
+
// renderToString pass — the site's production QueryClientProvider (wired via
|
|
24
|
+
// createDecoRouter's `Wrap`) is not in scope on the /live/previews path.
|
|
25
|
+
// Retries are disabled so a preview render never hangs on a failing query;
|
|
26
|
+
// this is a static content render (matches __decoFBT=0), so cached data is
|
|
27
|
+
// not expected here.
|
|
28
|
+
const previewQueryClient = new QueryClient({
|
|
29
|
+
defaultOptions: { queries: { retry: false } },
|
|
30
|
+
});
|
|
31
|
+
|
|
19
32
|
/**
|
|
20
33
|
* Default preview wrapper for admin iframe rendering.
|
|
21
34
|
* Provides a TanStack Router context with memory history so components
|
|
22
|
-
* that depend on router hooks (Link, useNavigate, etc.) work in previews
|
|
35
|
+
* that depend on router hooks (Link, useNavigate, etc.) work in previews,
|
|
36
|
+
* plus a QueryClientProvider so components that call React Query hooks at
|
|
37
|
+
* render time don't crash the preview.
|
|
23
38
|
*/
|
|
24
39
|
export default function PreviewProviders({ children }: { children: ReactNode }) {
|
|
25
|
-
return
|
|
40
|
+
return (
|
|
41
|
+
<QueryClientProvider client={previewQueryClient}>
|
|
42
|
+
<RouterContextProvider router={previewRouter as any}>{children}</RouterContextProvider>
|
|
43
|
+
</QueryClientProvider>
|
|
44
|
+
);
|
|
26
45
|
}
|