@decocms/start 0.31.0 → 0.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cms/resolve.ts +27 -5
package/package.json
CHANGED
package/src/cms/resolve.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { findPageByPath, loadBlocks } from "./loader";
|
|
2
|
-
import { getOnBeforeResolveProps, getSection } from "./registry";
|
|
2
|
+
import { getOnBeforeResolveProps, getSection, registerOnBeforeResolveProps } from "./registry";
|
|
3
3
|
import { isLayoutSection, runSingleSectionLoader } from "./sectionLoaders";
|
|
4
4
|
import { normalizeUrlsInObject } from "../sdk/normalizeUrls";
|
|
5
5
|
|
|
@@ -9,6 +9,30 @@ if (!G.__deco) G.__deco = {};
|
|
|
9
9
|
if (!G.__deco.commerceLoaders) G.__deco.commerceLoaders = {};
|
|
10
10
|
if (!G.__deco.customMatchers) G.__deco.customMatchers = {};
|
|
11
11
|
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// onBeforeResolveProps helper — eagerly loads the section module if needed
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
async function applyOnBeforeResolveProps(
|
|
17
|
+
sectionType: string,
|
|
18
|
+
props: Record<string, unknown>,
|
|
19
|
+
): Promise<Record<string, unknown>> {
|
|
20
|
+
let fn = getOnBeforeResolveProps(sectionType);
|
|
21
|
+
if (!fn) {
|
|
22
|
+
const loader = getSection(sectionType);
|
|
23
|
+
if (loader) {
|
|
24
|
+
try {
|
|
25
|
+
const mod = await loader();
|
|
26
|
+
if (mod?.onBeforeResolveProps) {
|
|
27
|
+
registerOnBeforeResolveProps(sectionType, mod.onBeforeResolveProps);
|
|
28
|
+
fn = mod.onBeforeResolveProps;
|
|
29
|
+
}
|
|
30
|
+
} catch {}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return fn ? fn(props) : props;
|
|
34
|
+
}
|
|
35
|
+
|
|
12
36
|
// ---------------------------------------------------------------------------
|
|
13
37
|
// Well-known resolve types — extracted as constants so they're searchable
|
|
14
38
|
// and overridable. Consumers migrating from deco-cx/deco may have blocks
|
|
@@ -483,8 +507,7 @@ async function internalResolve(value: unknown, rctx: ResolveContext): Promise<un
|
|
|
483
507
|
// onBeforeResolveProps: let sections transform raw props before resolution.
|
|
484
508
|
// This runs with unresolved props (containing __resolveType refs) so sections
|
|
485
509
|
// can extract metadata that would be lost after resolution (e.g., collection IDs).
|
|
486
|
-
const
|
|
487
|
-
const propsToResolve = beforeResolve ? beforeResolve(rest) : rest;
|
|
510
|
+
const propsToResolve = await applyOnBeforeResolveProps(resolveType, rest);
|
|
488
511
|
|
|
489
512
|
const resolvedRest = await resolveProps(propsToResolve, childCtx);
|
|
490
513
|
return { __resolveType: resolveType, ...resolvedRest };
|
|
@@ -1391,8 +1414,7 @@ export async function resolveDeferredSection(
|
|
|
1391
1414
|
};
|
|
1392
1415
|
|
|
1393
1416
|
// onBeforeResolveProps: let sections transform raw props before resolution.
|
|
1394
|
-
const
|
|
1395
|
-
const propsToResolve = beforeResolve ? beforeResolve(rawProps) : rawProps;
|
|
1417
|
+
const propsToResolve = await applyOnBeforeResolveProps(component, rawProps);
|
|
1396
1418
|
|
|
1397
1419
|
const resolvedProps = await resolveProps(propsToResolve, rctx);
|
|
1398
1420
|
const normalizedProps = normalizeNestedSections(resolvedProps) as Record<string, unknown>;
|