@eldrajs/theme-nuxt 0.5.0 → 0.5.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/CHANGELOG.md +6 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +4 -1
- package/dist/runtime/previewSession.d.ts +13 -0
- package/dist/runtime/previewSession.js +32 -7
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
5
5
|
|
|
6
6
|
## Unreleased
|
|
7
7
|
|
|
8
|
+
- **A theme can keep a draft preview session's veil up for its own reads (WS-1277).** New
|
|
9
|
+
auto-import `holdPreviewSession(work)`: work started while a session is covered (a read outside
|
|
10
|
+
Nuxt's async data that the draft's own render started, such as a block whose draft names a
|
|
11
|
+
collection the pinned build never read) keeps the veil up until it settles, and the session
|
|
12
|
+
renders once more before the draft is shown, within the same 15 s bound. A no-op outside a
|
|
13
|
+
covered session. A focus the session replays now lands on the settled page.
|
|
8
14
|
- **Link targets carry a card's picture and price (WS-1326).** `collectLinkTargets` fills
|
|
9
15
|
`LinkTargetInfo.image` from a product's `thumbnail` or a collection's `image` and
|
|
10
16
|
`LinkTargetInfo.price` from a product's `minPrice`, out of the reads it already makes.
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -165,7 +165,10 @@ const eldraModule = defineNuxtModule({
|
|
|
165
165
|
// module is what fills it from the route.
|
|
166
166
|
{ name: "useEldraLocale", from: "@eldrajs/theme-vue" },
|
|
167
167
|
{ name: "useEldraEntry", from: "@eldrajs/theme-vue" },
|
|
168
|
-
{ name: "useEldraPreview", from: "@eldrajs/theme-vue" }
|
|
168
|
+
{ name: "useEldraPreview", from: "@eldrajs/theme-vue" },
|
|
169
|
+
// A read a theme makes outside Nuxt's async data, started while a draft preview session is
|
|
170
|
+
// covered, keeps the veil up until it has answered (`./runtime/previewSession.ts`).
|
|
171
|
+
{ name: "holdPreviewSession", from: resolver.resolve("./runtime/previewSession") }
|
|
169
172
|
]);
|
|
170
173
|
let localeRouting = resolveLocaleRouting(null, options.locale);
|
|
171
174
|
const crawlRoutes = [];
|
|
@@ -117,6 +117,19 @@ export declare const PREVIEW_SESSION_DRAFT_TIMEOUT_MS = 15000;
|
|
|
117
117
|
* settled within `timeoutMs`, end in the unavailable notice. Never the published page either way.
|
|
118
118
|
*/
|
|
119
119
|
export declare function settlePreviewSessionDrafts(reads: () => Promise<unknown>, afterRender: () => Promise<unknown>, timeoutMs?: number): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Keep the veil up until `work` has settled, when it was started while the session is covered —
|
|
122
|
+
* a no-op otherwise (outside a session, or once the draft is shown).
|
|
123
|
+
*
|
|
124
|
+
* For the reads a theme makes outside Nuxt's async data, which the session cannot see: a block
|
|
125
|
+
* whose draft names a collection the pinned build never read starts that read in the draft's own
|
|
126
|
+
* render, and without this the veil drops on its skeleton and the page changes under the merchant
|
|
127
|
+
* a moment later — and a focus the session replays (`replayCoveredFocus`) scrolls against a layout
|
|
128
|
+
* that is about to change, landing where the live page, which never had the skeleton, does not.
|
|
129
|
+
* Resolve `work` once its answer has been written where the page renders it from; the session
|
|
130
|
+
* renders once more after it.
|
|
131
|
+
*/
|
|
132
|
+
export declare function holdPreviewSession(work: PromiseLike<unknown>): void;
|
|
120
133
|
/** How long a session waits for the site's saved settings before it keeps the build's. */
|
|
121
134
|
export declare const PREVIEW_SESSION_SITE_SETTINGS_TIMEOUT_MS = 10000;
|
|
122
135
|
/**
|
|
@@ -211,20 +211,45 @@ export async function settlePreviewSessionDrafts(reads, afterRender, timeoutMs =
|
|
|
211
211
|
() => "settled"
|
|
212
212
|
);
|
|
213
213
|
const outcome = await Promise.race([settled, timedOut]);
|
|
214
|
-
clearTimeout(timer);
|
|
215
214
|
if (outcome === "timeout") {
|
|
215
|
+
clearTimeout(timer);
|
|
216
216
|
refuse({ status: "unavailable", errorId: null });
|
|
217
217
|
return;
|
|
218
218
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
219
|
+
for (let round = 0; ; round += 1) {
|
|
220
|
+
try {
|
|
221
|
+
await afterRender();
|
|
222
|
+
} catch (cause) {
|
|
223
|
+
clearTimeout(timer);
|
|
224
|
+
console.warn("[eldra] the draft preview could not be rendered", cause);
|
|
225
|
+
refuse({ status: "unavailable", errorId: null });
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (held.size === 0 || round >= PREVIEW_SESSION_HELD_ROUNDS) break;
|
|
229
|
+
const quiet = await Promise.race([
|
|
230
|
+
Promise.all([...held]).then(() => "quiet"),
|
|
231
|
+
timedOut
|
|
232
|
+
]);
|
|
233
|
+
if (quiet === "timeout") {
|
|
234
|
+
clearTimeout(timer);
|
|
235
|
+
refuse({ status: "unavailable", errorId: null });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
225
238
|
}
|
|
239
|
+
clearTimeout(timer);
|
|
226
240
|
markPreviewSessionDraftShown();
|
|
227
241
|
}
|
|
242
|
+
const PREVIEW_SESSION_HELD_ROUNDS = 5;
|
|
243
|
+
const held = /* @__PURE__ */ new Set();
|
|
244
|
+
export function holdPreviewSession(work) {
|
|
245
|
+
if (state.status !== "pending") return;
|
|
246
|
+
const settled = Promise.resolve(work).then(
|
|
247
|
+
() => void 0,
|
|
248
|
+
() => void 0
|
|
249
|
+
);
|
|
250
|
+
held.add(settled);
|
|
251
|
+
void settled.then(() => held.delete(settled));
|
|
252
|
+
}
|
|
228
253
|
export const PREVIEW_SESSION_SITE_SETTINGS_TIMEOUT_MS = 1e4;
|
|
229
254
|
export async function settlePreviewSessionSiteSettings(read, timeoutMs = PREVIEW_SESSION_SITE_SETTINGS_TIMEOUT_MS) {
|
|
230
255
|
let open = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrajs/theme-nuxt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Nuxt module for Eldra themes: wires @eldrajs/vite-plugin-theme, the gateway client, draft overlays and the Studio preview bridge into a Nuxt 4 site.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"defu": "^6.1.4",
|
|
53
53
|
"h3": "^1.15.0",
|
|
54
54
|
"@eldrajs/sdk": "^0.5.4",
|
|
55
|
+
"@eldrajs/theme-vue": "^0.2.8",
|
|
55
56
|
"@eldrajs/vite-plugin-theme": "^0.4.0",
|
|
56
|
-
"@eldrajs/theme-core": "^0.4.0"
|
|
57
|
-
"@eldrajs/theme-vue": "^0.2.8"
|
|
57
|
+
"@eldrajs/theme-core": "^0.4.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@nuxt/module-builder": "^0.8.4",
|