@decocms/blocks-admin 7.34.2 → 7.34.4

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": "@decocms/blocks-admin",
3
- "version": "7.34.2",
3
+ "version": "7.34.4",
4
4
  "type": "module",
5
5
  "description": "Deco admin protocol: /live/_meta, /.decofile, /deco/invoke, /deco/render, plus admin-facing site setup and commerce-app auto-configuration",
6
6
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "lint:unused": "knip"
26
26
  },
27
27
  "dependencies": {
28
- "@decocms/blocks": "7.34.2"
28
+ "@decocms/blocks": "7.34.4"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "react": "^19.0.0",
@@ -162,7 +162,11 @@ export async function resolvePreviewRequest(request: Request): Promise<PreviewRe
162
162
  return { type: "unknown", component };
163
163
  }
164
164
 
165
- const resolvedProps = (await resolveValue(props)) as Record<string, unknown>;
165
+ const resolvedProps = (await resolveValue(
166
+ props,
167
+ undefined,
168
+ buildPreviewMatcherCtx(request),
169
+ )) as Record<string, unknown>;
166
170
  const { __resolveType: _, ...cleanProps } = resolvedProps;
167
171
  return {
168
172
  type: "sections",
@@ -70,6 +70,30 @@ export interface AppRegistryEntry {
70
70
 
71
71
  export type AppRegistry = readonly AppRegistryEntry[];
72
72
 
73
+ // One-shot re-configuration registered by autoconfigApps() and triggered by the
74
+ // first request (reconfigureAppsOnce). See reconfigureAppsOnce() below for why.
75
+ let pendingReinit: (() => Promise<void>) | null = null;
76
+ let reinitPromise: Promise<void> | null = null;
77
+
78
+ /**
79
+ * Re-run app configuration once, the first time it's called from within a
80
+ * request scope. Idempotent — subsequent calls await the same in-flight promise
81
+ * (or return immediately once done).
82
+ *
83
+ * Why this exists: autoconfigApps() runs at module-init (setup.ts), BEFORE any
84
+ * request. In CF Workers production/preview the `env` binding (holding
85
+ * DECO_CRYPTO_KEY) is only available inside the fetch handler, so the startup
86
+ * pass decrypts nothing and configures apps with null credentials. workerEntry
87
+ * calls this after setRuntimeEnv(env) so configure() re-runs with the real key
88
+ * now reachable via getRuntimeEnv() inside crypto.ts's getEnvVar().
89
+ */
90
+ export function reconfigureAppsOnce(): Promise<void> {
91
+ if (reinitPromise) return reinitPromise;
92
+ if (!pendingReinit) return Promise.resolve(); // nothing registered yet
93
+ reinitPromise = pendingReinit();
94
+ return reinitPromise;
95
+ }
96
+
73
97
  async function configureAllApps(
74
98
  blocks: Record<string, unknown>,
75
99
  registry: AppRegistry,
@@ -137,12 +161,27 @@ export async function autoconfigApps(
137
161
  await setupApps(apps);
138
162
  }
139
163
 
164
+ // Latest blocks, kept current by onChange so the first-request re-init below
165
+ // uses fresh content if the decofile was reloaded before the first request.
166
+ let latestBlocks = blocks;
167
+
140
168
  // Re-configure on admin hot-reload
141
169
  onChange(async (newBlocks) => {
142
170
  if (typeof document !== "undefined") return;
171
+ latestBlocks = newBlocks;
143
172
  const updatedApps = await configureAllApps(newBlocks, registry);
144
173
  if (updatedApps.length > 0) {
145
174
  await setupApps(updatedApps);
146
175
  }
147
176
  });
177
+
178
+ // Register the one-shot re-init fired on the first request (where the CF
179
+ // Workers `env` — and thus DECO_CRYPTO_KEY — becomes reachable). See
180
+ // reconfigureAppsOnce() for the full rationale.
181
+ pendingReinit = async () => {
182
+ const reconfigured = await configureAllApps(latestBlocks, registry);
183
+ if (reconfigured.length > 0) {
184
+ await setupApps(reconfigured);
185
+ }
186
+ };
148
187
  }