@shop-on/create-theme 0.9.0 → 0.10.0

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": "@shop-on/create-theme",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Scaffolds a Shop-On storefront theme: `npm create @shop-on/theme <dir>`.",
5
5
  "license": "SEE LICENSE IN dist/LICENSE.md",
6
6
  "bin": {
@@ -98,7 +98,7 @@ Pick the matching recipe and follow it end-to-end:
98
98
  - [Wire a picker (image/video/menu/collection/product_list/metaobject)](recipes/picker-data.md)
99
99
  - [Dynamic sources (editor "dynamic values")](recipes/dynamic-sources.md) — the loader-side resolution pass; raw `product_attribute:title` on the storefront means it's missing
100
100
  - [Design or optimize data fetching](recipes/data-fetching.md) — SSR, payload sizing, lazy interaction data, route loaders
101
- - [Let AI build sections and blocks](recipes/custom-sections.md) — opt in with `custom-section` / `custom-block` so a connected AI assistant can write a section when none you ship fits
101
+ - [AI-built sections and blocks](recipes/custom-sections.md) — the shipped `custom-section` / `custom-block`: how they work, the rules for changing them, what to do as the theme grows
102
102
  - [Add buyer auth to a theme](recipes/customer-auth.md) — consume the `@shop-on/theme-server` auth surface: bouncers, handoff consume, customer-aware cart, logout, header account control
103
103
  - [Add a translation key](recipes/locales.md)
104
104
  - [Input setting types reference](recipes/input-settings.md) — every supported `type`, value shape, gotchas
@@ -275,7 +275,7 @@ AI assistants connected to a store (Claude, ChatGPT) and `shop-on theme mcp` edi
275
275
  - **The rule is strict:** `ai/` holds exactly `guide.md` and `recipes/*.json`. No other file, subdir or dotfile — the build and the upload both refuse it.
276
276
  - **Recipes are checked at build — but only shallowly.** Every section/block type and setting id must exist, or `pnpm build` fails. Setting values are checked only when a merchant applies the recipe: a select value outside its options, an out-of-range number or a `palette:` ref the shop no longer has makes `apply_recipe` refuse the whole recipe. Keep literal values to the schema's options; leave colours to the theme's defaults.
277
277
  - **Optional params drop their line.** The editor tools store a rich-text value with nothing to show as `""` — `<p>{{tagline}}</p>` or `<a href="tel:{{phone}}">{{phone}}</a>` with the param omitted, or `<p>&nbsp;</p>` — so a theme that hides empty rich text drops it. A plain `text` setting, a button label or an FAQ row's question is not emptied for you: make that param required, or check the block renders nothing when it is blank.
278
- - **Custom sections need a guide section too.** If the theme ships `custom-section` / `custom-block`, `guide.md` says how to style one for this theme: see [custom-sections.md](recipes/custom-sections.md#6-tell-the-ai-how-to-style-for-your-theme).
278
+ - **Custom sections need a guide section too.** If the theme ships `custom-section` / `custom-block`, `guide.md` says how to style one for this theme, and changes with the theme's CSS variables: see [custom-sections.md](recipes/custom-sections.md#as-the-theme-grows).
279
279
  - **Keep it in step with the sections.** Adding, renaming or removing a section or block, or changing a setting the guide names, means editing `guide.md` and any recipe that uses it in the same change.
280
280
 
281
281
  ## Building in the editor (Save to source)
@@ -1,240 +1,42 @@
1
- # Let AI build sections and blocks (custom sections)
1
+ # AI-built sections and blocks (custom sections)
2
2
 
3
- When no section your theme ships fits what a merchant asks for ("a comparison table", "our three stores with opening hours"), an AI assistant connected to the store can write one. It writes Liquid, the platform validates it, and your theme renders the result. Your theme opts in by shipping two types:
3
+ When no section your theme ships fits what a merchant asks for ("a comparison table", "our three stores with opening hours"), an AI assistant connected to the store can write one. It writes Liquid, the platform validates it, and your theme renders the result. Two theme-shipped types make that possible:
4
4
 
5
5
  - `sections/custom-section.{json,tsx}`: an AI-built section, a band of its own on the page.
6
- - `blocks/custom-block.{json,tsx}`: an AI-built block inside a section that lists it (the product page's buy column, say).
6
+ - `blocks/custom-block.{json,tsx}`: an AI-built block inside a section that lists it (the product page's info column, say).
7
7
 
8
- Each file is the **capability gate** for its feature. A theme version without `custom-section` gets no custom sections, and one without `custom-block` gets no custom blocks. You can ship either one alone.
8
+ **The starter ships both, wired.** This recipe is what each piece does and the rules for changing it. Each file is also the **capability gate** for its feature: delete `custom-section` and the theme gets no custom sections; delete `custom-block` and it gets no custom blocks.
9
9
 
10
- ## What the AI writes, what you write
10
+ ## How it works
11
11
 
12
- An instance carries a `definition` field next to its `settings`: `{ settings: SchemaSetting[], liquid: string }`. The AI declares its own settings and writes the template. The values sit in the instance's ordinary `settings`, and its CSS goes in `custom_css`. You never read `definition`: the render pass turns it into HTML and deletes it before the component renders.
12
+ An instance carries a `definition` field next to its `settings`: `{ settings: SchemaSetting[], liquid: string }`. The AI declares its own settings and writes the template. The values sit in the instance's ordinary `settings`, and its CSS goes in `custom_css`. The theme never reads `definition`: the render pass turns it into HTML and deletes it before the component renders.
13
13
 
14
- You write the shell: the schema, a component that draws the finished HTML, and one call in `enrich()`.
14
+ | Piece | Where |
15
+ | ---------------------------------------------- | --------------------------------------------------------- |
16
+ | Section shell: width + padding settings | `src/sections/custom-section.json` |
17
+ | Draws the finished HTML, or the editor's error | `src/sections/custom-section.tsx` |
18
+ | Block (no settings, no shell) | `src/blocks/custom-block.{json,tsx}` |
19
+ | The render pass | `loadTemplate` in `src/server/settings.ts` |
20
+ | The section that takes custom blocks | `main-product` (`"blocks": [{ "type": "custom-block" }]`) |
21
+ | How the AI should style for this theme | `## Custom sections` in `src/ai/guide.md` |
15
22
 
16
- ## 1. The section schema: exactly four settings
23
+ ## Rules when you change them
17
24
 
18
- `src/sections/custom-section.json` declares only the shell, the four ids the contract reserves (`BASE_SETTING_IDS` in `@shop-on/theme-contract/custom-section`): `color_scheme`, `container`, `padding_top` and `padding_bottom`. Leave out `presets`: without one the type never shows in the merchant's "Add section" picker, and the AI adds instances with its own tool, `create_custom_section`. The model reads each setting as `settings.<id>`, so keep the ids exact.
25
+ - **The section declares only reserved ids.** The contract reserves four, `color_scheme`, `container`, `padding_top` and `padding_bottom` (`BASE_SETTING_IDS`, `@shop-on/theme-contract/custom-section`), and the AI reads them as `settings.<id>`. Any other id on the type could clash with one the AI declares. `custom-section.test.ts` pins the set.
26
+ - **No `presets` on the section.** Without one the type never shows in the merchant's "Add section" picker. The AI adds instances with its own tool, `create_custom_section`. (`theme:check` knows this and doesn't ask for presets.)
27
+ - **Render through `CustomSectionHtml`, never anything else.** Not a bare `dangerouslySetInnerHTML`, and never a Custom HTML snippet that re-activates `<script>` tags: AI-written markup must never run one. `CustomSectionHtml` doesn't activate scripts, and it hands same-origin link clicks to the router, so internal links navigate client-side and keep the editor's preview.
28
+ - **Empty renders nothing.** `customHtml` is `""` when there is nothing to draw, and the section returns `null` so it takes no space. `customError` exists only in editor preview, since the pass writes it only when the request carries an editor `sid`.
29
+ - **The block declares no settings at all**: every setting it has comes from its definition. It has no shell either. The section around it owns width and spacing, and the base ids read as `nil` inside a block.
30
+ - **The pass runs after `runEnrichment`.** The enrichment's last phase re-scans string settings, so rendered HTML has to land after it. If you add a Custom Liquid pass, run this one after that too. Keep the `import()` dynamic, so liquidjs stays out of the client bundle. A page with no custom section loads neither liquidjs nor the validator.
31
+ - **`localizePath` only takes a locale the shop serves.** `req.locale` is server-fn input, and a crafted one would turn a site path into another host's (`//evil.example/…`). That's what the `isValidLocale` guard is for.
19
32
 
20
- ```json
21
- {
22
- "name": "t:sections.custom_section",
23
- "tag": "section",
24
- "settings": [
25
- {
26
- "type": "color_scheme",
27
- "id": "color_scheme",
28
- "label": "t:settings.color_scheme",
29
- "default": "scheme_1"
30
- },
31
- {
32
- "type": "select",
33
- "id": "container",
34
- "label": "t:settings.content_width",
35
- "options": [
36
- { "value": "small", "label": "t:content_width_options.small" },
37
- { "value": "medium", "label": "t:content_width_options.medium" },
38
- { "value": "large", "label": "t:content_width_options.large" },
39
- { "value": "page", "label": "t:content_width_options.page" },
40
- { "value": "full", "label": "t:content_width_options.full" }
41
- ],
42
- "default": "page"
43
- },
44
- {
45
- "type": "range",
46
- "id": "padding_top",
47
- "label": "t:settings.padding_top",
48
- "min": 0,
49
- "max": 100,
50
- "step": 4,
51
- "unit": "px",
52
- "default": 0
53
- },
54
- {
55
- "type": "range",
56
- "id": "padding_bottom",
57
- "label": "t:settings.padding_bottom",
58
- "min": 0,
59
- "max": 100,
60
- "step": 4,
61
- "unit": "px",
62
- "default": 0
63
- }
64
- ]
65
- }
66
- ```
33
+ ## As the theme grows
67
34
 
68
- Pin the set with a test, so a fifth setting can't slip in:
69
-
70
- ```ts
71
- import { BASE_SETTING_IDS } from "@shop-on/theme-contract/custom-section";
72
- import { expect, it } from "vitest";
73
- import schema from "./custom-section.json";
74
-
75
- it("declares exactly the base settings the custom-section contract reserves", () => {
76
- const ids = schema.settings.flatMap((s) => ("id" in s ? [s.id] : []));
77
- expect(ids.toSorted()).toEqual(BASE_SETTING_IDS.toSorted());
78
- });
79
- ```
80
-
81
- ## 2. The section component
82
-
83
- The pass hands you two strings: `customHtml` (the finished markup, `""` when there is nothing to draw) and `customError` (editor preview only, since the pass writes it only when the request carries an editor `sid`). Draw the HTML through `CustomSectionHtml`:
84
-
85
- ```tsx
86
- import { useTranslations } from "@shop-on/i18n";
87
- import { CustomSectionHtml } from "@shop-on/theme-react/custom-section-html";
88
-
89
- const WIDTHS: Record<string, string> = { small: "44rem", medium: "60rem", large: "78rem" };
90
-
91
- export default function CustomSectionSection({
92
- sectionId,
93
- color_scheme = "scheme_1",
94
- customHtml = null,
95
- customError = null,
96
- container = "page",
97
- padding_top = 0,
98
- padding_bottom = 0,
99
- }: {
100
- sectionId?: string;
101
- color_scheme?: string | null;
102
- customHtml?: string | null;
103
- customError?: string | null;
104
- container?: string | null;
105
- padding_top?: number | null;
106
- padding_bottom?: number | null;
107
- }) {
108
- const t = useTranslations("custom_section");
109
- if (!customError && !customHtml?.trim()) return null;
110
-
111
- const measure = WIDTHS[container ?? "page"];
112
- const body = customError ? (
113
- <p className="border p-4">
114
- {t("error")}: {customError}
115
- </p>
116
- ) : (
117
- <CustomSectionHtml html={customHtml ?? ""} />
118
- );
119
-
120
- return (
121
- <section
122
- data-section-id={sectionId}
123
- data-color-scheme={color_scheme ?? undefined}
124
- className="bg-background text-foreground"
125
- style={{ paddingTop: `${padding_top ?? 0}px`, paddingBottom: `${padding_bottom ?? 0}px` }}
126
- >
127
- <div className={container === "full" ? undefined : "mx-auto max-w-6xl px-6"}>
128
- {measure ? (
129
- <div className="mx-auto w-full" style={{ maxWidth: measure }}>
130
- {body}
131
- </div>
132
- ) : (
133
- body
134
- )}
135
- </div>
136
- </section>
137
- );
138
- }
139
- ```
140
-
141
- - **Never render `customHtml` through your Custom HTML snippet** or with a bare `dangerouslySetInnerHTML`. The Custom HTML snippet re-activates `<script>` tags, and AI-written markup must never run one. `CustomSectionHtml` doesn't activate scripts, and it hands same-origin link clicks to the router, so internal links navigate client-side and keep the editor's preview.
142
- - **Empty renders nothing**, as `custom-liquid` does. A section with no output takes no space on the page.
143
- - Map `container` onto your own width vocabulary. `page` is your theme container (the starter's is `mx-auto max-w-6xl px-6`) and `full` is edge to edge.
144
- - Keep `color_scheme` even if your theme has no color schemes yet: the id is reserved, and the AI reads it. Put the value on `data-color-scheme` so your scheme CSS applies once you add some.
145
-
146
- ## 3. Run the pass in `enrich()`
147
-
148
- In `src/server/settings.ts`, after `runEnrichment` (and after the Custom Liquid pass, if your theme has one), call `renderCustomSections`. The enrichment's last phase re-scans string settings, so rendered HTML has to land after it. Import it dynamically, as the other loaders are, so liquidjs stays out of the client bundle:
149
-
150
- ```ts
151
- import { isValidLocale } from "@/src/lib/i18n"; // top of the file
152
-
153
- // inside enrich():
154
- const [{ renderCustomSections }] = await Promise.all([
155
- import("@shop-on/theme-loader/custom-sections"),
156
- // …your other dynamic imports
157
- ]);
158
- await runEnrichment(loaderConfig, template, enrichAdapter, req);
159
-
160
- // Only a locale the shop serves may prefix a path: `req.locale` is server-fn
161
- // input, and a crafted one would turn a site path into another host's.
162
- const pathLocale = isValidLocale(req.locale) ? req.locale : undefined;
163
- await renderCustomSections(loaderConfig, template, {
164
- sid: req.sid,
165
- locale: req.locale,
166
- // If your TemplateRequest carries them (the starter's carries only sid + locale):
167
- // product: req.product, // the route product, product pages only
168
- // getCollection: req.getCollection, // the route collection, lazily, collection pages only
169
- localizePath: (path) => (pathLocale ? `/${pathLocale}${path === "/" ? "" : path}` : path),
170
- });
171
- ```
172
-
173
- - `product` and `getCollection` are optional. Without them, the template's `product` / `collection` drops are `nil` on the route page, but pickers the AI declared still resolve. Pass them once your product and collection routes load the route resource through `settings.ts` (see [dynamic-sources.md](dynamic-sources.md)).
174
- - `localizePath` gives the template's `link_url` the request's locale prefix, so a crawler and a no-JS load get the right address. Leave it out and links stay unprefixed until clicked.
175
- - A page with no enabled custom section loads neither liquidjs nor the validator, so the call costs nothing elsewhere.
176
-
177
- ## 4. Custom blocks (optional)
178
-
179
- `src/blocks/custom-block.json` declares **no settings**: every setting a block has is one its definition declares, and a type-level id could clash with one.
180
-
181
- ```json
182
- { "name": "t:blocks.custom_block", "settings": [] }
183
- ```
184
-
185
- The component draws `customHtml` with no shell of its own. The section around it owns the scheme, width and spacing:
186
-
187
- ```tsx
188
- import { useTranslations } from "@shop-on/i18n";
189
- import { CustomSectionHtml } from "@shop-on/theme-react/custom-section-html";
190
-
191
- export default function CustomBlock({
192
- customHtml = null,
193
- customError = null,
194
- }: {
195
- customHtml?: string | null;
196
- customError?: string | null;
197
- }) {
198
- const t = useTranslations("custom_section");
199
- if (customError)
200
- return (
201
- <p className="border p-4">
202
- {t("block_error")}: {customError}
203
- </p>
204
- );
205
- return <CustomSectionHtml html={customHtml ?? ""} />;
206
- }
207
- ```
208
-
209
- Then **list it** in the `blocks` of each section that should take one, typically `main-product`: `{ "type": "custom-block" }`. A container block can list it too. `create_custom_block` refuses any section that doesn't.
210
-
211
- **Drop empty ones from your spacing.** An AI block that rendered nothing still sits in `blocks`. If the section wraps each block in a row with a gap, skip it with `hasCustomOutput`, or it opens an empty gap:
212
-
213
- ```tsx
214
- import { hasCustomOutput } from "@shop-on/theme-react/custom-section-html";
215
-
216
- const visible = blocks.filter((b) => b.type !== "custom-block" || hasCustomOutput(b.settings));
217
- ```
218
-
219
- ## 5. Locales
220
-
221
- Add the display names and the editor-only error labels, in every catalog you ship:
222
-
223
- - `*.schema.json`: `sections.custom_section` ("AI-built section") and `blocks.custom_block` ("AI-built block").
224
- - `*.json`: `custom_section.error` ("Section error") and `custom_section.block_error` ("Block error").
225
- - `*.schema.json`, if your catalog lacks them: the labels the section schema names, `settings.color_scheme`, `settings.content_width`, `settings.padding_top`, `settings.padding_bottom` and `content_width_options.{small,medium,large,page,full}`. A fresh starter has none of them.
226
-
227
- `pnpm theme:check` lists any key still missing.
228
-
229
- ## 6. Tell the AI how to style for your theme
230
-
231
- The AI's markup can't use your Tailwind classes: Tailwind emits only the classes it finds in your source, and the AI's HTML isn't in it. It writes plain CSS into `custom_css`. Add a `## Custom sections` section to `src/ai/guide.md` that says:
232
-
233
- - which CSS variables to use for color (the starter's are `--color-background`, `--color-foreground`, `--color-muted`, `--color-border`, `--color-accent` and `--color-accent-foreground`; name the ones that follow the color scheme, if you have schemes), plus your font and spacing variables;
234
- - that the shell already provides background, width and padding, so its markup needs no outer background or page margins;
235
- - your root font size, if `1rem` isn't 16px;
236
- - when to build one: only when no section you ship does the job, after checking their settings and blocks;
237
- - for blocks, which sections take one, and to keep them compact with no outer padding or background.
35
+ - **Adding color schemes:** the starter's section leaves out `color_scheme`, because with no schemes its picker would do nothing. When you add a `color_scheme_group` to the theme settings, add a `color_scheme` setting to `custom-section.json`, put its value on `data-color-scheme` on the section root, add the `settings.color_scheme` label to every schema catalog, and switch `custom-section.test.ts` to expect all four ids. Then tell the guide which CSS variables follow the scheme.
36
+ - **Loading the route product or collection in `settings.ts`:** pass `product` (the `ProductData`) and `getCollection` (a lazy provider) to `renderCustomSections`. Until you do, the template's `product` / `collection` drops are `nil` on those pages, but pickers the AI declared still resolve. See [dynamic-sources.md](dynamic-sources.md) for loading the route resource.
37
+ - **Letting another section take custom blocks:** add `{ "type": "custom-block" }` to its `blocks`. A container block can list it too. `create_custom_block` refuses any section that doesn't.
38
+ - **Drop empty blocks from your spacing.** An AI block that rendered nothing still sits in `blocks`. A section that wraps each block in a spaced row has to skip it, or it opens an empty gap. `main-product` shows how: `blocks.filter((b) => b.type !== "custom-block" || hasCustomOutput(b.settings))`, with `hasCustomOutput` from `@shop-on/theme-react/custom-section-html`.
39
+ - **Restyling the theme:** keep the guide's `## Custom sections` honest. The AI's HTML renders inside your page, so your stylesheet applies, and the AI is told to use the classes and CSS variables the guide names. Name your own heading, text and button classes there (`.button`, `.h2`: classes your stylesheet defines outright), and say whether plain `h1`–`h6` are styled (Tailwind's preflight resets them unless your base styles put them back). Don't name Tailwind utilities: Tailwind emits only the ones your own source uses, so the rest don't exist. Everything else the AI writes as plain CSS in `custom_css` against the variables the guide names. Rename a class or variable, and the guide changes in the same commit. Also tell it your root font size if `1rem` isn't 16px.
238
40
 
239
41
  ## What the AI can and can't do
240
42
 
@@ -526,7 +526,7 @@ Hide a setting based on a sibling's value:
526
526
  - Evaluated by the editor as a small subset of Liquid: `==` / `!=` against a quoted literal or `blank`, `<` `<=` `>` `>=` on numbers, a bare `settings.<id>` for truthiness, `and` / `or`, and parentheses.
527
527
  - **`and` / `or` read right to left, like Liquid, with no precedence:** `a and b or c` is `a and (b or c)`. When you mean `(a and b) or c`, write the parentheses.
528
528
  - **An unsaved setting reads as its schema `default`**, as it renders on the storefront. So a checkbox that defaults on gates its dependents with a bare `{{ settings.show_x }}` (or `== true`), and they still show on an instance that never saved it.
529
- - **Gate a field only when it does nothing**: a hidden field that still worked is a setting the merchant can no longer reach.
529
+ - **Gate a field only when it does nothing**: a hidden field that still worked is a setting the merchant can no longer reach. A `!= blank` gate on a picker also hides its dependents while the picker is bound to a dynamic source, because a binding is not stored in `settings`.
530
530
 
531
531
  ---
532
532
 
@@ -17,14 +17,14 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@bprogress/core": "1.3.4",
20
- "@shop-on/i18n": "^0.9.0",
21
- "@shop-on/theme-contract": "^0.9.0",
22
- "@shop-on/theme-loader": "^0.9.0",
23
- "@shop-on/theme-react": "^0.9.0",
24
- "@shop-on/theme-routes": "^0.9.0",
25
- "@shop-on/theme-runtime": "^0.9.0",
26
- "@shop-on/theme-server": "^0.9.0",
27
- "@shop-on/theme-system": "^0.9.0",
20
+ "@shop-on/i18n": "^0.10.0",
21
+ "@shop-on/theme-contract": "^0.10.0",
22
+ "@shop-on/theme-loader": "^0.10.0",
23
+ "@shop-on/theme-react": "^0.10.0",
24
+ "@shop-on/theme-routes": "^0.10.0",
25
+ "@shop-on/theme-runtime": "^0.10.0",
26
+ "@shop-on/theme-server": "^0.10.0",
27
+ "@shop-on/theme-system": "^0.10.0",
28
28
  "@tailwindcss/vite": "4.3.3",
29
29
  "@tanstack/react-router": "1.170.45",
30
30
  "@tanstack/react-start": "1.169.3",
@@ -35,8 +35,8 @@
35
35
  "tailwindcss": "4.3.3"
36
36
  },
37
37
  "devDependencies": {
38
- "@shop-on/theme-config": "^0.9.0",
39
- "@shop-on/theme-dev-host": "^0.9.0",
38
+ "@shop-on/theme-config": "^0.10.0",
39
+ "@shop-on/theme-dev-host": "^0.10.0",
40
40
  "@spiriit/vite-plugin-svg-spritemap": "7.2.0",
41
41
  "@types/node": "26.6.5",
42
42
  "@types/react": "19.3.0",
@@ -22,6 +22,31 @@ one they won't reach for.
22
22
  (`cta_label`, `cta_url`). Keep the headline short; leave the button out
23
23
  rather than pointing it nowhere.
24
24
 
25
+ ## Custom sections
26
+
27
+ Build a custom section only when no section above can do the job, after
28
+ checking their settings. Its width (`container`: small, medium, large, page or
29
+ full) and padding come from the theme, so its own markup needs no outer
30
+ background or page margins.
31
+
32
+ The theme's utility classes don't exist inside it: write plain CSS in the
33
+ section's CSS against these variables:
34
+
35
+ - Colors: `--color-background`, `--color-foreground` (text), `--color-muted`
36
+ (secondary text), `--color-border` (hairlines), `--color-accent` (buttons
37
+ and links) and `--color-accent-foreground` (text on the accent).
38
+
39
+ Use the variables rather than fixed colors, so the section follows the theme
40
+ when its palette changes.
41
+
42
+ ## Custom blocks
43
+
44
+ For content that belongs in the product page's info column rather than as its
45
+ own band (a delivery note, a size hint, a trust badge), build a custom block
46
+ with `create_custom_block` in `main-product`, the one section that takes one.
47
+ It follows the CSS rules above, but the section around it owns the width and
48
+ spacing: keep it compact, with no outer padding or background of its own.
49
+
25
50
  ## What to avoid
26
51
 
27
52
  - Don't stack two `hero` sections.
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "t:blocks.custom_block",
3
+ "settings": []
4
+ }
@@ -0,0 +1,16 @@
1
+ import { expect, it } from "vitest";
2
+ import mainProduct from "../sections/main-product.json";
3
+ import schema from "./custom-block.json";
4
+
5
+ // A custom block's settings are the ones its `definition` declares, and a
6
+ // declared id may not repeat one of the type's: any setting here could clash
7
+ // with a declared one.
8
+ it("declares no settings of its own", () => {
9
+ expect(schema.settings).toEqual([]);
10
+ });
11
+
12
+ // The case for custom blocks: AI-written content in the product page's info
13
+ // column. `create_custom_block` refuses a section that doesn't list the type.
14
+ it("is one of the blocks the product information section takes", () => {
15
+ expect(mainProduct.blocks.map((b) => b.type)).toContain("custom-block");
16
+ });
@@ -0,0 +1,26 @@
1
+ import { useTranslations } from "@shop-on/i18n";
2
+ import { CustomSectionHtml } from "@shop-on/theme-react/custom-section-html";
3
+
4
+ // A block an AI assistant wrote inside a section that lists `custom-block`
5
+ // (main-product's info column): rendered on the server by the same pass as a
6
+ // custom section, arriving as `customHtml`. No shell of its own: the section
7
+ // around it owns the width and spacing.
8
+ export default function CustomBlock({
9
+ customHtml = null,
10
+ customError = null,
11
+ }: {
12
+ customHtml?: string | null;
13
+ customError?: string | null;
14
+ }) {
15
+ const t = useTranslations("custom_section");
16
+
17
+ // Editor-only by construction: the pass writes `customError` only when the
18
+ // request carries an editor `sid`.
19
+ if (customError)
20
+ return (
21
+ <p className="rounded-lg border border-border p-4 text-sm text-muted">
22
+ {t("block_error")}: {customError}
23
+ </p>
24
+ );
25
+ return <CustomSectionHtml html={customHtml ?? ""} />;
26
+ }
@@ -37,3 +37,12 @@ export function publicPath(pathname: string): string {
37
37
  if (!getCurrentLocale()) return pathname;
38
38
  return localizeUrl(new URL(pathname, "http://internal")).pathname;
39
39
  }
40
+
41
+ /** The public path for a site path in an EXPLICIT content locale (undefined on
42
+ * the primary one), for server code that holds the request's locale rather
43
+ * than the ambient one: the custom-section pass's `localizePath`. The raw
44
+ * string is prefixed, so a query survives. */
45
+ export function localizedPath(path: string, locale: string | undefined): string {
46
+ if (!locale) return path;
47
+ return `/${locale}${path === "/" ? "" : path}`;
48
+ }
@@ -7,6 +7,10 @@
7
7
  "empty": "Your cart is empty.",
8
8
  "heading": "Your cart"
9
9
  },
10
+ "custom_section": {
11
+ "block_error": "Block error",
12
+ "error": "Section error"
13
+ },
10
14
  "footer": {
11
15
  "platform_name": "Cody",
12
16
  "powered_by": "Powered by"
@@ -26,7 +26,11 @@
26
26
  "main_article": "Article",
27
27
  "main_search": "Search results",
28
28
  "main_policy": "Policy",
29
- "main_password": "Password"
29
+ "main_password": "Password",
30
+ "custom_section": "AI-built section"
31
+ },
32
+ "blocks": {
33
+ "custom_block": "AI-built block"
30
34
  },
31
35
  "names": {
32
36
  "custom_css": "Custom CSS"
@@ -42,7 +46,17 @@
42
46
  "cta_label": "Button label",
43
47
  "cta_url": "Button link",
44
48
  "heading": "Heading",
45
- "message": "Message"
49
+ "message": "Message",
50
+ "content_width": "Content width",
51
+ "padding_top": "Top padding",
52
+ "padding_bottom": "Bottom padding"
53
+ },
54
+ "content_width_options": {
55
+ "small": "Narrow",
56
+ "medium": "Medium",
57
+ "large": "Wide",
58
+ "page": "Page width",
59
+ "full": "Full width"
46
60
  },
47
61
  "info": {
48
62
  "custom_css": "Applies to every page. Target a section with its `.section-<type>` class, a block with `.block-<type>`."
@@ -7,6 +7,10 @@
7
7
  "empty": "Таны сагс хоосон байна.",
8
8
  "heading": "Таны сагс"
9
9
  },
10
+ "custom_section": {
11
+ "block_error": "Блокийн алдаа",
12
+ "error": "Хэсгийн алдаа"
13
+ },
10
14
  "footer": {
11
15
  "platform_name": "Cody",
12
16
  "powered_by": "Powered by"
@@ -26,7 +26,11 @@
26
26
  "main_article": "Нийтлэл",
27
27
  "main_search": "Хайлтын үр дүн",
28
28
  "main_policy": "Бодлого",
29
- "main_password": "Нууц үг"
29
+ "main_password": "Нууц үг",
30
+ "custom_section": "AI бүтээсэн хэсэг"
31
+ },
32
+ "blocks": {
33
+ "custom_block": "AI бүтээсэн блок"
30
34
  },
31
35
  "names": {
32
36
  "custom_css": "Өөрийн CSS"
@@ -42,7 +46,17 @@
42
46
  "cta_label": "Товчны бичиг",
43
47
  "cta_url": "Товчны холбоос",
44
48
  "heading": "Гарчиг",
45
- "message": "Мессеж"
49
+ "message": "Мессеж",
50
+ "content_width": "Агуулгын өргөн",
51
+ "padding_top": "Дээд зай",
52
+ "padding_bottom": "Доод зай"
53
+ },
54
+ "content_width_options": {
55
+ "small": "Нарийн",
56
+ "medium": "Дунд",
57
+ "large": "Өргөн",
58
+ "page": "Хуудасны өргөн",
59
+ "full": "Бүтэн өргөн"
46
60
  },
47
61
  "info": {
48
62
  "custom_css": "Бүх хуудсанд үйлчилнэ. Хэсгийг `.section-<type>`, блокийг `.block-<type>` классаар онилно."
@@ -29,6 +29,7 @@ import { Route as Char123LocaleChar125AccountVerifyRouteImport } from './routes/
29
29
  import { Route as Char123LocaleChar125BlogsBlogHandleRouteImport } from './routes/{-$locale}/blogs/$blogHandle'
30
30
  import { Route as Char123LocaleChar125CollectionsIndexRouteImport } from './routes/{-$locale}/collections/index'
31
31
  import { Route as Char123LocaleChar125CollectionsCollectionHandleRouteImport } from './routes/{-$locale}/collections/$collectionHandle'
32
+ import { Route as Char123LocaleChar125OrdersFindRouteImport } from './routes/{-$locale}/orders/find'
32
33
  import { Route as Char123LocaleChar125PagesHandleRouteImport } from './routes/{-$locale}/pages/$handle'
33
34
  import { Route as Char123LocaleChar125PoliciesHandleRouteImport } from './routes/{-$locale}/policies/$handle'
34
35
  import { Route as Char123LocaleChar125PreviewSectionRouteImport } from './routes/{-$locale}/preview/section'
@@ -148,6 +149,12 @@ const Char123LocaleChar125CollectionsCollectionHandleRoute =
148
149
  path: '/collections/$collectionHandle',
149
150
  getParentRoute: () => Char123LocaleChar125Route,
150
151
  } as any)
152
+ const Char123LocaleChar125OrdersFindRoute =
153
+ Char123LocaleChar125OrdersFindRouteImport.update({
154
+ id: '/orders/find',
155
+ path: '/orders/find',
156
+ getParentRoute: () => Char123LocaleChar125Route,
157
+ } as any)
151
158
  const Char123LocaleChar125PagesHandleRoute =
152
159
  Char123LocaleChar125PagesHandleRouteImport.update({
153
160
  id: '/pages/$handle',
@@ -206,6 +213,7 @@ export interface FileRoutesByFullPath {
206
213
  '/{-$locale}/account/verify': typeof Char123LocaleChar125AccountVerifyRoute
207
214
  '/{-$locale}/blogs/$blogHandle': typeof Char123LocaleChar125BlogsBlogHandleRoute
208
215
  '/{-$locale}/collections/$collectionHandle': typeof Char123LocaleChar125CollectionsCollectionHandleRoute
216
+ '/{-$locale}/orders/find': typeof Char123LocaleChar125OrdersFindRoute
209
217
  '/{-$locale}/pages/$handle': typeof Char123LocaleChar125PagesHandleRoute
210
218
  '/{-$locale}/policies/$handle': typeof Char123LocaleChar125PoliciesHandleRoute
211
219
  '/{-$locale}/preview/section': typeof Char123LocaleChar125PreviewSectionRoute
@@ -233,6 +241,7 @@ export interface FileRoutesByTo {
233
241
  '/{-$locale}/account/verify': typeof Char123LocaleChar125AccountVerifyRoute
234
242
  '/{-$locale}/blogs/$blogHandle': typeof Char123LocaleChar125BlogsBlogHandleRoute
235
243
  '/{-$locale}/collections/$collectionHandle': typeof Char123LocaleChar125CollectionsCollectionHandleRoute
244
+ '/{-$locale}/orders/find': typeof Char123LocaleChar125OrdersFindRoute
236
245
  '/{-$locale}/pages/$handle': typeof Char123LocaleChar125PagesHandleRoute
237
246
  '/{-$locale}/policies/$handle': typeof Char123LocaleChar125PoliciesHandleRoute
238
247
  '/{-$locale}/preview/section': typeof Char123LocaleChar125PreviewSectionRoute
@@ -262,6 +271,7 @@ export interface FileRoutesById {
262
271
  '/{-$locale}/account/verify': typeof Char123LocaleChar125AccountVerifyRoute
263
272
  '/{-$locale}/blogs/$blogHandle': typeof Char123LocaleChar125BlogsBlogHandleRoute
264
273
  '/{-$locale}/collections/$collectionHandle': typeof Char123LocaleChar125CollectionsCollectionHandleRoute
274
+ '/{-$locale}/orders/find': typeof Char123LocaleChar125OrdersFindRoute
265
275
  '/{-$locale}/pages/$handle': typeof Char123LocaleChar125PagesHandleRoute
266
276
  '/{-$locale}/policies/$handle': typeof Char123LocaleChar125PoliciesHandleRoute
267
277
  '/{-$locale}/preview/section': typeof Char123LocaleChar125PreviewSectionRoute
@@ -292,6 +302,7 @@ export interface FileRouteTypes {
292
302
  | '/{-$locale}/account/verify'
293
303
  | '/{-$locale}/blogs/$blogHandle'
294
304
  | '/{-$locale}/collections/$collectionHandle'
305
+ | '/{-$locale}/orders/find'
295
306
  | '/{-$locale}/pages/$handle'
296
307
  | '/{-$locale}/policies/$handle'
297
308
  | '/{-$locale}/preview/section'
@@ -319,6 +330,7 @@ export interface FileRouteTypes {
319
330
  | '/{-$locale}/account/verify'
320
331
  | '/{-$locale}/blogs/$blogHandle'
321
332
  | '/{-$locale}/collections/$collectionHandle'
333
+ | '/{-$locale}/orders/find'
322
334
  | '/{-$locale}/pages/$handle'
323
335
  | '/{-$locale}/policies/$handle'
324
336
  | '/{-$locale}/preview/section'
@@ -347,6 +359,7 @@ export interface FileRouteTypes {
347
359
  | '/{-$locale}/account/verify'
348
360
  | '/{-$locale}/blogs/$blogHandle'
349
361
  | '/{-$locale}/collections/$collectionHandle'
362
+ | '/{-$locale}/orders/find'
350
363
  | '/{-$locale}/pages/$handle'
351
364
  | '/{-$locale}/policies/$handle'
352
365
  | '/{-$locale}/preview/section'
@@ -509,6 +522,13 @@ declare module '@tanstack/react-router' {
509
522
  preLoaderRoute: typeof Char123LocaleChar125CollectionsCollectionHandleRouteImport
510
523
  parentRoute: typeof Char123LocaleChar125Route
511
524
  }
525
+ '/{-$locale}/orders/find': {
526
+ id: '/{-$locale}/orders/find'
527
+ path: '/orders/find'
528
+ fullPath: '/{-$locale}/orders/find'
529
+ preLoaderRoute: typeof Char123LocaleChar125OrdersFindRouteImport
530
+ parentRoute: typeof Char123LocaleChar125Route
531
+ }
512
532
  '/{-$locale}/pages/$handle': {
513
533
  id: '/{-$locale}/pages/$handle'
514
534
  path: '/pages/$handle'
@@ -566,6 +586,7 @@ interface Char123LocaleChar125RouteChildren {
566
586
  Char123LocaleChar125AccountVerifyRoute: typeof Char123LocaleChar125AccountVerifyRoute
567
587
  Char123LocaleChar125BlogsBlogHandleRoute: typeof Char123LocaleChar125BlogsBlogHandleRoute
568
588
  Char123LocaleChar125CollectionsCollectionHandleRoute: typeof Char123LocaleChar125CollectionsCollectionHandleRoute
589
+ Char123LocaleChar125OrdersFindRoute: typeof Char123LocaleChar125OrdersFindRoute
569
590
  Char123LocaleChar125PagesHandleRoute: typeof Char123LocaleChar125PagesHandleRoute
570
591
  Char123LocaleChar125PoliciesHandleRoute: typeof Char123LocaleChar125PoliciesHandleRoute
571
592
  Char123LocaleChar125PreviewSectionRoute: typeof Char123LocaleChar125PreviewSectionRoute
@@ -592,6 +613,7 @@ const Char123LocaleChar125RouteChildren: Char123LocaleChar125RouteChildren = {
592
613
  Char123LocaleChar125BlogsBlogHandleRoute,
593
614
  Char123LocaleChar125CollectionsCollectionHandleRoute:
594
615
  Char123LocaleChar125CollectionsCollectionHandleRoute,
616
+ Char123LocaleChar125OrdersFindRoute: Char123LocaleChar125OrdersFindRoute,
595
617
  Char123LocaleChar125PagesHandleRoute: Char123LocaleChar125PagesHandleRoute,
596
618
  Char123LocaleChar125PoliciesHandleRoute:
597
619
  Char123LocaleChar125PoliciesHandleRoute,
@@ -0,0 +1,13 @@
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+ import { orderLookupRouteOptions } from "@shop-on/theme-routes";
3
+ import { routeAdapter } from "@/src/route-adapter";
4
+
5
+ // The address a merchant links for "Find an order": the account app holds the
6
+ // lookup, so this path on the storefront host only bounces there. Thrown from
7
+ // `beforeLoad`, like the account bounces, so the root loader never runs.
8
+ const { validateSearch, beforeLoad } = orderLookupRouteOptions(routeAdapter.account);
9
+
10
+ export const Route = createFileRoute("/{-$locale}/orders/find")({
11
+ validateSearch,
12
+ beforeLoad,
13
+ });
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "t:sections.custom_section",
3
+ "tag": "section",
4
+ "settings": [
5
+ {
6
+ "type": "select",
7
+ "id": "container",
8
+ "label": "t:settings.content_width",
9
+ "options": [
10
+ { "value": "small", "label": "t:content_width_options.small" },
11
+ { "value": "medium", "label": "t:content_width_options.medium" },
12
+ { "value": "large", "label": "t:content_width_options.large" },
13
+ { "value": "page", "label": "t:content_width_options.page" },
14
+ { "value": "full", "label": "t:content_width_options.full" }
15
+ ],
16
+ "default": "page"
17
+ },
18
+ {
19
+ "type": "range",
20
+ "id": "padding_top",
21
+ "label": "t:settings.padding_top",
22
+ "min": 0,
23
+ "max": 100,
24
+ "step": 4,
25
+ "unit": "px",
26
+ "default": 0
27
+ },
28
+ {
29
+ "type": "range",
30
+ "id": "padding_bottom",
31
+ "label": "t:settings.padding_bottom",
32
+ "min": 0,
33
+ "max": 100,
34
+ "step": 4,
35
+ "unit": "px",
36
+ "default": 0
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,14 @@
1
+ import { BASE_SETTING_IDS } from "@shop-on/theme-contract/custom-section";
2
+ import { expect, it } from "vitest";
3
+ import schema from "./custom-section.json";
4
+
5
+ // A custom section's template reads the contract's base settings
6
+ // (`settings.container`, …) beside its own declared ones, whose ids may not
7
+ // reuse a base id. A setting here outside the contract would let a template
8
+ // read a value the contract doesn't know about. `color_scheme` is the one base
9
+ // id left out: the theme has no color schemes yet, so its picker would do
10
+ // nothing. Declare it when the schemes arrive.
11
+ it("declares the contract's base settings, but color_scheme", () => {
12
+ const ids = schema.settings.flatMap((s) => ("id" in s ? [s.id] : []));
13
+ expect(ids.toSorted()).toEqual(BASE_SETTING_IDS.filter((id) => id !== "color_scheme").toSorted());
14
+ });
@@ -0,0 +1,73 @@
1
+ import type { CSSProperties } from "react";
2
+ import { useTranslations } from "@shop-on/i18n";
3
+ import { CustomSectionHtml } from "@shop-on/theme-react/custom-section-html";
4
+
5
+ // `page` is the theme container and `full` is edge to edge; the rest cap the
6
+ // content's measure inside the container.
7
+ const WIDTHS: Record<string, string> = {
8
+ small: "44rem",
9
+ medium: "60rem",
10
+ large: "78rem",
11
+ };
12
+
13
+ // A section an AI assistant wrote: Liquid the custom-section pass
14
+ // (`renderCustomSections`, @shop-on/theme-loader/custom-sections, called from
15
+ // `loadTemplate` in src/server/settings.ts) validated and rendered on the
16
+ // server, arriving here as a finished HTML string on `customHtml`. The
17
+ // instance's `definition` (its template and declared settings) never reaches
18
+ // this component: the pass deletes it.
19
+ //
20
+ // Rendered through the shared `CustomSectionHtml`, never a raw
21
+ // `dangerouslySetInnerHTML` or a Custom HTML snippet that re-activates
22
+ // `<script>` tags: model-written markup must not run one. `CustomSectionHtml`
23
+ // also hands clicks on its internal links to the router.
24
+ export default function CustomSection({
25
+ sectionId,
26
+ customHtml = null,
27
+ customError = null,
28
+ container = "page",
29
+ padding_top = 0,
30
+ padding_bottom = 0,
31
+ }: {
32
+ sectionId?: string;
33
+ customHtml?: string | null;
34
+ customError?: string | null;
35
+ container?: string | null;
36
+ padding_top?: number | null;
37
+ padding_bottom?: number | null;
38
+ }) {
39
+ const t = useTranslations("custom_section");
40
+
41
+ // Nothing rendered, nothing shown. An error shows only in the editor: the
42
+ // pass writes `customError` only when the request carries an editor `sid`.
43
+ if (!customError && !customHtml?.trim()) return null;
44
+
45
+ const measure = WIDTHS[container ?? "page"];
46
+ const body = customError ? (
47
+ <p className="rounded-lg border border-border p-4 text-sm text-muted">
48
+ {t("error")}: {customError}
49
+ </p>
50
+ ) : (
51
+ <CustomSectionHtml html={customHtml ?? ""} />
52
+ );
53
+
54
+ return (
55
+ <section
56
+ data-section-id={sectionId}
57
+ style={{ paddingTop: `${padding_top ?? 0}px`, paddingBottom: `${padding_bottom ?? 0}px` }}
58
+ >
59
+ <div className={container === "full" ? undefined : "mx-auto max-w-6xl px-6"}>
60
+ {measure ? (
61
+ <div
62
+ className="mx-auto w-full max-w-(--cs-w)"
63
+ style={{ "--cs-w": measure } as CSSProperties}
64
+ >
65
+ {body}
66
+ </div>
67
+ ) : (
68
+ body
69
+ )}
70
+ </div>
71
+ </section>
72
+ );
73
+ }
@@ -21,7 +21,12 @@
21
21
  "default": "t:text_defaults.hero_body"
22
22
  },
23
23
  { "type": "text", "id": "cta_label", "label": "t:settings.cta_label" },
24
- { "type": "url", "id": "cta_url", "label": "t:settings.cta_url" }
24
+ {
25
+ "type": "url",
26
+ "id": "cta_url",
27
+ "label": "t:settings.cta_url",
28
+ "visible_if": "{{ section.settings.cta_label != blank }}"
29
+ }
25
30
  ],
26
31
  "presets": [{ "name": "t:sections.hero" }]
27
32
  }
@@ -3,5 +3,6 @@
3
3
  "tag": "section",
4
4
  "enabled_on": { "templates": ["product", "product.*"] },
5
5
  "settings": [],
6
+ "blocks": [{ "type": "custom-block" }],
6
7
  "presets": [{ "name": "t:sections.main_product" }]
7
8
  }
@@ -7,16 +7,24 @@
7
7
  // settings as `productData`. Then add a variant picker + add-to-cart (cart
8
8
  // mutations live in `@shop-on/theme-server/cart-mutations`).
9
9
  import { formatMoney } from "@shop-on/theme-runtime/money";
10
+ import { hasCustomOutput } from "@shop-on/theme-react/custom-section-html";
10
11
  import type { ProductData } from "@shop-on/theme-server/product";
12
+ import { BlockRenderer, type BlockInstance } from "@/src/components/template-renderer";
11
13
  import { useProductViewed } from "@/src/lib/use-analytics";
12
14
 
13
15
  export default function MainProduct({
14
16
  sectionId,
15
17
  productData,
18
+ blocks = [],
16
19
  }: {
17
20
  sectionId?: string;
18
21
  productData?: ProductData | null;
22
+ blocks?: BlockInstance[];
19
23
  }) {
24
+ // An AI-built block the custom-section pass rendered nothing for would still
25
+ // get a wrapper of its own, and the wrapper's margin would open a gap.
26
+ const shown = blocks.filter((b) => b.type !== "custom-block" || hasCustomOutput(b.settings));
27
+
20
28
  // `product_viewed` — no-ops until the route patches in `productData`.
21
29
  useProductViewed(productData?.id, productData?.handle);
22
30
 
@@ -47,6 +55,13 @@ export default function MainProduct({
47
55
  <div className="h-4 w-5/6 rounded-sm bg-border" />
48
56
  </div>
49
57
  )}
58
+ {/* One wrapper per block, not one BlockRenderer over the list: its own
59
+ wrapper is `display: contents`, so it can't carry the spacing. */}
60
+ {shown.map((block, i) => (
61
+ <div key={block.id ?? i} className="mt-8">
62
+ <BlockRenderer blocks={[block]} />
63
+ </div>
64
+ ))}
50
65
  </div>
51
66
  </div>
52
67
  </section>
@@ -21,6 +21,7 @@
21
21
 
22
22
  import { createServerFn } from "@tanstack/react-start";
23
23
  import type { LoadedTemplate } from "@shop-on/theme-loader/types";
24
+ import { isValidLocale, localizedPath } from "@/src/lib/i18n";
24
25
 
25
26
  /** Everything the loader needs about the request behind a template load. */
26
27
  interface TemplateRequest {
@@ -37,16 +38,35 @@ async function loadTemplate(
37
38
  templateId: string,
38
39
  req: TemplateRequest = {},
39
40
  ): Promise<LoadedTemplate | null> {
40
- const [{ loadTemplateForRequest, runEnrichment }, { loaderConfig }, { enrichAdapter }] =
41
- await Promise.all([
42
- import("@shop-on/theme-loader"),
43
- import("./template-loader"),
44
- import("./enrich-adapter"),
45
- ]);
41
+ const [
42
+ { loadTemplateForRequest, runEnrichment },
43
+ { loaderConfig },
44
+ { enrichAdapter },
45
+ { renderCustomSections },
46
+ ] = await Promise.all([
47
+ import("@shop-on/theme-loader"),
48
+ import("./template-loader"),
49
+ import("./enrich-adapter"),
50
+ import("@shop-on/theme-loader/custom-sections"),
51
+ ]);
46
52
 
47
53
  const template = await loadTemplateForRequest(loaderConfig, templateId, req.sid, req.locale);
48
54
  if (!template) return null;
49
55
  await runEnrichment(loaderConfig, template, enrichAdapter, req);
56
+ // AI-built sections and blocks (`custom-section`, `custom-block`). AFTER the
57
+ // enrichment, deliberately: its last phase re-scans every string setting, so
58
+ // rendered HTML must land after it. `link_url` hands `localizePath` a
59
+ // locale-free site path. Only a locale the shop serves may prefix it:
60
+ // `req.locale` is server-fn input, and a crafted one would otherwise turn a
61
+ // site path into another host's (`//evil.example/…`). Once a route loads its
62
+ // product or collection here, pass `product` / `getCollection` as well, and
63
+ // the template's `product` / `collection` drops fill in on that page.
64
+ const pathLocale = isValidLocale(req.locale) ? req.locale : undefined;
65
+ await renderCustomSections(loaderConfig, template, {
66
+ sid: req.sid,
67
+ locale: req.locale,
68
+ localizePath: (path) => localizedPath(path, pathLocale),
69
+ });
50
70
  return template;
51
71
  }
52
72