@recapi/client 0.18.0 → 0.33.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/src/magento.js CHANGED
@@ -16,6 +16,14 @@
16
16
  */
17
17
 
18
18
  import { createClient } from './index.js';
19
+ import { GRID, addStyle, blankStyle, blanks, card, cardStyle, carry, escape, headingAbove, idOf, listOf, listStyle, nameOf, nameStyle, near, opened, paired, pictureOf, recentlyViewed, region, wasOf, wasStyle, web } from './cards.js';
20
+ import { bought, fillRows, followReturns, landing, onReturn, orderStorage } from './shops.js';
21
+ import { storageKey } from './storage.js';
22
+ // Their own imports, named so the browser asks for all at once (TestEntriesImportTheirWholeGraph).
23
+ import './client.js';
24
+ import './history.js';
25
+ import './page.js';
26
+ import './transport.js';
19
27
 
20
28
  /**
21
29
  * Runs a page of the store. Resolves once the page's work is set up (the row
@@ -24,44 +32,9 @@ import { createClient } from './index.js';
24
32
  *
25
33
  * @param {{ api: string, key: string, platform: string, product: string|null,
26
34
  * placement: string, cookieRestriction: boolean, website: string,
27
- * cards: string, currency: string|null }} page
35
+ * cards: string, currency: string|null, bought?: string[] }} page
28
36
  */
29
37
  export async function magentoPage(page) {
30
- // The server sends the orders and can't read the browser's storage: each
31
- // time the library saves the visitor's state, the "recapi" cookie gets what
32
- // a purchase needs, the visitor's id and the recommendation each clicked
33
- // product came from (the saved list entries that have a click time). The
34
- // library saves only with consent. A day, as long as the library credits a
35
- // click.
36
- const secure = location.protocol === 'https:' ? '; secure' : '';
37
- const cookie = (value, maxAge) => {
38
- document.cookie = `recapi=${value}; path=/; max-age=${maxAge}; samesite=lax${secure}`;
39
- };
40
- const mirror = (saved) => {
41
- let state;
42
- try {
43
- state = JSON.parse(saved);
44
- } catch {
45
- return;
46
- }
47
- if (typeof state?.anonId !== 'string') return;
48
- const clicked = (Array.isArray(state.shown) ? state.shown : []).filter((entry) => Array.isArray(entry) && entry.length >= 4);
49
- // A browser drops a cookie over 4 KB: the products shown last stay.
50
- let value;
51
- do {
52
- value = encodeURIComponent(JSON.stringify({ anon: state.anonId, recs: Object.fromEntries(clicked.map(([item, rec]) => [item, rec])) }));
53
- } while (value.length > 3000 && clicked.shift());
54
- cookie(value, 86400);
55
- };
56
- const storage = {
57
- getItem: (key) => localStorage.getItem(key),
58
- setItem: (key, value) => {
59
- localStorage.setItem(key, value);
60
- mirror(value);
61
- },
62
- removeItem: (key) => localStorage.removeItem(key)
63
- };
64
-
65
38
  // Magento's Cookie Restriction Mode is the store's consent switch: on, the
66
39
  // visitor's device keeps nothing until they accept the cookie notice, which
67
40
  // writes {"<website id>": 1} into user_allowed_save_cookie. Without consent
@@ -76,23 +49,34 @@ export async function magentoPage(page) {
76
49
  }
77
50
  };
78
51
  const consent = allowed();
79
- const recapi = createClient({ apiKey: page.key, baseUrl: page.api, consent, storage, platform: page.platform });
80
- // A visitor who took their consent back (deleted the notice's cookie) leaves
81
- // no ids for their next order.
82
- if (!consent && /(?:^|;\s*)recapi=/.test(document.cookie)) cookie('', 0);
52
+ // The server sends the orders, with the ids the cookie keeps.
53
+ const recapi = createClient({ apiKey: page.key, baseUrl: page.api, consent, storage: orderStorage(consent), platform: page.platform });
83
54
 
84
55
  // Luma and its children announce through jQuery, which RequireJS loads:
85
56
  // the cookie notice's accept and the Ajax add to cart, with its products.
57
+ // A speed module that delays classic scripts until the visitor's first
58
+ // touch, but not modules, holds RequireJS back too: this script then runs
59
+ // first. Asked again at each click until it is there (the add to cart's
60
+ // call answers later) and at load, and once, or each cart would count twice.
61
+ let asked = false;
86
62
  const jquery = (use) => {
63
+ if (asked) return;
87
64
  if (typeof window.require === 'function') window.require(['jquery'], use);
88
65
  else if (window.jQuery) use(window.jQuery);
66
+ else return;
67
+ asked = true;
89
68
  };
90
- jquery(($) => {
69
+ const subscribe = () => jquery(($) => {
91
70
  $(document).on('user:allowed:save:cookie', () => recapi.setConsent(allowed()));
92
71
  $(document).on('ajax:addToCart', (event, data) => {
93
72
  for (const id of data?.productIds ?? []) if (id) recapi.track(String(id), 'cart');
94
73
  });
95
74
  });
75
+ subscribe();
76
+ if (!asked) {
77
+ window.addEventListener('load', subscribe, { once: true });
78
+ document.addEventListener('click', subscribe, true);
79
+ }
96
80
  // Hyvä's cookie notice announces the accept on the window instead: the
97
81
  // consent applies on the same page there too, not only from the next one.
98
82
  window.addEventListener('user-allowed-save-cookie', () => recapi.setConsent(allowed()));
@@ -106,29 +90,12 @@ export async function magentoPage(page) {
106
90
  if (id) recapi.track(String(id), 'cart');
107
91
  });
108
92
 
109
- // The product id is the item id. A card's link carries its recommendation:
110
- // without consent nothing on the device remembers which list showed it. In the
111
- // fragment, which no server or page cache sees: an unknown ?rec= gave every
112
- // click from the row its own entry in the full-page cache. ?rec= is still read:
113
- // links already out there, and the cards that can't use a fragment (below).
114
- const inFragment = /^#rec_[0-9a-f]+$/;
115
- const viewed = () => {
116
- const fragment = inFragment.test(location.hash) ? location.hash.slice(1) : null;
117
- const linked = fragment ?? new URLSearchParams(location.search).get('rec');
118
- recapi.track(page.product, 'view', { recommendationId: linked });
119
- // recapi credits an explicit id to whoever brings it: drop it from the
120
- // address so a copied or shared link doesn't credit strangers' visits.
121
- if (fragment !== null) history.replaceState(history.state, '', `${location.pathname}${location.search}`);
122
- else if (linked !== null) {
123
- const query = location.search.slice(1).split('&').filter((p) => p.split('=')[0] !== 'rec').join('&');
124
- history.replaceState(history.state, '', `${location.pathname}${query ? `?${query}` : ''}${location.hash}`);
125
- }
126
- };
127
- // A browser may preload the link under the pointer, and a page it prerenders
128
- // runs this script though nobody may ever open it: a click nobody made must
129
- // not be credited.
130
- if (page.product && document.prerendering) document.addEventListener('prerenderingchange', viewed);
131
- else if (page.product) viewed();
93
+ // The product id is the item id. A card's link carries its list's id in
94
+ // the fragment, which no page cache sees: an unknown ?rec= gave every click
95
+ // from the row its own entry in the full-page cache.
96
+ if (page.product) landing(recapi, page.product);
97
+ // The order's own page: the server sent the purchases.
98
+ bought(recapi, page.bought);
132
99
 
133
100
  // recapi's row (the product page's recommendations block) arrives printed
134
101
  // with the store's own products in it: recapi's cards replace them when it
@@ -137,22 +104,64 @@ export async function magentoPage(page) {
137
104
  // and empty: it shows only once recapi has products for it.
138
105
  const slot = document.getElementById('recapi-recommendations');
139
106
  const together = page.product ? document.getElementById('recapi-bought-together') : null;
140
- const rows = [
141
- { slot, placement: page.placement },
142
- ...(slot && together ? [{ slot: together, placement: 'bought_together', together: true }] : [])
143
- ];
144
107
  const blockOf = (element) => element.closest?.('.recapi-recommendations') ?? element;
145
- const escape = (s) => String(s).replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
146
- // Only http(s) addresses: metadata is the shop's, but a javascript: link
147
- // must never reach the page.
148
- const web = (address) => {
108
+ // The home page's Recently viewed row (the body's class names Magento's
109
+ // page): the products this shopper opened before, hidden until it has some.
110
+ // Under the theme's recapi block when it placed one (its own such block
111
+ // makes two), else in a box of its own at the end of the main content: the
112
+ // module places no block there, and a shop that never edits a layout file
113
+ // gets the row too, with no module update (Shopify's homeBox does the same).
114
+ let recent = null;
115
+ const main = !slot && document.body?.classList?.contains('cms-index-index')
116
+ ? document.querySelector?.('#maincontent .column.main') ?? document.querySelector?.('main, [role="main"]')
117
+ : null;
118
+ if (slot ? document.body?.classList?.contains('cms-index-index') : main) {
119
+ const id = 'recapi-recently-viewed';
120
+ const box = `<div class="block recapi-recommendations" hidden role="region" aria-labelledby="${id}-title"><div class="block-title title" id="${id}-title"><strong role="heading" aria-level="2">${escape(recentlyViewed())}</strong></div><div id="${id}" class="block-content"></div>\n</div>`;
121
+ if (slot) blockOf(slot).insertAdjacentHTML('afterend', box);
122
+ else main.insertAdjacentHTML('beforeend', box);
123
+ recent = document.getElementById(id);
124
+ // Hyvä sets no margin on a block's title: the row touched the content above.
125
+ addStyle(`:where(#${id}){${GRID}}:where(#${id}-title){margin-block:1.5rem .5rem}${cardStyle(`#${id}`)}`);
126
+ }
127
+ const rows = slot
128
+ ? [{ slot, placement: page.placement }, ...(together ? [{ slot: together, placement: 'bought_together' }] : []),
129
+ ...(recent ? [{ slot: recent, placement: 'recently_viewed' }] : [])]
130
+ : recent ? [{ slot: recent, placement: 'recently_viewed' }] : [];
131
+ // Its cards take the width of those in the row above, the theme's own
132
+ // (Luma's and Hyvä's product-item) or recapi's: the grid's quarter of the
133
+ // page made them twice as wide as Luma's (about 300 px under 170). Measured,
134
+ // as no rule can read another element's width; again when the window turns.
135
+ const fit = () => {
136
+ if (!recent?.style || typeof document.querySelectorAll !== 'function') return;
137
+ const block = blockOf(recent);
138
+ const cards = [...document.querySelectorAll('.product-item, #recapi-recommendations>ul>li')]
139
+ // 4: the card comes before the row (Node.DOCUMENT_POSITION_FOLLOWING).
140
+ .filter((each) => !block.contains(each) && each.compareDocumentPosition(block) & 4 && each.getBoundingClientRect().width > 0);
141
+ const boxes = cards.map((each) => each.getBoundingClientRect());
142
+ const box = boxes[boxes.length - 1];
143
+ // Their gap too, between the last two cards in one line: Luma's phone
144
+ // grid fits two 176 px cards 7 px apart in 360 px, which ours (1rem)
145
+ // split into one a line. Both rounded down, so as many always fit.
146
+ let pair = boxes.length - 1;
147
+ while (pair > 0 && !(Math.abs(boxes[pair].top - boxes[pair - 1].top) < 1 && boxes[pair].left > boxes[pair - 1].left)) pair -= 1;
148
+ const width = box ? Math.floor(box.width) : 0;
149
+ const gap = pair > 0 ? Math.max(0, Math.floor(boxes[pair].left - boxes[pair - 1].right)) : null;
150
+ recent.style.gridTemplateColumns = width ? `repeat(auto-fill,minmax(min(100%,${width}px),${width}px))` : '';
151
+ recent.style.columnGap = width && gap !== null ? `${gap}px` : '';
152
+ };
153
+ if (recent) window.addEventListener('resize', fit);
154
+ // recapi's own box reads the history only on a device that keeps one: a
155
+ // shopper new to the shop opened nothing, and the page leaves nothing on
156
+ // their device for a row with nothing in it (reading it starts the visitor).
157
+ const kept = () => {
149
158
  try {
150
- const url = new URL(address, location.href);
151
- return url.protocol === 'https:' || url.protocol === 'http:' ? url : null;
159
+ return localStorage.getItem(storageKey(page.key.slice(0, 16))) !== null;
152
160
  } catch {
153
- return null;
161
+ return false;
154
162
  }
155
163
  };
164
+ const fresh = Boolean(main && recent) && !kept();
156
165
  const lang = document.documentElement?.lang || undefined;
157
166
  const money = (amount) => {
158
167
  if (typeof amount === 'string') return amount;
@@ -169,106 +178,131 @@ export async function magentoPage(page) {
169
178
  if (typeof metadata?.name !== 'string' || typeof metadata.url !== 'string' || !web(metadata.url)) return null;
170
179
  const price = metadata.price === undefined || metadata.price === null ? '' : money(metadata.price);
171
180
  if (price === null) return null;
172
- return { name: metadata.name, url: metadata.url, picture: typeof metadata.picture === 'string' ? metadata.picture : '', price };
181
+ return { name: metadata.name, url: metadata.url, picture: metadata.picture, price, was: wasOf(metadata, money) };
173
182
  };
174
- // A row shows 4 cards. recapi counts every product of a list as shown, so
175
- // a spare asked for would get an impression and could be credited a view it
176
- // never caused: each row asks for 4. recapi may not know a product sold out
177
- // or was disabled since the last sync; one more call, for the rows left
178
- // short only and without the products already listed, then fills the gaps.
179
- const ROW = 4;
180
- // Through the call that takes all of a page's rows: billed as one, the
181
- // history sent once, and no product on two rows (the first row's go first).
182
- // Each row its own placement.
183
- const ask = (wanted, exclude) => recapi.recommendLists({
184
- lists: wanted.map(({ count, placement }) => ({ count, placement, ...(page.product ? { contextItemId: page.product } : {}) })),
185
- ...(exclude.length ? { exclude } : {})
186
- });
183
+ // The store's cards: the module (0.4.37 on) sends the old price formatted
184
+ // as the price, and only when a sale cut it.
185
+ const fromStore = (found) => ({ ...found, was: typeof found.list_price === 'string' && found.list_price.trim() ? found.list_price : null });
187
186
  // A list's cards, in recapi's order, each with the list's id: those whose
188
187
  // metadata draws them, the others from the store in one request.
189
188
  const cardsOf = async ({ recommendationId, items }) => {
190
189
  const cards = new Map(items.map(({ itemId, metadata }) => [itemId, fromMetadata(metadata)]));
191
- const missing = [...cards].filter(([id, card]) => !card && /^\d+$/.test(id)).map(([id]) => id);
190
+ const missing = [...cards].filter(([id, found]) => !found && /^\d+$/.test(id)).map(([id]) => id);
192
191
  if (missing.length) {
193
192
  const url = new URL(page.cards, location.href);
194
193
  url.searchParams.set('ids', missing.join(','));
195
194
  const response = await fetch(url.href, { headers: { Accept: 'application/json' } }).catch(() => null);
196
195
  const found = (response?.ok ? await response.json().catch(() => null) : null)?.cards;
197
- for (const card of Array.isArray(found) ? found : []) if (cards.has(String(card?.id))) cards.set(String(card.id), card);
196
+ for (const each of Array.isArray(found) ? found : []) if (cards.has(String(each?.id))) cards.set(String(each.id), fromStore(each));
198
197
  }
199
198
  const reasons = new Map(items.map(({ itemId, why }) => [itemId, why]));
200
- return [...cards].filter(([, card]) => card && web(card.url)).map(([id, card]) => ({ ...card, recommendationId, why: reasons.get(id) }));
199
+ return [...cards].filter(([, found]) => found && web(found.url)).map(([id, found]) => ({ ...found, recommendationId, why: reasons.get(id) }));
201
200
  };
202
- const html = (cards) => cards.slice(0, ROW).map(({ recommendationId, why, ...card }) => {
203
- const link = web(card.url);
204
- // ?rec= only where a fragment can't carry the id: the address has its own
205
- // (a theme's, not ours to overwrite), it's the page already open (a
206
- // fragment wouldn't load it, so no view), or the page wouldn't read it back.
207
- const open = link.href.split('#')[0] === location.href.split('#')[0];
208
- if (recommendationId && (link.hash || open || !inFragment.test(`#${recommendationId}`))) link.searchParams.set('rec', recommendationId);
209
- else if (recommendationId) link.hash = recommendationId;
210
- const picture = web(card.picture);
211
- return `<a href="${escape(link.href)}">${picture ? `<img src="${escape(picture.href)}" alt="" loading="lazy">` : ''}` +
212
- `<span>${escape(card.name)}</span>${card.price ? `<span class="recapi-price">${escape(card.price)}</span>` : ''}</a>`;
213
- });
201
+ // Both rows are named by the title the module printed; the first one at
202
+ // once, as the store's own products may stay in it.
203
+ const titleOf = (element) => blockOf(element).querySelector?.('.block-title');
204
+ let name;
205
+ if (slot) {
206
+ name = nameOf(idOf(titleOf(slot), 'recapi-recommendations-title') ?? headingAbove(slot));
207
+ region(blockOf(slot), name);
208
+ } else if (recent) {
209
+ name = nameOf(idOf(titleOf(recent), 'recapi-recently-viewed-title'));
210
+ }
214
211
  // Each row's cards, drawn as far as recapi got: a row never waits on, nor
215
212
  // loses its cards to, the other row or a later call.
213
+ // Rows holding blank cards (below).
214
+ const blank = new WeakSet();
215
+ const show = (row, i, cards) => {
216
+ blank.delete(row.slot);
217
+ // The title only over a real pair: similar products under it would be
218
+ // true cards under a false title, so they show untitled. Its words go,
219
+ // its line stays: the line closing as the cards arrive would move the
220
+ // page under them. Not hidden: a theme's .block-title rule beats [hidden].
221
+ const heading = titleOf(row.slot);
222
+ const titled = Boolean(heading) && (row.placement !== 'bought_together' || paired(cards));
223
+ if (heading && !titled) {
224
+ heading.setAttribute('aria-hidden', 'true');
225
+ heading.innerHTML = '<strong>\u00a0</strong>';
226
+ }
227
+ const its = i && titled ? nameOf(idOf(heading, 'recapi-bought-together-title')) : name;
228
+ row.slot.innerHTML = listOf(cards.map((each) => ({
229
+ html: card(carry(web(each.url), each.recommendationId).href, pictureOf(each), each.name, each.price || null, '', each.why, each.price ? each.was : null)
230
+ })), its);
231
+ region(blockOf(row.slot), its);
232
+ blockOf(row.slot).hidden = false;
233
+ if (row.slot === recent) fit();
234
+ };
235
+ const styled = () => addStyle(rows.map((row) => listStyle(`#${row.slot.id}`) + wasStyle(`#${row.slot.id}`) + nameStyle(`#${row.slot.id}`)).join(''));
236
+ let styledYet = false;
237
+ // Back to the home page: its Recently viewed row drawn again, or shown.
238
+ const drawing = recent && followReturns(recapi, rows[rows.length - 1], page.product, cardsOf, (cards) => {
239
+ const row = rows[rows.length - 1];
240
+ if (!cards.length) {
241
+ row.slot.innerHTML = '';
242
+ blockOf(row.slot).hidden = true;
243
+ return;
244
+ }
245
+ if (!styledYet) styled();
246
+ styledYet = true;
247
+ show(row, rows.length - 1, cards);
248
+ });
216
249
  const draw = async () => {
217
- const lists = await ask(rows.map(({ placement }) => ({ count: ROW, placement })), []);
218
- // Popular items (recapi slow, down or at a limit) are no bought-together row.
219
- const cards = await Promise.all(lists.map((list, i) => (rows[i].together && list.fallback ? [] : cardsOf(list))));
220
- // Only a full list that couldn't fill its row: a shorter one means recapi
221
- // has no more to give, and a fallback would only wait again.
222
- const short = rows.map((row, i) => i).filter((i) => cards[i].length < ROW && lists[i].items.length >= ROW && !lists[i].fallback);
223
- if (short.length) {
224
- try {
225
- const more = await ask(short.map((i) => ({ count: ROW - cards[i].length, placement: rows[i].placement })),
226
- lists.flatMap(({ items }) => items.map(({ itemId }) => itemId)));
227
- // A popular top-up (recapi slow or at a limit on this call) fills the
228
- // first row's gap with what that row shows anyway when recapi is
229
- // down, but under the bought-together title it would mislead: that
230
- // row keeps the cards it has.
231
- const extra = await Promise.all(more.map((list, k) => (rows[short[k]].together && list.fallback ? [] : cardsOf(list))));
232
- short.forEach((i, k) => cards[i].push(...extra[k]));
233
- } catch (error) {
234
- // Rejected (a key revoked mid-page): the cards of the first call stay.
235
- console.warn('recapi:', error);
236
- }
250
+ const listed = [];
251
+ const fallback = [];
252
+ const drawn = drawing && drawing(rows, listed, fallback);
253
+ const cards = await fillRows(recapi, rows, page.product, cardsOf, { listed, fallback });
254
+ if (drawn) drawn();
255
+ // Not in the module's own stylesheet before 0.4.34 (the list) and 0.4.37 (the old price).
256
+ if (cards.flat().length) {
257
+ styled();
258
+ styledYet = true;
237
259
  }
238
260
  rows.forEach((row, i) => {
239
- const drawn = html(cards[i]);
240
- if (drawn.length) {
241
- row.slot.innerHTML = drawn.join('');
242
- // The title only over a real pair among the cards drawn: a product
243
- // nobody bought with another yet gets similar ones, true cards under
244
- // a false title, so they show untitled, as more of the row above.
245
- // Removed, not hidden: a theme's .block-title rule beats [hidden].
246
- if (row.together && !cards[i].slice(0, ROW).some(({ why }) => why === 'bought_together')) {
247
- blockOf(row.slot).querySelector?.('.block-title')?.remove();
248
- }
249
- blockOf(row.slot).hidden = false;
250
- }
261
+ if (cards[i].length) show(row, i, cards[i]);
251
262
  });
252
263
  };
264
+ // While the lists load, each row with no store product in it holds its
265
+ // place: blank cards in its grid at this width, under its title, shown
266
+ // (bought together's as a real pair's; Recently viewed's only for a shopper
267
+ // who opened a product). The store's own products are their real height already.
268
+ // From 0.4.43 the module prints that hold itself, closing after 4 s in case
269
+ // no script comes (.recapi-holding): the script takes it over and stops the clock.
270
+ for (const row of rows) {
271
+ const printed = row.slot.querySelector?.(':scope > .recapi-blank');
272
+ blockOf(row.slot).classList?.remove('recapi-holding');
273
+ if ((row.slot.children.length && !printed) || (row.placement === 'recently_viewed' && (fresh || !opened(recapi, page.product)))) continue;
274
+ if (!styledYet) {
275
+ styled();
276
+ addStyle(rows.map((each) => blankStyle(`#${each.slot.id}`)).join(''));
277
+ styledYet = true;
278
+ }
279
+ row.slot.innerHTML = blanks();
280
+ blank.add(row.slot);
281
+ blockOf(row.slot).hidden = false;
282
+ if (row.slot === recent) fit();
283
+ }
253
284
  // A row with no card at all (no store product either) hides, title included.
254
285
  // A rejected request (a revoked key: recapi's own error) keeps the store's.
255
286
  const fill = async () => {
256
287
  await draw().catch(() => 0);
288
+ for (const row of rows) if (blank.delete(row.slot)) row.slot.innerHTML = '';
257
289
  for (const row of rows) if (!row.slot.children.length) blockOf(row.slot).hidden = true;
258
290
  };
259
291
  // Only once the row comes within 400px of the screen, as Magento's lazy
260
- // images load: each list is billed and counted as shown, and a shopper who
261
- // never scrolls down saw none. The view above went at once. The block is
262
- // watched, not the cards' div: with no store product that div is empty, and
263
- // a theme hiding every empty div (div:empty { display: none }, Dawn's rule)
264
- // would leave nothing to come near the screen; the block has its title.
265
- if (slot && typeof IntersectionObserver !== 'function') await fill();
266
- else if (slot) {
267
- const observer = new IntersectionObserver((entries) => {
268
- if (!entries.some((entry) => entry.isIntersecting)) return undefined;
269
- observer.disconnect();
270
- return fill();
271
- }, { rootMargin: '0px 0px 400px 0px' });
272
- observer.observe(blockOf(slot));
292
+ // images load. The block is watched, not the cards' div: with no store
293
+ // product that div is empty, and a theme hiding every empty div
294
+ // (div:empty { display: none }) would leave nothing to come near the
295
+ // screen; the block has its title. The view above went at once. recapi's
296
+ // own box stays hidden for a shopper new to the shop until Back from a
297
+ // product shows this page again from memory.
298
+ if (fresh) {
299
+ let waiting = true;
300
+ onReturn(() => {
301
+ if (!waiting || !kept()) return;
302
+ waiting = false;
303
+ fill();
304
+ });
305
+ } else if (rows.length) {
306
+ await near([blockOf(rows[0].slot)], fill);
273
307
  }
274
308
  }