@decocms/blocks 7.12.0 → 7.12.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 +1 -1
- package/src/cms/resolve.test.ts +52 -0
package/package.json
CHANGED
package/src/cms/resolve.test.ts
CHANGED
|
@@ -17,6 +17,7 @@ vi.mock("./loader", () => ({
|
|
|
17
17
|
|
|
18
18
|
vi.mock("./registry", () => ({
|
|
19
19
|
getSection: vi.fn(),
|
|
20
|
+
getOnBeforeResolveProps: vi.fn(),
|
|
20
21
|
}));
|
|
21
22
|
|
|
22
23
|
import {
|
|
@@ -28,6 +29,7 @@ import {
|
|
|
28
29
|
registerEagerSections,
|
|
29
30
|
registerNeverDeferSections,
|
|
30
31
|
resolveDeferredSectionFull,
|
|
32
|
+
resolveDecoPage,
|
|
31
33
|
resolvePageSeoBlock,
|
|
32
34
|
resolveSectionsList,
|
|
33
35
|
resolveValue,
|
|
@@ -37,6 +39,8 @@ import {
|
|
|
37
39
|
} from "./resolve";
|
|
38
40
|
import { runSingleSectionLoader } from "./sectionLoaders";
|
|
39
41
|
import { normalizeUrlsInObject } from "../sdk/normalizeUrls";
|
|
42
|
+
import { findPageByPath } from "./loader";
|
|
43
|
+
import { getSection } from "./registry";
|
|
40
44
|
import type { AsyncRenderingConfig, DeferredSection } from "./resolve";
|
|
41
45
|
|
|
42
46
|
describe("resolveDeferredSectionFull", () => {
|
|
@@ -586,3 +590,51 @@ describe("resolvePageSeoBlock — bot-aware commerce SEO", () => {
|
|
|
586
590
|
expect(res?.props?.jsonLD).toMatchObject({ seo: { title: "Rich SEO title" } });
|
|
587
591
|
});
|
|
588
592
|
});
|
|
593
|
+
|
|
594
|
+
// ---------------------------------------------------------------------------
|
|
595
|
+
// resolveDecoPage — #277 client-side navigation disables deferral
|
|
596
|
+
// ---------------------------------------------------------------------------
|
|
597
|
+
//
|
|
598
|
+
// When isClientNavigation is true, resolveDecoPageImpl sets useAsync = false so
|
|
599
|
+
// shouldDeferSection is never called. All sections — including CMS ⚡-wrapped
|
|
600
|
+
// ones — are resolved eagerly. This prevents client-nav from returning a
|
|
601
|
+
// deferredSections array that loadDeferredSection would then try to resolve
|
|
602
|
+
// without the per-request commerce app context.
|
|
603
|
+
|
|
604
|
+
describe("resolveDecoPage — #277 client-side navigation disables deferral", () => {
|
|
605
|
+
const lazySec = {
|
|
606
|
+
__resolveType: WELL_KNOWN_TYPES.LAZY,
|
|
607
|
+
section: { __resolveType: "site/sections/Hero.tsx" },
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
beforeEach(() => {
|
|
611
|
+
// Enable async rendering so useAsync can be true for SSR requests.
|
|
612
|
+
setAsyncRenderingConfig({ foldThreshold: Infinity, respectCmsLazy: true });
|
|
613
|
+
// resolveSectionShallow unwraps the ⚡ and looks up the inner key via
|
|
614
|
+
// getSection — return truthy so it produces a DeferredSection rather than
|
|
615
|
+
// falling back to eager resolution.
|
|
616
|
+
(getSection as ReturnType<typeof vi.fn>).mockReturnValue({ default: () => null });
|
|
617
|
+
// Return a page with one CMS ⚡-wrapped section.
|
|
618
|
+
(findPageByPath as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
619
|
+
page: { name: "test", sections: [lazySec] },
|
|
620
|
+
params: {},
|
|
621
|
+
blockKey: "test-page",
|
|
622
|
+
});
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
afterEach(() => {
|
|
626
|
+
(getSection as ReturnType<typeof vi.fn>).mockReset();
|
|
627
|
+
(findPageByPath as ReturnType<typeof vi.fn>).mockReset();
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
it("SSR request defers a CMS ⚡ section", async () => {
|
|
631
|
+
const result = await resolveDecoPage("/product/foo", {});
|
|
632
|
+
expect(result?.deferredSections).toHaveLength(1);
|
|
633
|
+
expect(result?.deferredSections[0].component).toBe("site/sections/Hero.tsx");
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
it("client-nav (isClientNavigation: true) resolves the ⚡ section eagerly — empty deferredSections", async () => {
|
|
637
|
+
const result = await resolveDecoPage("/product/foo", { isClientNavigation: true });
|
|
638
|
+
expect(result?.deferredSections).toHaveLength(0);
|
|
639
|
+
});
|
|
640
|
+
});
|