@decocms/blocks 8.0.0 → 8.1.0-next.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.
Files changed (220) hide show
  1. package/bin/deco.js +13 -0
  2. package/package.json +32 -82
  3. package/src/index.ts +35 -8
  4. package/src/protocol/assets.ts +124 -0
  5. package/src/protocol/canonical.ts +7 -0
  6. package/src/protocol/ciphertext.ts +6 -0
  7. package/src/protocol/client.ts +170 -0
  8. package/src/protocol/conformance/cases/assets.ts +81 -0
  9. package/src/protocol/conformance/cases/guards.ts +314 -0
  10. package/src/protocol/conformance/cases/reads.ts +168 -0
  11. package/src/protocol/conformance/cases/types.ts +9 -0
  12. package/src/protocol/conformance/cases/wire.ts +138 -0
  13. package/src/protocol/conformance/cases/writes.ts +345 -0
  14. package/src/protocol/conformance/contentHashFixtures.ts +79 -0
  15. package/src/protocol/conformance/context.ts +222 -0
  16. package/src/protocol/conformance/index.ts +140 -0
  17. package/src/protocol/errors.ts +142 -0
  18. package/src/protocol/index.ts +39 -0
  19. package/src/protocol/keys.ts +279 -0
  20. package/src/protocol/params.ts +67 -0
  21. package/src/protocol/secrets.ts +231 -0
  22. package/src/protocol/server/assets.ts +119 -0
  23. package/src/protocol/server/auth.ts +49 -0
  24. package/src/protocol/server/bodyCache.ts +84 -0
  25. package/src/protocol/server/content.ts +175 -0
  26. package/src/protocol/server/core.ts +112 -0
  27. package/src/protocol/server/handler.ts +102 -0
  28. package/src/protocol/server/http.ts +139 -0
  29. package/src/protocol/server/index.ts +11 -0
  30. package/src/protocol/server/methods/apply.ts +341 -0
  31. package/src/protocol/server/methods/read.ts +156 -0
  32. package/src/protocol/server/rpc.ts +136 -0
  33. package/src/protocol/storage/fs/hash.ts +21 -0
  34. package/src/protocol/storage/fs/index.ts +338 -0
  35. package/src/protocol/storage/fs/lock.ts +68 -0
  36. package/src/protocol/storage/fs/transaction.ts +183 -0
  37. package/src/protocol/storage/fs/unsupported.ts +15 -0
  38. package/src/protocol/storage/memory.ts +238 -0
  39. package/src/protocol/storage.ts +182 -0
  40. package/src/protocol/types.ts +172 -0
  41. package/src/v8/analytics.ts +50 -0
  42. package/src/v8/background.ts +107 -0
  43. package/src/v8/builtins/data.ts +23 -0
  44. package/src/v8/builtins/index.ts +26 -0
  45. package/src/v8/builtins/lazy.ts +23 -0
  46. package/src/v8/builtins/legacy.ts +65 -0
  47. package/src/v8/builtins/matchers.ts +31 -0
  48. package/src/v8/builtins/multivariate.ts +25 -0
  49. package/src/v8/builtins/secret.ts +82 -0
  50. package/src/v8/canonical.ts +117 -0
  51. package/src/v8/ciphertext.ts +158 -0
  52. package/src/v8/cli/builtins.ts +20 -0
  53. package/src/v8/cli/check/index.ts +774 -0
  54. package/src/v8/cli/check/messages.ts +168 -0
  55. package/src/v8/cli/content.ts +287 -0
  56. package/src/v8/cli/index.ts +17 -0
  57. package/src/v8/cli/log.ts +18 -0
  58. package/src/v8/cli/main.ts +12 -0
  59. package/src/v8/cli/root.ts +66 -0
  60. package/src/v8/cli/run.ts +236 -0
  61. package/src/v8/cli/schema/builtinSchemas.ts +236 -0
  62. package/src/v8/cli/schema/generate.ts +507 -0
  63. package/src/v8/cli/schema/index.ts +63 -0
  64. package/src/v8/cli/schema/tsProgram.ts +497 -0
  65. package/src/v8/cli/schema/typeToSchema.ts +689 -0
  66. package/src/v8/cli/serve/server.ts +303 -0
  67. package/src/v8/cli/watch.ts +86 -0
  68. package/src/v8/client.ts +147 -0
  69. package/src/v8/cms.ts +237 -0
  70. package/src/v8/content.ts +195 -0
  71. package/src/v8/draft.ts +136 -0
  72. package/src/v8/errors.ts +59 -0
  73. package/src/v8/fetch.ts +133 -0
  74. package/src/v8/identity.ts +65 -0
  75. package/src/v8/index.ts +39 -0
  76. package/src/v8/json.ts +74 -0
  77. package/src/v8/matchRoute.ts +204 -0
  78. package/src/v8/remoteLoader.ts +282 -0
  79. package/src/v8/resolver.ts +278 -0
  80. package/src/v8/secrets.ts +17 -0
  81. package/src/v8/telemetry.ts +533 -0
  82. package/src/v8/types.ts +240 -0
  83. package/src/cms/applySectionConventions.ts +0 -124
  84. package/src/cms/blockSource.test.ts +0 -76
  85. package/src/cms/blockSource.ts +0 -191
  86. package/src/cms/client.browserBundle.test.ts +0 -44
  87. package/src/cms/client.ts +0 -80
  88. package/src/cms/draftSource.test.ts +0 -343
  89. package/src/cms/draftSource.ts +0 -362
  90. package/src/cms/index.ts +0 -151
  91. package/src/cms/layoutCacheRace.test.ts +0 -181
  92. package/src/cms/loadDecofileDirectory.test.ts +0 -109
  93. package/src/cms/loadDecofileDirectory.ts +0 -89
  94. package/src/cms/loader.test.ts +0 -200
  95. package/src/cms/loader.ts +0 -304
  96. package/src/cms/registry.test.ts +0 -110
  97. package/src/cms/registry.ts +0 -242
  98. package/src/cms/resolve.test.ts +0 -980
  99. package/src/cms/resolve.ts +0 -2282
  100. package/src/cms/schema.test.ts +0 -356
  101. package/src/cms/schema.ts +0 -1215
  102. package/src/cms/sectionLoaderContext.test.ts +0 -111
  103. package/src/cms/sectionLoaderContext.ts +0 -113
  104. package/src/cms/sectionLoaders.test.ts +0 -533
  105. package/src/cms/sectionLoaders.ts +0 -636
  106. package/src/cms/sectionMixins.test.ts +0 -167
  107. package/src/cms/sectionMixins.ts +0 -153
  108. package/src/cms/stickyFlags.test.ts +0 -117
  109. package/src/flags/audience.ts +0 -56
  110. package/src/flags/everyone.ts +0 -29
  111. package/src/flags/flag.ts +0 -15
  112. package/src/flags/flags.test.ts +0 -148
  113. package/src/flags/multivariate/image.ts +0 -11
  114. package/src/flags/multivariate/message.ts +0 -11
  115. package/src/flags/multivariate/page.ts +0 -16
  116. package/src/flags/multivariate/section.ts +0 -16
  117. package/src/flags/multivariate.ts +0 -1
  118. package/src/flags/types.ts +0 -59
  119. package/src/flags/utils/multivariate.ts +0 -20
  120. package/src/hooks/Image.test.ts +0 -100
  121. package/src/hooks/Image.tsx +0 -250
  122. package/src/hooks/JsonLd.tsx +0 -353
  123. package/src/hooks/LazySection.tsx +0 -121
  124. package/src/hooks/LiveControls.tsx +0 -122
  125. package/src/hooks/Picture.tsx +0 -127
  126. package/src/hooks/RenderSection.test.tsx +0 -81
  127. package/src/hooks/RenderSection.tsx +0 -91
  128. package/src/hooks/SectionErrorFallback.tsx +0 -97
  129. package/src/hooks/index.ts +0 -30
  130. package/src/matchers/builtins.test.ts +0 -318
  131. package/src/matchers/builtins.ts +0 -459
  132. package/src/matchers/countryNames.ts +0 -104
  133. package/src/matchers/override.test.ts +0 -205
  134. package/src/matchers/override.ts +0 -136
  135. package/src/matchers/posthog.ts +0 -154
  136. package/src/middleware/decoState.ts +0 -55
  137. package/src/middleware/healthMetrics.ts +0 -133
  138. package/src/middleware/hydrationContext.test.ts +0 -61
  139. package/src/middleware/hydrationContext.ts +0 -79
  140. package/src/middleware/index.ts +0 -88
  141. package/src/middleware/liveness.ts +0 -21
  142. package/src/middleware/observability.test.ts +0 -242
  143. package/src/middleware/observability.ts +0 -643
  144. package/src/middleware/validateSection.test.ts +0 -147
  145. package/src/middleware/validateSection.ts +0 -100
  146. package/src/sdk/abTesting.test.ts +0 -326
  147. package/src/sdk/abTesting.ts +0 -499
  148. package/src/sdk/analytics.ts +0 -77
  149. package/src/sdk/cacheHeaders.test.ts +0 -115
  150. package/src/sdk/cacheHeaders.ts +0 -433
  151. package/src/sdk/cachedLoader.test.ts +0 -122
  152. package/src/sdk/cachedLoader.ts +0 -503
  153. package/src/sdk/cachedLoaderModule.test.ts +0 -209
  154. package/src/sdk/clx.ts +0 -5
  155. package/src/sdk/cn.test.ts +0 -34
  156. package/src/sdk/cn.ts +0 -28
  157. package/src/sdk/composite.test.ts +0 -121
  158. package/src/sdk/composite.ts +0 -114
  159. package/src/sdk/cookie.test.ts +0 -108
  160. package/src/sdk/cookie.ts +0 -129
  161. package/src/sdk/crypto.ts +0 -185
  162. package/src/sdk/csp.ts +0 -59
  163. package/src/sdk/detectDevice.ts +0 -45
  164. package/src/sdk/djb2.ts +0 -20
  165. package/src/sdk/encoding.test.ts +0 -71
  166. package/src/sdk/encoding.ts +0 -47
  167. package/src/sdk/env.test.ts +0 -33
  168. package/src/sdk/env.ts +0 -54
  169. package/src/sdk/flags.test.ts +0 -91
  170. package/src/sdk/flags.ts +0 -108
  171. package/src/sdk/http.test.ts +0 -71
  172. package/src/sdk/http.ts +0 -124
  173. package/src/sdk/index.ts +0 -90
  174. package/src/sdk/inflightTimeout.test.ts +0 -35
  175. package/src/sdk/inflightTimeout.ts +0 -53
  176. package/src/sdk/instrumentedFetch.test.ts +0 -559
  177. package/src/sdk/instrumentedFetch.ts +0 -339
  178. package/src/sdk/invoke.test.ts +0 -115
  179. package/src/sdk/invoke.ts +0 -298
  180. package/src/sdk/logger.test.ts +0 -432
  181. package/src/sdk/logger.ts +0 -304
  182. package/src/sdk/mergeCacheControl.ts +0 -150
  183. package/src/sdk/normalizeUrls.ts +0 -91
  184. package/src/sdk/observability.ts +0 -109
  185. package/src/sdk/otel.test.ts +0 -526
  186. package/src/sdk/otel.ts +0 -1012
  187. package/src/sdk/otelAdapters/clickhouseCollector.ts +0 -65
  188. package/src/sdk/otelAdapters.test.ts +0 -89
  189. package/src/sdk/otelAdapters.ts +0 -144
  190. package/src/sdk/otelHttpLog.test.ts +0 -457
  191. package/src/sdk/otelHttpLog.ts +0 -419
  192. package/src/sdk/otelHttpMeter.test.ts +0 -292
  193. package/src/sdk/otelHttpMeter.ts +0 -506
  194. package/src/sdk/otelHttpTracer.test.ts +0 -474
  195. package/src/sdk/otelHttpTracer.ts +0 -543
  196. package/src/sdk/redirects.ts +0 -228
  197. package/src/sdk/requestContext.ts +0 -281
  198. package/src/sdk/requestContextStorage.browser.test.ts +0 -29
  199. package/src/sdk/requestContextStorage.browser.ts +0 -43
  200. package/src/sdk/requestContextStorage.ts +0 -35
  201. package/src/sdk/retry.ts +0 -45
  202. package/src/sdk/serverTimings.ts +0 -68
  203. package/src/sdk/signal.ts +0 -42
  204. package/src/sdk/sitemap.ts +0 -160
  205. package/src/sdk/urlRedaction.test.ts +0 -73
  206. package/src/sdk/urlRedaction.ts +0 -82
  207. package/src/sdk/urlUtils.ts +0 -134
  208. package/src/sdk/useDevice.test.ts +0 -130
  209. package/src/sdk/useDevice.ts +0 -89
  210. package/src/sdk/useDeviceContext.tsx +0 -108
  211. package/src/sdk/useId.ts +0 -7
  212. package/src/sdk/useScript.test.ts +0 -128
  213. package/src/sdk/useScript.ts +0 -210
  214. package/src/sdk/useSuggestions.test.ts +0 -230
  215. package/src/sdk/useSuggestions.ts +0 -188
  216. package/src/sdk/wrapCaughtErrors.ts +0 -107
  217. package/src/setup.ts +0 -120
  218. package/src/types/index.ts +0 -53
  219. package/src/types/widgets.ts +0 -14
  220. package/tsconfig.json +0 -7
@@ -1,127 +0,0 @@
1
- "use client";
2
-
3
- // `"use client"` added by @decocms/nextjs's next-smoke fixture build
4
- // (Picture is reachable from `DecoRootLayout`/`SectionRenderer` via the
5
- // `hooks/index.ts` barrel, so it is part of the react-server module graph
6
- // on any Next.js Server Component page even when a given page never
7
- // renders it): `createContext`/`useContext` are unavailable under React's
8
- // react-server condition, and Next statically flags any reachable module
9
- // that imports them without this directive ("You're importing a component
10
- // that needs createContext...") — same class of fix, same precedent, as
11
- // `SectionErrorFallback.tsx`'s `"use client"` (class component /
12
- // componentDidCatch, also client-only).
13
- import {
14
- type ComponentPropsWithoutRef,
15
- type Context,
16
- createContext,
17
- forwardRef,
18
- type ReactNode,
19
- useContext,
20
- useMemo,
21
- } from "react";
22
- import { type FitOptions, getOptimizedMediaUrl, getSrcSet } from "./Image";
23
-
24
- // -------------------------------------------------------------------------
25
- // Preload context — flows from <Picture preload> to child <Source> elements
26
- // so each source can inject its own <link rel="preload"> with the correct
27
- // media query for responsive art direction.
28
- //
29
- // Still created LAZILY (first render, not module scope) even under
30
- // `"use client"`: this keeps a single memoized context object regardless of
31
- // how many client bundle chunks end up importing this module, rather than
32
- // relying on module-instance identity across chunks.
33
- // -------------------------------------------------------------------------
34
-
35
- interface PreloadContextValue {
36
- preload: boolean;
37
- }
38
-
39
- let _preloadContext: Context<PreloadContextValue> | null = null;
40
- function getPreloadContext(): Context<PreloadContextValue> {
41
- _preloadContext ??= createContext<PreloadContextValue>({ preload: false });
42
- return _preloadContext;
43
- }
44
-
45
- // -------------------------------------------------------------------------
46
- // Source — composable <source> with automatic srcSet optimization and
47
- // preload link injection when inside a <Picture preload>.
48
- // -------------------------------------------------------------------------
49
-
50
- export type SourceProps = Omit<ComponentPropsWithoutRef<"source">, "width" | "height"> & {
51
- src: string;
52
- /** @description Improves Web Vitals (CLS|LCP) */
53
- width: number;
54
- /** @description Improves Web Vitals (CLS|LCP) */
55
- height?: number;
56
- /** @description Improves Web Vitals (LCP). Use high for LCP image. */
57
- fetchPriority?: "high" | "low" | "auto";
58
- /** @description Object-fit */
59
- fit?: FitOptions;
60
- };
61
-
62
- export const Source = forwardRef<HTMLSourceElement, SourceProps>(function Source(
63
- { src, width, height, fetchPriority, fit = "cover", ...rest },
64
- ref,
65
- ) {
66
- const { preload } = useContext(getPreloadContext());
67
-
68
- const optimizedSrc = getOptimizedMediaUrl({
69
- originalSrc: src,
70
- width,
71
- height,
72
- fit,
73
- });
74
- const srcSet = rest.srcSet ?? getSrcSet(src, width, height, fit);
75
-
76
- return (
77
- <>
78
- {preload && (
79
- <link
80
- as="image"
81
- rel="preload"
82
- href={optimizedSrc}
83
- imageSrcSet={srcSet}
84
- fetchPriority={fetchPriority ?? "high"}
85
- media={rest.media}
86
- />
87
- )}
88
- <source {...rest} srcSet={srcSet ?? optimizedSrc} width={width} height={height} ref={ref} />
89
- </>
90
- );
91
- });
92
-
93
- // -------------------------------------------------------------------------
94
- // Picture — composable wrapper that provides preload context to children.
95
- //
96
- // Usage:
97
- // <Picture preload={isLcp}>
98
- // <Source media="(max-width: 767px)" src={mobile} width={320} height={280} />
99
- // <Source media="(min-width: 768px)" src={desktop} width={1280} height={280} />
100
- // <Image src={desktop} width={1280} height={280} />
101
- // </Picture>
102
- // -------------------------------------------------------------------------
103
-
104
- export type PictureProps = ComponentPropsWithoutRef<"picture"> & {
105
- children: ReactNode;
106
- /**
107
- * @description When true, child <Source> and <Image> elements inject
108
- * `<link rel="preload">` tags for their respective media queries.
109
- */
110
- preload?: boolean;
111
- };
112
-
113
- export const Picture = forwardRef<HTMLPictureElement, PictureProps>(function Picture(
114
- { children, preload = false, ...props },
115
- ref,
116
- ) {
117
- const value = useMemo(() => ({ preload }), [preload]);
118
- const PreloadContext = getPreloadContext();
119
-
120
- return (
121
- <PreloadContext.Provider value={value}>
122
- <picture {...props} ref={ref}>
123
- {children}
124
- </picture>
125
- </PreloadContext.Provider>
126
- );
127
- });
@@ -1,81 +0,0 @@
1
- import { renderToString } from "react-dom/server";
2
- import { describe, expect, it } from "vitest";
3
- import { registerSection, registerSectionsSync } from "../cms/registry";
4
- import RenderSection from "./RenderSection";
5
-
6
- // NOTE: each test uses its OWN section key. The registry module captures the
7
- // `globalThis.__deco.*` objects at module load, so re-assigning them in a
8
- // beforeEach (the registry.test.ts pattern) does not actually clear the
9
- // registry this module writes to — and RenderSection additionally keeps a
10
- // module-level lazy cache keyed by resolveType. Unique keys sidestep both.
11
-
12
- function Hero({ label }: { label?: string }) {
13
- // Single text node — avoids React's `<!-- -->` separator between
14
- // adjacent text/expression children, keeping assertions simple.
15
- return <h1>{`hero-${label ?? "none"}`}</h1>;
16
- }
17
-
18
- // A lazy loader that never settles: the lazy path suspends forever, so any
19
- // content that DOES render must have come from the sync registry.
20
- const neverResolves = () => new Promise<never>(() => {});
21
-
22
- describe("RenderSection sync-first", () => {
23
- it("renders a sync-registered section directly (no Suspense fallback)", () => {
24
- const KEY = "site/sections/SyncA.tsx";
25
- registerSectionsSync({ [KEY]: { default: Hero } });
26
-
27
- const html = renderToString(<RenderSection section={{ __resolveType: KEY, label: "a" }} />);
28
- expect(html).toContain("hero-a");
29
- });
30
-
31
- it("renders sync for the old { Component: string } shape too", () => {
32
- const KEY = "site/sections/SyncB.tsx";
33
- registerSectionsSync({ [KEY]: { default: Hero } });
34
-
35
- const html = renderToString(
36
- <RenderSection section={{ Component: KEY as any, props: { label: "b" } }} />,
37
- );
38
- expect(html).toContain("hero-b");
39
- });
40
-
41
- it("prefers the sync component over a pending lazy loader", () => {
42
- const KEY = "site/sections/SyncC.tsx";
43
- // Both registered: lazy loader never settles, sync is available.
44
- // Sync-first must render the content without suspending.
45
- registerSection(KEY, neverResolves as any);
46
- registerSectionsSync({ [KEY]: { default: Hero } });
47
-
48
- const html = renderToString(
49
- <RenderSection
50
- section={{ __resolveType: KEY, label: "c" }}
51
- fallback={<span>loading</span>}
52
- />,
53
- );
54
- expect(html).toContain("hero-c");
55
- expect(html).not.toContain("loading");
56
- });
57
-
58
- it("falls back to the lazy path when no sync component is registered", () => {
59
- const KEY = "site/sections/LazyOnlyD.tsx";
60
- registerSection(KEY, neverResolves as any);
61
-
62
- const html = renderToString(
63
- <RenderSection
64
- section={{ __resolveType: KEY, label: "d" }}
65
- fallback={<span>loading</span>}
66
- />,
67
- );
68
- expect(html).toContain("loading");
69
- expect(html).not.toContain("hero-d");
70
- });
71
-
72
- it("renders the fallback when the section is not registered at all", () => {
73
- const html = renderToString(
74
- <RenderSection
75
- section={{ __resolveType: "site/sections/MissingE.tsx" }}
76
- fallback={<span>missing</span>}
77
- />,
78
- );
79
- expect(html).toContain("missing");
80
- });
81
- });
@@ -1,91 +0,0 @@
1
- import { type ComponentType, lazy, Suspense } from "react";
2
- import { getSection, getSyncComponent } from "../cms/registry";
3
-
4
- const componentCache = new Map<string, ComponentType<any>>();
5
-
6
- function getOrCreateLazy(resolveType: string): ComponentType<any> | null {
7
- if (componentCache.has(resolveType)) {
8
- return componentCache.get(resolveType)!;
9
- }
10
-
11
- const loader = getSection(resolveType);
12
- if (!loader) return null;
13
-
14
- const LazyComponent = lazy(async () => {
15
- const mod = await loader();
16
- return { default: mod.default };
17
- });
18
-
19
- componentCache.set(resolveType, LazyComponent);
20
- return LazyComponent;
21
- }
22
-
23
- interface SectionLike {
24
- __resolveType?: string;
25
- Component?: ComponentType<any>;
26
- props?: Record<string, unknown>;
27
- [key: string]: unknown;
28
- }
29
-
30
- /**
31
- * Renders a Section-type prop from the CMS.
32
- *
33
- * Handles both the old Deco format ({ Component, props }) and
34
- * the new @decocms/start format ({ __resolveType, ...props }).
35
- *
36
- * Sync-first: sections registered as sync (`export const sync = true`,
37
- * bundled in the main chunk) render DIRECTLY — no React.lazy / Suspense.
38
- * This mirrors DecoPageRenderer's sync-first path and matters twice:
39
- *
40
- * - SSR streaming: React 19 omits the `<!--$-->` markers when a Suspense
41
- * boundary resolves synchronously, which triggers a hydration mismatch
42
- * (minified #418) — same reason DecoPageRenderer bifurcates.
43
- * - SPA commit: the lazy path suspends with `fallback ?? null` while the
44
- * section chunk loads, so a route commit that renders content through
45
- * RenderSection (e.g. a gate section like NotFoundChallenge) paints the
46
- * page with a BLANK middle until the chunk resolves.
47
- *
48
- * Sites without registered sync components are unaffected:
49
- * `getSyncComponent()` returns undefined and the lazy path runs as before.
50
- */
51
- export default function RenderSection({
52
- section,
53
- fallback,
54
- }: {
55
- section: SectionLike | null | undefined;
56
- fallback?: React.ReactNode;
57
- }) {
58
- if (!section) return null;
59
-
60
- if (section.Component) {
61
- const { Component, props = {}, ...overrides } = section;
62
- const mergedProps = { ...(props as Record<string, unknown>), ...overrides };
63
- if (typeof Component === "string") {
64
- const Sync = getSyncComponent(Component);
65
- if (Sync) return <Sync {...mergedProps} />;
66
- const Comp = getOrCreateLazy(Component);
67
- if (!Comp) return <>{fallback ?? null}</>;
68
- return (
69
- <Suspense fallback={fallback ?? null}>
70
- <Comp {...mergedProps} />
71
- </Suspense>
72
- );
73
- }
74
- return <Component {...mergedProps} />;
75
- }
76
-
77
- if (section.__resolveType) {
78
- const { __resolveType: _, ...props } = section;
79
- const Sync = getSyncComponent(section.__resolveType);
80
- if (Sync) return <Sync {...props} />;
81
- const Comp = getOrCreateLazy(section.__resolveType);
82
- if (!Comp) return <>{fallback ?? null}</>;
83
- return (
84
- <Suspense fallback={fallback ?? null}>
85
- <Comp {...props} />
86
- </Suspense>
87
- );
88
- }
89
-
90
- return null;
91
- }
@@ -1,97 +0,0 @@
1
- "use client";
2
-
3
- // `"use client"` added by Phase 2 Task 9 (@decocms/nextjs's next-smoke
4
- // fixture): `SectionErrorBoundary` is a class component with
5
- // `componentDidCatch`/`getDerivedStateFromError` — error boundaries require
6
- // a Client Component in Next's App Router. `SectionRenderer.tsx` wraps
7
- // every rendered section in this boundary, so without the directive, any
8
- // Server Component that ends up importing `@decocms/blocks/hooks`
9
- // transitively fails Next's build. Server Component children passed via
10
- // `props.children` still render fine — passing already-rendered Server
11
- // Component output into a Client Component's `children` is a supported RSC
12
- // composition pattern.
13
- import { Component, type ErrorInfo, type ReactNode } from "react";
14
-
15
- interface ErrorBoundaryProps {
16
- sectionKey: string;
17
- fallback?: ReactNode;
18
- children: ReactNode;
19
- }
20
-
21
- interface ErrorBoundaryState {
22
- error: Error | null;
23
- }
24
-
25
- /**
26
- * Per-section error boundary that prevents a single broken section
27
- * from crashing the entire page.
28
- *
29
- * In development, shows the error message + stack trace.
30
- * In production, renders a silent empty placeholder.
31
- */
32
- export class SectionErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
33
- constructor(props: ErrorBoundaryProps) {
34
- super(props);
35
- this.state = { error: null };
36
- }
37
-
38
- static getDerivedStateFromError(error: Error): ErrorBoundaryState {
39
- return { error };
40
- }
41
-
42
- componentDidCatch(error: Error, info: ErrorInfo) {
43
- console.error(`[CMS] Section "${this.props.sectionKey}" crashed:`, error, info.componentStack);
44
- }
45
-
46
- render() {
47
- if (this.state.error) {
48
- if (this.props.fallback) return this.props.fallback;
49
- return (
50
- <DefaultSectionErrorFallback error={this.state.error} sectionKey={this.props.sectionKey} />
51
- );
52
- }
53
- return this.props.children;
54
- }
55
- }
56
-
57
- function DefaultSectionErrorFallback({ error, sectionKey }: { error: Error; sectionKey: string }) {
58
- const isDev = typeof process !== "undefined" && process.env.NODE_ENV === "development";
59
-
60
- if (!isDev) {
61
- return <div data-section-error={sectionKey} className="hidden" />;
62
- }
63
-
64
- return (
65
- <div
66
- data-section-error={sectionKey}
67
- style={{
68
- padding: "16px",
69
- margin: "8px 0",
70
- border: "2px solid #ef4444",
71
- borderRadius: "8px",
72
- background: "#fef2f2",
73
- fontFamily: "monospace",
74
- fontSize: "13px",
75
- }}
76
- >
77
- <div style={{ fontWeight: "bold", color: "#dc2626", marginBottom: "8px" }}>
78
- Section Error: {sectionKey}
79
- </div>
80
- <div style={{ color: "#991b1b" }}>{error.message}</div>
81
- {error.stack && (
82
- <pre
83
- style={{
84
- marginTop: "8px",
85
- fontSize: "11px",
86
- color: "#6b7280",
87
- whiteSpace: "pre-wrap",
88
- overflow: "auto",
89
- maxHeight: "200px",
90
- }}
91
- >
92
- {error.stack}
93
- </pre>
94
- )}
95
- </div>
96
- );
97
- }
@@ -1,30 +0,0 @@
1
- export { isBelowFold, LazySection, type LazySectionProps } from "./LazySection";
2
- export { LiveControls } from "./LiveControls";
3
- export { SectionErrorBoundary } from "./SectionErrorFallback";
4
- export { default as RenderSection } from "./RenderSection";
5
-
6
- // Commerce UI primitives (moved from apps-start's commerce/components/).
7
- export {
8
- default as Image,
9
- registerImageCdnDomain,
10
- getImageCdnDomain,
11
- getOptimizedMediaUrl,
12
- getSrcSet,
13
- FACTORS,
14
- type ImageProps,
15
- type FitOptions,
16
- } from "./Image";
17
- export { Picture, Source, type PictureProps, type SourceProps } from "./Picture";
18
- export {
19
- ProductJsonLd,
20
- PLPJsonLd,
21
- BreadcrumbJsonLd,
22
- seoMetaTags,
23
- type ProductJsonLdProps,
24
- type PLPJsonLdProps,
25
- type BreadcrumbJsonLdProps,
26
- type SeoMetaProps,
27
- type JsonLdProduct,
28
- type JsonLdProductListingPage,
29
- type JsonLdBreadcrumbList,
30
- } from "./JsonLd";