@decocms/tanstack 7.54.0 → 7.55.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/tanstack",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.55.1",
|
|
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.
|
|
28
|
-
"@decocms/blocks-admin": "7.
|
|
29
|
-
"@decocms/blocks-cli": "7.
|
|
27
|
+
"@decocms/blocks": "7.55.1",
|
|
28
|
+
"@decocms/blocks-admin": "7.55.1",
|
|
29
|
+
"@decocms/blocks-cli": "7.55.1",
|
|
30
30
|
"@deco-cx/warp-node": "^0.3.16",
|
|
31
31
|
"fast-json-patch": "^3.1.0",
|
|
32
32
|
"ws": "^8.18.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, type ReactNode } from "react";
|
|
2
2
|
import { HeadContent, Scripts, ScriptOnce, useRouterState } from "@tanstack/react-router";
|
|
3
|
-
import { LiveControls } from "@decocms/blocks/hooks";
|
|
3
|
+
import { LiveControls, Stats } from "@decocms/blocks/hooks";
|
|
4
4
|
import {
|
|
5
5
|
ANALYTICS_SCRIPT,
|
|
6
6
|
SPECULATION_DEV_WARN_SCRIPT,
|
|
@@ -161,6 +161,20 @@ export function DecoRootLayout({
|
|
|
161
161
|
</head>
|
|
162
162
|
<body className={bodyClassName} suppressHydrationWarning>
|
|
163
163
|
<ScriptOnce children={buildDecoEventsBootstrap(account)} />
|
|
164
|
+
{/*
|
|
165
|
+
* AFTER the bootstrap above, and in the body rather than the head. The collector's
|
|
166
|
+
* deco module subscribes with `window?.DECO?.events?.subscribe?.(…)` — once,
|
|
167
|
+
* optional-chained, with no retry. In the head it is an `async` script the parser
|
|
168
|
+
* can reach and run before the inline bootstrap below it has defined
|
|
169
|
+
* `DECO.events`, and the subscription would simply not happen: pageviews would
|
|
170
|
+
* still flow while every commerce event went nowhere, with no error. Here the
|
|
171
|
+
* parser has already executed the bootstrap.
|
|
172
|
+
*
|
|
173
|
+
* Rendering unconditionally is safe — the component returns null unless
|
|
174
|
+
* DECO_ANALYTICS_ENABLED is exactly "true", which is what makes this an env-var
|
|
175
|
+
* change for a site instead of a code change.
|
|
176
|
+
*/}
|
|
177
|
+
<Stats />
|
|
164
178
|
<NavigationProgress />
|
|
165
179
|
<main>
|
|
166
180
|
<StableOutlet />
|
|
@@ -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
|
}
|