create-nextblock 0.15.5 → 0.15.9

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 (79) hide show
  1. package/package.json +50 -26
  2. package/templates/nextblock-template/app/ToasterProvider.tsx +26 -17
  3. package/templates/nextblock-template/app/actions/contactSellerActions.test.ts +280 -0
  4. package/templates/nextblock-template/app/actions/contactSellerActions.ts +222 -0
  5. package/templates/nextblock-template/app/actions/email-retry.test.ts +62 -0
  6. package/templates/nextblock-template/app/actions/email.ts +241 -110
  7. package/templates/nextblock-template/app/actions/formActions.ts +245 -116
  8. package/templates/nextblock-template/app/actions/interactions.ts +489 -396
  9. package/templates/nextblock-template/app/actions/threadActions.ts +166 -0
  10. package/templates/nextblock-template/app/api/checkout/route.ts +162 -146
  11. package/templates/nextblock-template/app/api/cron/reset-sandbox/route.ts +14 -0
  12. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +664 -1
  13. package/templates/nextblock-template/app/checkout/page.tsx +57 -52
  14. package/templates/nextblock-template/app/cms/CmsClientLayout.tsx +552 -529
  15. package/templates/nextblock-template/app/cms/blocks/editors/FormBlockEditor.tsx +304 -181
  16. package/templates/nextblock-template/app/cms/components/ContactReminderBanner.tsx +75 -0
  17. package/templates/nextblock-template/app/cms/components/PaymentsReminderBanner.tsx +58 -0
  18. package/templates/nextblock-template/app/cms/components/VisibilityControl.tsx +542 -528
  19. package/templates/nextblock-template/app/cms/inquiries/actions.ts +66 -0
  20. package/templates/nextblock-template/app/cms/inquiries/page.tsx +12 -0
  21. package/templates/nextblock-template/app/cms/interactions/page.tsx +12 -51
  22. package/templates/nextblock-template/app/cms/layout.tsx +101 -73
  23. package/templates/nextblock-template/app/cms/messages/MessagesClient.tsx +661 -0
  24. package/templates/nextblock-template/app/cms/messages/actions.ts +404 -0
  25. package/templates/nextblock-template/app/cms/messages/loadInbox.ts +333 -0
  26. package/templates/nextblock-template/app/cms/messages/page.tsx +87 -0
  27. package/templates/nextblock-template/app/cms/messages/require-admin.ts +37 -0
  28. package/templates/nextblock-template/app/cms/products/[id]/edit/page.tsx +370 -362
  29. package/templates/nextblock-template/app/cms/revisions/service.ts +20 -0
  30. package/templates/nextblock-template/app/cms/settings/email/components/EmailForm.tsx +227 -185
  31. package/templates/nextblock-template/app/layout.tsx +671 -667
  32. package/templates/nextblock-template/app/lib/seo.ts +319 -311
  33. package/templates/nextblock-template/app/product/[slug]/page.tsx +502 -482
  34. package/templates/nextblock-template/app/providers.tsx +96 -96
  35. package/templates/nextblock-template/app/thread/ThreadView.tsx +164 -0
  36. package/templates/nextblock-template/app/thread/[token]/route.ts +57 -0
  37. package/templates/nextblock-template/app/thread/layout.tsx +15 -0
  38. package/templates/nextblock-template/app/thread/page.tsx +98 -0
  39. package/templates/nextblock-template/components/BlockRenderer.tsx +312 -296
  40. package/templates/nextblock-template/components/ContactSellerSection.tsx +188 -0
  41. package/templates/nextblock-template/components/PostCommentsSection.tsx +378 -369
  42. package/templates/nextblock-template/components/ProductReviewsSection.tsx +426 -419
  43. package/templates/nextblock-template/components/StaffReplies.tsx +102 -0
  44. package/templates/nextblock-template/components/blocks/renderers/CartBlockRenderer.tsx +18 -17
  45. package/templates/nextblock-template/components/blocks/renderers/CheckoutBlockRenderer.tsx +20 -19
  46. package/templates/nextblock-template/components/blocks/renderers/FeaturedProductBlockRenderer.tsx +25 -22
  47. package/templates/nextblock-template/components/blocks/renderers/FormBlockRenderer.tsx +385 -381
  48. package/templates/nextblock-template/components/blocks/renderers/ProductDetailsBlockRenderer.tsx +157 -92
  49. package/templates/nextblock-template/components/blocks/renderers/ProductGridBlockRenderer.tsx +34 -31
  50. package/templates/nextblock-template/components/blocks/renderers/SectionBlockRenderer.tsx +612 -600
  51. package/templates/nextblock-template/components/commerce/PaymentReadinessBoundary.tsx +32 -0
  52. package/templates/nextblock-template/docs/05-DEVELOPER-GUIDE.md +25 -19
  53. package/templates/nextblock-template/docs/06-CLI-AND-SCAFFOLDING.md +1 -1
  54. package/templates/nextblock-template/docs/08-NEXTBLOCK-CORTEX-AI-ARCHITECTURE.md +2 -2
  55. package/templates/nextblock-template/docs/12-VERCEL-DEPLOYMENT.md +32 -9
  56. package/templates/nextblock-template/docs/14-MESSAGES-INBOX.md +309 -0
  57. package/templates/nextblock-template/docs/README.md +42 -41
  58. package/templates/nextblock-template/docs/TECHNICAL_SPECIFICATION.md +540 -542
  59. package/templates/nextblock-template/docs/assets/lighthouse-scores.png +0 -0
  60. package/templates/nextblock-template/lib/blocks/blockColors.test.ts +22 -2
  61. package/templates/nextblock-template/lib/blocks/blockColors.ts +44 -1
  62. package/templates/nextblock-template/lib/blocks/blockRegistry.ts +761 -753
  63. package/templates/nextblock-template/lib/cms/contact-reminder.ts +64 -0
  64. package/templates/nextblock-template/lib/cms/payments-reminder.ts +98 -0
  65. package/templates/nextblock-template/lib/cms/unread-messages.ts +42 -0
  66. package/templates/nextblock-template/lib/commerce/seller-contact.ts +162 -0
  67. package/templates/nextblock-template/lib/config/email-settings.ts +323 -254
  68. package/templates/nextblock-template/lib/config/email-tls.test.ts +57 -0
  69. package/templates/nextblock-template/lib/email/placeholder-address.test.ts +59 -0
  70. package/templates/nextblock-template/lib/email/placeholder-address.ts +39 -0
  71. package/templates/nextblock-template/lib/messages/thread-reference.test.ts +70 -0
  72. package/templates/nextblock-template/lib/messages/thread-token.test.ts +93 -0
  73. package/templates/nextblock-template/lib/messages/thread-token.ts +157 -0
  74. package/templates/nextblock-template/lib/messages/threads.ts +579 -0
  75. package/templates/nextblock-template/lib/setup/migrations-bundle.ts +20 -0
  76. package/templates/nextblock-template/lib/site-url.test.ts +89 -0
  77. package/templates/nextblock-template/lib/site-url.ts +102 -48
  78. package/templates/nextblock-template/package.json +14 -1
  79. package/templates/nextblock-template/public/assets/nextblock-banner.jpg +0 -0
@@ -1,296 +1,312 @@
1
- // components/BlockRenderer.tsx
2
- import React from "react";
3
- import type { Database } from "@nextblock-cms/db";
4
- import type { SectionBlockContent } from "../lib/blocks/blockRegistry";
5
- import { buildVisualEditAttributes } from "../lib/visual-editing/edit-info";
6
- import type {
7
- VisualEditAttributes,
8
- VisualEditingDocumentContext,
9
- } from "../lib/visual-editing/types";
10
- import { getPublicBlockRendererLoader } from "./blocks/publicRendererLoaders";
11
- import { createClient as createSupabaseServerClient } from "@nextblock-cms/db/server";
12
- import { headers } from "next/headers";
13
-
14
- type Block = Database['public']['Tables']['blocks']['Row'];
15
- import SectionBlockRenderer from "./blocks/renderers/SectionBlockRenderer"; // Static import for LCP
16
- import ClientTextBlockRenderer from "./blocks/renderers/ClientTextBlockRenderer"; // Static import for client component
17
- import { addNonceToInlineScripts } from "../lib/blocks/inlineScriptNonce";
18
- import { getCachedCustomBlockDefinitionBySlug } from "../lib/custom-block-definitions";
19
- import { CachedDynamicLayoutEngine } from "./renderers/CachedDynamicLayoutEngine";
20
- import { resolveBlockRelations } from "../lib/resolve-block-relations";
21
- import { substitutePrivacyMergeTags } from "../lib/privacy/contact-emails";
22
-
23
- const ECOMMERCE_BLOCK_TYPES = new Set([
24
- "product_grid",
25
- "featured_product",
26
- "cart",
27
- "checkout",
28
- "product_details",
29
- ]);
30
-
31
- function loadEcommerceBlockRenderer(blockType: string) {
32
- return import("./blocks/ecommerceRendererLoaders").then((module) =>
33
- module.loadEcommerceBlockRenderer(blockType)
34
- );
35
- }
36
-
37
- interface BlockRendererProps {
38
- blocks: Block[];
39
- languageId: number;
40
- excludeProductId?: string;
41
- excludeTranslationGroupId?: string | null;
42
- visualEditing?: VisualEditingDocumentContext;
43
- productVisualEditingEnabled?: boolean;
44
- }
45
-
46
- interface BlockRenderContext {
47
- block: Block;
48
- blockIndex: number;
49
- languageId: number;
50
- excludeProductId?: string;
51
- excludeTranslationGroupId?: string | null;
52
- visualEditing?: VisualEditingDocumentContext;
53
- productVisualEditingEnabled?: boolean;
54
- visualEditAttributes?: VisualEditAttributes;
55
- botProtectionPublic?: {
56
- provider: 'none' | 'turnstile' | 'recaptcha';
57
- siteKey: string;
58
- };
59
- scriptNonce?: string;
60
- }
61
-
62
- async function renderLoadedBlock({
63
- block,
64
- blockIndex,
65
- languageId,
66
- excludeProductId,
67
- excludeTranslationGroupId,
68
- visualEditing,
69
- productVisualEditingEnabled,
70
- visualEditAttributes,
71
- botProtectionPublic,
72
- scriptNonce,
73
- }: BlockRenderContext) {
74
- const rendererLoader = getPublicBlockRendererLoader(block.block_type);
75
-
76
- if (!rendererLoader) {
77
- if (ECOMMERCE_BLOCK_TYPES.has(block.block_type)) {
78
- const { default: EcommerceRendererComponent } = await loadEcommerceBlockRenderer(
79
- block.block_type
80
- );
81
-
82
- return (
83
- <EcommerceRendererComponent
84
- content={block.content}
85
- languageId={languageId}
86
- excludeProductId={excludeProductId}
87
- excludeTranslationGroupId={excludeTranslationGroupId}
88
- visualEditAttributes={visualEditAttributes}
89
- productVisualEditingEnabled={productVisualEditingEnabled}
90
- visualEditing={visualEditing}
91
- />
92
- );
93
- }
94
-
95
- const definition = await getCachedCustomBlockDefinitionBySlug(block.block_type);
96
- if (definition) {
97
- const resolvedBlock = (await resolveBlockRelations({
98
- data: block.content as Record<string, any>,
99
- fields: definition.fields,
100
- })) as any;
101
-
102
- return (
103
- <div key={block.id} {...visualEditAttributes}>
104
- <CachedDynamicLayoutEngine
105
- definition={definition}
106
- layoutSchema={definition.layout_schema}
107
- fields={definition.fields}
108
- data={{
109
- ...(resolvedBlock.data || {}),
110
- resolved_relations: resolvedBlock.resolved_relations || {},
111
- }}
112
- />
113
- </div>
114
- );
115
- }
116
-
117
- // No renderer and no matching custom block definition. Public visitors
118
- // should never see a raw error/JSON dump, so only surface the diagnostic
119
- // when visual editing is actually enabled (the page always passes a
120
- // visualEditing object, so check the enabled flag); otherwise render nothing.
121
- if (!visualEditing?.enabled) {
122
- return null;
123
- }
124
-
125
- return (
126
- <div
127
- key={block.id}
128
- className="my-4 p-4 border rounded bg-destructive/10 text-destructive"
129
- {...visualEditAttributes}
130
- >
131
- <p>
132
- <strong>Unsupported block type:</strong> {block.block_type}
133
- </p>
134
- <p className="text-xs mt-1">
135
- No custom block definition was found for the slug{' '}
136
- <code>{block.block_type}</code>. Save a custom block with this exact slug,
137
- or re-add the block from the picker.
138
- </p>
139
- <pre className="text-xs whitespace-pre-wrap mt-2">
140
- {JSON.stringify(block.content, null, 2)}
141
- </pre>
142
- </div>
143
- );
144
- }
145
-
146
- // Keep common LCP-adjacent text blocks out of the dynamic renderer manifest.
147
- if (block.block_type === 'text') {
148
- // Top-level text blocks bypass the server TextBlockRenderer, so everything it
149
- // would have done to the HTML has to happen here too: merge tags (e.g.
150
- // {{privacy_email}} on the Privacy/Terms pages) and — because the CSP carries a
151
- // nonce, which makes browsers ignore 'unsafe-inline' — the inline-script nonce.
152
- // Without the latter, an inline <script> an editor wrote into a rich-text block
153
- // is dropped by the browser with nothing failing server-side.
154
- const textContent = block.content as { html_content?: string } | null;
155
- const rawHtml = typeof textContent?.html_content === 'string' ? textContent.html_content : '';
156
- const merged = rawHtml.includes('{{')
157
- ? await substitutePrivacyMergeTags(rawHtml)
158
- : rawHtml;
159
- const html = addNonceToInlineScripts(merged, scriptNonce ?? '');
160
- return (
161
- <ClientTextBlockRenderer
162
- content={{ ...(textContent as any), html_content: html }}
163
- languageId={languageId}
164
- visualEditAttributes={visualEditAttributes}
165
- />
166
- );
167
- }
168
-
169
- const { default: RendererComponent } = await rendererLoader();
170
-
171
- // Handle different prop requirements for different renderers
172
- // PostsGridBlockRenderer needs the full block object
173
- if (block.block_type === 'posts_grid') {
174
- return (
175
- <RendererComponent
176
- content={block.content}
177
- languageId={languageId}
178
- block={block}
179
- visualEditAttributes={visualEditAttributes}
180
- />
181
- );
182
- }
183
-
184
- return (
185
- <RendererComponent
186
- content={block.content}
187
- languageId={languageId}
188
- excludeProductId={excludeProductId}
189
- excludeTranslationGroupId={excludeTranslationGroupId}
190
- visualEditAttributes={visualEditAttributes}
191
- productVisualEditingEnabled={productVisualEditingEnabled}
192
- visualEditing={visualEditing}
193
- parentBlockId={block.id}
194
- parentBlockIndex={blockIndex}
195
- botProtectionPublic={botProtectionPublic}
196
- scriptNonce={scriptNonce}
197
- // The first top-level block is above the fold, so its media is the LCP
198
- // candidate. Renderers that own an image (video_embed's poster frame)
199
- // use this to preload instead of lazy-loading it.
200
- priority={blockIndex === 0}
201
- />
202
- );
203
- }
204
-
205
- async function renderBlock(context: BlockRenderContext) {
206
- const { block, blockIndex, languageId, visualEditAttributes, visualEditing } = context;
207
-
208
- if (block.block_type === 'section') {
209
- return (
210
- <SectionBlockRenderer
211
- content={block.content as unknown as SectionBlockContent}
212
- languageId={languageId}
213
- visualEditAttributes={visualEditAttributes}
214
- visualEditing={visualEditing}
215
- parentBlockId={block.id}
216
- parentBlockIndex={blockIndex}
217
- blockType={block.block_type}
218
- botProtectionPublic={context.botProtectionPublic}
219
- scriptNonce={context.scriptNonce}
220
- />
221
- );
222
- }
223
-
224
- return renderLoadedBlock(context);
225
- }
226
-
227
- export default async function BlockRenderer({
228
- blocks,
229
- languageId,
230
- excludeProductId,
231
- excludeTranslationGroupId,
232
- visualEditing,
233
- productVisualEditingEnabled,
234
- }: BlockRendererProps) {
235
- if (!blocks || blocks.length === 0) {
236
- return null;
237
- }
238
-
239
- let botProtectionPublic: { provider: 'none' | 'turnstile' | 'recaptcha'; siteKey: string } | undefined;
240
- let scriptNonce = '';
241
-
242
- try {
243
- scriptNonce = (await headers()).get('x-nonce') || '';
244
- } catch (e) {
245
- console.error("[Bot Protection] Error loading CSP nonce in BlockRenderer:", e);
246
- }
247
-
248
- try {
249
- const supabase = createSupabaseServerClient();
250
- const { data: publicSetting } = await supabase
251
- .from('site_settings')
252
- .select('value')
253
- .eq('key', 'bot_protection_public')
254
- .maybeSingle();
255
- if (publicSetting?.value) {
256
- const publicVal = publicSetting.value as Record<string, any>;
257
- botProtectionPublic = {
258
- provider: publicVal.provider || 'none',
259
- siteKey: publicVal.siteKey || '',
260
- };
261
- }
262
- } catch (e) {
263
- console.error("[Bot Protection] Error loading settings in BlockRenderer:", e);
264
- }
265
-
266
- const renderedBlocks = await Promise.all(
267
- blocks.map(async (block, blockIndex) => ({
268
- id: block.id,
269
- node: await renderBlock({
270
- block,
271
- blockIndex,
272
- languageId,
273
- excludeProductId,
274
- excludeTranslationGroupId,
275
- visualEditing,
276
- productVisualEditingEnabled,
277
- botProtectionPublic,
278
- scriptNonce,
279
- visualEditAttributes: buildVisualEditAttributes(visualEditing, {
280
- kind: "top-level",
281
- blockId: block.id,
282
- blockIndex,
283
- blockType: block.block_type,
284
- }),
285
- }),
286
- }))
287
- );
288
-
289
- return (
290
- <>
291
- {renderedBlocks.map(({ id, node }) => (
292
- <React.Fragment key={id}>{node}</React.Fragment>
293
- ))}
294
- </>
295
- );
296
- }
1
+ // components/BlockRenderer.tsx
2
+ import React from "react";
3
+ import type { Database } from "@nextblock-cms/db";
4
+ import type { SectionBlockContent } from "../lib/blocks/blockRegistry";
5
+ import { buildVisualEditAttributes } from "../lib/visual-editing/edit-info";
6
+ import type {
7
+ VisualEditAttributes,
8
+ VisualEditingDocumentContext,
9
+ } from "../lib/visual-editing/types";
10
+ import { getPublicBlockRendererLoader } from "./blocks/publicRendererLoaders";
11
+ import { createClient as createSupabaseServerClient } from "@nextblock-cms/db/server";
12
+ import { headers } from "next/headers";
13
+
14
+ type Block = Database['public']['Tables']['blocks']['Row'];
15
+ import SectionBlockRenderer from "./blocks/renderers/SectionBlockRenderer"; // Static import for LCP
16
+ import ClientTextBlockRenderer from "./blocks/renderers/ClientTextBlockRenderer"; // Static import for client component
17
+ import { addNonceToInlineScripts } from "../lib/blocks/inlineScriptNonce";
18
+ import { getCachedCustomBlockDefinitionBySlug } from "../lib/custom-block-definitions";
19
+ import { CachedDynamicLayoutEngine } from "./renderers/CachedDynamicLayoutEngine";
20
+ import { resolveBlockRelations } from "../lib/resolve-block-relations";
21
+ import { substitutePrivacyMergeTags } from "../lib/privacy/contact-emails";
22
+
23
+ const ECOMMERCE_BLOCK_TYPES = new Set([
24
+ "product_grid",
25
+ "featured_product",
26
+ "cart",
27
+ "checkout",
28
+ "product_details",
29
+ ]);
30
+
31
+ function loadEcommerceBlockRenderer(blockType: string) {
32
+ return import("./blocks/ecommerceRendererLoaders").then((module) =>
33
+ module.loadEcommerceBlockRenderer(blockType)
34
+ );
35
+ }
36
+
37
+ interface BlockRendererProps {
38
+ blocks: Block[];
39
+ languageId: number;
40
+ excludeProductId?: string;
41
+ excludeTranslationGroupId?: string | null;
42
+ visualEditing?: VisualEditingDocumentContext;
43
+ productVisualEditingEnabled?: boolean;
44
+ }
45
+
46
+ interface BlockRenderContext {
47
+ block: Block;
48
+ blockIndex: number;
49
+ languageId: number;
50
+ excludeProductId?: string;
51
+ excludeTranslationGroupId?: string | null;
52
+ visualEditing?: VisualEditingDocumentContext;
53
+ productVisualEditingEnabled?: boolean;
54
+ visualEditAttributes?: VisualEditAttributes;
55
+ botProtectionPublic?: {
56
+ provider: 'none' | 'turnstile' | 'recaptcha';
57
+ siteKey: string;
58
+ };
59
+ scriptNonce?: string;
60
+ }
61
+
62
+ async function renderLoadedBlock({
63
+ block,
64
+ blockIndex,
65
+ languageId,
66
+ excludeProductId,
67
+ excludeTranslationGroupId,
68
+ visualEditing,
69
+ productVisualEditingEnabled,
70
+ visualEditAttributes,
71
+ botProtectionPublic,
72
+ scriptNonce,
73
+ }: BlockRenderContext) {
74
+ const rendererLoader = getPublicBlockRendererLoader(block.block_type);
75
+
76
+ if (!rendererLoader) {
77
+ if (ECOMMERCE_BLOCK_TYPES.has(block.block_type)) {
78
+ const { default: EcommerceRendererComponent } = await loadEcommerceBlockRenderer(
79
+ block.block_type
80
+ );
81
+
82
+ return (
83
+ <EcommerceRendererComponent
84
+ content={block.content}
85
+ languageId={languageId}
86
+ excludeProductId={excludeProductId}
87
+ excludeTranslationGroupId={excludeTranslationGroupId}
88
+ visualEditAttributes={visualEditAttributes}
89
+ productVisualEditingEnabled={productVisualEditingEnabled}
90
+ visualEditing={visualEditing}
91
+ />
92
+ );
93
+ }
94
+
95
+ const definition = await getCachedCustomBlockDefinitionBySlug(block.block_type);
96
+ if (definition) {
97
+ const resolvedBlock = (await resolveBlockRelations({
98
+ data: block.content as Record<string, any>,
99
+ fields: definition.fields,
100
+ })) as any;
101
+
102
+ return (
103
+ <div key={block.id} {...visualEditAttributes}>
104
+ <CachedDynamicLayoutEngine
105
+ definition={definition}
106
+ layoutSchema={definition.layout_schema}
107
+ fields={definition.fields}
108
+ data={{
109
+ ...(resolvedBlock.data || {}),
110
+ resolved_relations: resolvedBlock.resolved_relations || {},
111
+ }}
112
+ />
113
+ </div>
114
+ );
115
+ }
116
+
117
+ // No renderer and no matching custom block definition. Public visitors
118
+ // should never see a raw error/JSON dump, so only surface the diagnostic
119
+ // when visual editing is actually enabled (the page always passes a
120
+ // visualEditing object, so check the enabled flag); otherwise render nothing.
121
+ if (!visualEditing?.enabled) {
122
+ return null;
123
+ }
124
+
125
+ return (
126
+ <div
127
+ key={block.id}
128
+ className="my-4 p-4 border rounded bg-destructive/10 text-destructive"
129
+ {...visualEditAttributes}
130
+ >
131
+ <p>
132
+ <strong>Unsupported block type:</strong> {block.block_type}
133
+ </p>
134
+ <p className="text-xs mt-1">
135
+ No custom block definition was found for the slug{' '}
136
+ <code>{block.block_type}</code>. Save a custom block with this exact slug,
137
+ or re-add the block from the picker.
138
+ </p>
139
+ <pre className="text-xs whitespace-pre-wrap mt-2">
140
+ {JSON.stringify(block.content, null, 2)}
141
+ </pre>
142
+ </div>
143
+ );
144
+ }
145
+
146
+ // Keep common LCP-adjacent text blocks out of the dynamic renderer manifest.
147
+ if (block.block_type === 'text') {
148
+ // Top-level text blocks bypass the server TextBlockRenderer, so everything it
149
+ // would have done to the HTML has to happen here too: merge tags (e.g.
150
+ // {{privacy_email}} on the Privacy/Terms pages) and — because the CSP carries a
151
+ // nonce, which makes browsers ignore 'unsafe-inline' — the inline-script nonce.
152
+ // Without the latter, an inline <script> an editor wrote into a rich-text block
153
+ // is dropped by the browser with nothing failing server-side.
154
+ const textContent = block.content as { html_content?: string } | null;
155
+ const rawHtml = typeof textContent?.html_content === 'string' ? textContent.html_content : '';
156
+ const merged = rawHtml.includes('{{')
157
+ ? await substitutePrivacyMergeTags(rawHtml)
158
+ : rawHtml;
159
+ const html = addNonceToInlineScripts(merged, scriptNonce ?? '');
160
+ return (
161
+ <ClientTextBlockRenderer
162
+ content={{ ...(textContent as any), html_content: html }}
163
+ languageId={languageId}
164
+ visualEditAttributes={visualEditAttributes}
165
+ />
166
+ );
167
+ }
168
+
169
+ const { default: RendererComponent } = await rendererLoader();
170
+
171
+ // Handle different prop requirements for different renderers
172
+ // PostsGridBlockRenderer needs the full block object
173
+ if (block.block_type === 'posts_grid') {
174
+ return (
175
+ <RendererComponent
176
+ content={block.content}
177
+ languageId={languageId}
178
+ block={block}
179
+ visualEditAttributes={visualEditAttributes}
180
+ />
181
+ );
182
+ }
183
+
184
+ return (
185
+ <RendererComponent
186
+ content={stripServerOnlyContent(block.block_type, block.content)}
187
+ languageId={languageId}
188
+ excludeProductId={excludeProductId}
189
+ excludeTranslationGroupId={excludeTranslationGroupId}
190
+ visualEditAttributes={visualEditAttributes}
191
+ productVisualEditingEnabled={productVisualEditingEnabled}
192
+ visualEditing={visualEditing}
193
+ parentBlockId={block.id}
194
+ parentBlockIndex={blockIndex}
195
+ botProtectionPublic={botProtectionPublic}
196
+ scriptNonce={scriptNonce}
197
+ // The first top-level block is above the fold, so its media is the LCP
198
+ // candidate. Renderers that own an image (video_embed's poster frame)
199
+ // use this to preload instead of lazy-loading it.
200
+ priority={blockIndex === 0}
201
+ />
202
+ );
203
+ }
204
+
205
+ /**
206
+ * Last line of defence before block content crosses into a client component, where
207
+ * everything is serialized into the RSC payload.
208
+ *
209
+ * Migration 27 removed `recipient_email` from every stored form block, but an install
210
+ * can still acquire one: a CSV/JSON import, a restored revision, or a fork that has not
211
+ * run the migration. Stripping it here means an un-migrated block degrades to "no
212
+ * recipient" (the server resolves one from settings) rather than publishing an address.
213
+ */
214
+ function stripServerOnlyContent(blockType: string, content: unknown): unknown {
215
+ if (blockType !== 'form' || !content || typeof content !== 'object') return content;
216
+ if (!('recipient_email' in (content as Record<string, unknown>))) return content;
217
+ const { recipient_email: _dropped, ...safe } = content as Record<string, unknown>;
218
+ return safe;
219
+ }
220
+
221
+ async function renderBlock(context: BlockRenderContext) {
222
+ const { block, blockIndex, languageId, visualEditAttributes, visualEditing } = context;
223
+
224
+ if (block.block_type === 'section') {
225
+ return (
226
+ <SectionBlockRenderer
227
+ content={block.content as unknown as SectionBlockContent}
228
+ languageId={languageId}
229
+ visualEditAttributes={visualEditAttributes}
230
+ visualEditing={visualEditing}
231
+ parentBlockId={block.id}
232
+ parentBlockIndex={blockIndex}
233
+ blockType={block.block_type}
234
+ botProtectionPublic={context.botProtectionPublic}
235
+ scriptNonce={context.scriptNonce}
236
+ />
237
+ );
238
+ }
239
+
240
+ return renderLoadedBlock(context);
241
+ }
242
+
243
+ export default async function BlockRenderer({
244
+ blocks,
245
+ languageId,
246
+ excludeProductId,
247
+ excludeTranslationGroupId,
248
+ visualEditing,
249
+ productVisualEditingEnabled,
250
+ }: BlockRendererProps) {
251
+ if (!blocks || blocks.length === 0) {
252
+ return null;
253
+ }
254
+
255
+ let botProtectionPublic: { provider: 'none' | 'turnstile' | 'recaptcha'; siteKey: string } | undefined;
256
+ let scriptNonce = '';
257
+
258
+ try {
259
+ scriptNonce = (await headers()).get('x-nonce') || '';
260
+ } catch (e) {
261
+ console.error("[Bot Protection] Error loading CSP nonce in BlockRenderer:", e);
262
+ }
263
+
264
+ try {
265
+ const supabase = createSupabaseServerClient();
266
+ const { data: publicSetting } = await supabase
267
+ .from('site_settings')
268
+ .select('value')
269
+ .eq('key', 'bot_protection_public')
270
+ .maybeSingle();
271
+ if (publicSetting?.value) {
272
+ const publicVal = publicSetting.value as Record<string, any>;
273
+ botProtectionPublic = {
274
+ provider: publicVal.provider || 'none',
275
+ siteKey: publicVal.siteKey || '',
276
+ };
277
+ }
278
+ } catch (e) {
279
+ console.error("[Bot Protection] Error loading settings in BlockRenderer:", e);
280
+ }
281
+
282
+ const renderedBlocks = await Promise.all(
283
+ blocks.map(async (block, blockIndex) => ({
284
+ id: block.id,
285
+ node: await renderBlock({
286
+ block,
287
+ blockIndex,
288
+ languageId,
289
+ excludeProductId,
290
+ excludeTranslationGroupId,
291
+ visualEditing,
292
+ productVisualEditingEnabled,
293
+ botProtectionPublic,
294
+ scriptNonce,
295
+ visualEditAttributes: buildVisualEditAttributes(visualEditing, {
296
+ kind: "top-level",
297
+ blockId: block.id,
298
+ blockIndex,
299
+ blockType: block.block_type,
300
+ }),
301
+ }),
302
+ }))
303
+ );
304
+
305
+ return (
306
+ <>
307
+ {renderedBlocks.map(({ id, node }) => (
308
+ <React.Fragment key={id}>{node}</React.Fragment>
309
+ ))}
310
+ </>
311
+ );
312
+ }