@wix/himalaya-cli 0.1944.0 → 0.1945.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.
Files changed (270) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/ecom/src/extensions.d.ts +27 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-ecom.mjs +16 -0
  3. package/dist/cli.mjs +1185 -644
  4. package/fixtures/wix-canned.json +6 -0
  5. package/guides/himi-json-output.md +8 -6
  6. package/guides/one-app-section-mappings.md +2 -2
  7. package/guides/one-app-to-himi-app.md +13 -4
  8. package/guides/release-notes.md +8 -0
  9. package/guides/sdk-reference.json +55 -0
  10. package/package.json +2 -2
  11. package/templates/bare-fashion/dev/index.ts +3 -1
  12. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-product-card.ts +5 -4
  13. package/templates/bare-fashion/tier5-src/_shared/collection-service.ts +35 -15
  14. package/templates/bare-fashion/tier5-src/_shared/himi-store-saved.ts +275 -13
  15. package/templates/bare-fashion/tier5-src/himi-bare-fashion-cart/index.ts +19 -12
  16. package/templates/bare-fashion/tier5-src/himi-bare-fashion-collection/index.ts +9 -4
  17. package/templates/bare-fashion/tier5-src/himi-bare-fashion-home/index.ts +10 -4
  18. package/templates/bare-fashion/tier5-src/himi-bare-fashion-product/index.ts +17 -8
  19. package/templates/bare-fashion/tier5-src/himi-bare-fashion-products/index.ts +8 -4
  20. package/templates/bare-fashion/tier5-src/himi-bare-fashion-saved/index.ts +31 -12
  21. package/templates/bare-fashion/tier5-src/himi-bare-fashion-search/index.ts +8 -4
  22. package/templates/beauty-salon/tier5-src/_shared/collection-service.ts +35 -15
  23. package/templates/beauty-salon/tier5-src/_shared/himi-store-facets.ts +4 -4
  24. package/templates/beauty-salon/tier5-src/_shared/himi-store-saved.ts +275 -13
  25. package/templates/beauty-salon/tier5-src/himi-branded-lite-cart/index.ts +13 -7
  26. package/templates/beauty-salon/tier5-src/himi-branded-lite-category/index.ts +6 -1
  27. package/templates/beauty-salon/tier5-src/himi-branded-lite-home/index.ts +6 -5
  28. package/templates/beauty-salon/tier5-src/himi-branded-lite-shop/index.ts +9 -3
  29. package/templates/beauty-salon/tier5-src/himi-store-product/index.ts +7 -5
  30. package/templates/beauty-salon/tier5-src/himi-store-saved/index.ts +31 -12
  31. package/templates/beauty-salon-owner/tier5-src/_shared/collection-service.ts +35 -15
  32. package/templates/branded-lite/recipes/wishlist-grid.json +1 -1
  33. package/templates/branded-lite/tier5-src/_shared/collection-service.ts +42 -19
  34. package/templates/branded-lite/tier5-src/_shared/himi-store-facets.ts +4 -4
  35. package/templates/branded-lite/tier5-src/_shared/himi-store-saved.ts +275 -13
  36. package/templates/branded-lite/tier5-src/_shared/saved-products-section.ts +14 -8
  37. package/templates/branded-lite/tier5-src/himi-branded-lite-cart/index.ts +13 -7
  38. package/templates/branded-lite/tier5-src/himi-branded-lite-category/index.ts +6 -1
  39. package/templates/branded-lite/tier5-src/himi-branded-lite-home/index.ts +6 -5
  40. package/templates/branded-lite/tier5-src/himi-branded-lite-shop/index.ts +9 -3
  41. package/templates/branded-lite/tier5-src/himi-store-product/index.ts +32 -15
  42. package/templates/branded-lite/tier5-src/himi-store-saved/index.ts +31 -12
  43. package/templates/brandy/tier5-src/_shared/collection-service.ts +42 -19
  44. package/templates/brandy/tier5-src/_shared/himi-store-saved.ts +275 -13
  45. package/templates/brandy/tier5-src/himi-branded-lite-cart/index.ts +13 -7
  46. package/templates/community-club/l10n/ar.json +5 -0
  47. package/templates/community-club/l10n/cs.json +5 -0
  48. package/templates/community-club/l10n/da.json +5 -0
  49. package/templates/community-club/l10n/de.json +5 -0
  50. package/templates/community-club/l10n/el.json +5 -0
  51. package/templates/community-club/l10n/es.json +5 -0
  52. package/templates/community-club/l10n/fi.json +5 -0
  53. package/templates/community-club/l10n/fr.json +5 -0
  54. package/templates/community-club/l10n/he.json +4 -0
  55. package/templates/community-club/l10n/hu.json +5 -0
  56. package/templates/community-club/l10n/id.json +5 -0
  57. package/templates/community-club/l10n/it.json +5 -0
  58. package/templates/community-club/l10n/ja.json +5 -0
  59. package/templates/community-club/l10n/ko.json +5 -0
  60. package/templates/community-club/l10n/lt.json +5 -0
  61. package/templates/community-club/l10n/nl.json +5 -0
  62. package/templates/community-club/l10n/no.json +5 -0
  63. package/templates/community-club/l10n/pl.json +5 -0
  64. package/templates/community-club/l10n/pt.json +5 -0
  65. package/templates/community-club/l10n/ru.json +5 -0
  66. package/templates/community-club/l10n/sv.json +5 -0
  67. package/templates/community-club/l10n/th.json +5 -0
  68. package/templates/community-club/l10n/tr.json +5 -0
  69. package/templates/community-club/l10n/uk.json +5 -0
  70. package/templates/community-club/l10n/vi.json +5 -0
  71. package/templates/community-club/l10n/zh.json +5 -0
  72. package/templates/community-club/tier5-src/_shared/collection-service.ts +35 -15
  73. package/templates/community-club/tier5-src/_shared/himi-store-saved.ts +275 -13
  74. package/templates/community-club/tier5-src/himi-branded-lite-home/index.ts +6 -5
  75. package/templates/community-club-owner/tier5-src/_shared/collection-service.ts +35 -15
  76. package/templates/conference/tier5-src/_shared/collection-service.ts +35 -15
  77. package/templates/events-meetups/l10n/ar.json +5 -0
  78. package/templates/events-meetups/l10n/cs.json +5 -0
  79. package/templates/events-meetups/l10n/da.json +5 -0
  80. package/templates/events-meetups/l10n/de.json +5 -0
  81. package/templates/events-meetups/l10n/el.json +5 -0
  82. package/templates/events-meetups/l10n/es.json +5 -0
  83. package/templates/events-meetups/l10n/fi.json +5 -0
  84. package/templates/events-meetups/l10n/fr.json +5 -0
  85. package/templates/events-meetups/l10n/he.json +4 -0
  86. package/templates/events-meetups/l10n/hu.json +5 -0
  87. package/templates/events-meetups/l10n/id.json +5 -0
  88. package/templates/events-meetups/l10n/it.json +5 -0
  89. package/templates/events-meetups/l10n/ja.json +5 -0
  90. package/templates/events-meetups/l10n/ko.json +5 -0
  91. package/templates/events-meetups/l10n/lt.json +5 -0
  92. package/templates/events-meetups/l10n/nl.json +5 -0
  93. package/templates/events-meetups/l10n/no.json +5 -0
  94. package/templates/events-meetups/l10n/pl.json +5 -0
  95. package/templates/events-meetups/l10n/pt.json +5 -0
  96. package/templates/events-meetups/l10n/ru.json +5 -0
  97. package/templates/events-meetups/l10n/sv.json +5 -0
  98. package/templates/events-meetups/l10n/th.json +5 -0
  99. package/templates/events-meetups/l10n/tr.json +5 -0
  100. package/templates/events-meetups/l10n/uk.json +5 -0
  101. package/templates/events-meetups/l10n/vi.json +5 -0
  102. package/templates/events-meetups/l10n/zh.json +5 -0
  103. package/templates/events-meetups/tier5-src/_shared/collection-service.ts +35 -15
  104. package/templates/events-meetups/tier5-src/_shared/himi-store-saved.ts +275 -13
  105. package/templates/events-meetups/tier5-src/himi-branded-lite-home/index.ts +6 -5
  106. package/templates/events-meetups-owner/tier5-src/_shared/collection-service.ts +35 -15
  107. package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +35 -15
  108. package/templates/gym-fitness/tier5-src/_shared/collection-service.ts +35 -15
  109. package/templates/gym-fitness/tier5-src/_shared/himi-store-facets.ts +4 -4
  110. package/templates/gym-fitness/tier5-src/_shared/himi-store-saved.ts +275 -13
  111. package/templates/gym-fitness/tier5-src/himi-branded-lite-cart/index.ts +13 -7
  112. package/templates/gym-fitness/tier5-src/himi-branded-lite-category/index.ts +6 -1
  113. package/templates/gym-fitness/tier5-src/himi-branded-lite-home/index.ts +6 -5
  114. package/templates/gym-fitness/tier5-src/himi-branded-lite-shop/index.ts +9 -3
  115. package/templates/gym-fitness/tier5-src/himi-store-product/index.ts +7 -5
  116. package/templates/gym-fitness/tier5-src/himi-store-saved/index.ts +31 -12
  117. package/templates/gym-fitness-owner/tier5-src/_shared/collection-service.ts +35 -15
  118. package/templates/medical-services/tier5-src/_shared/collection-service.ts +35 -15
  119. package/templates/nonprofit-cause/l10n/ar.json +5 -0
  120. package/templates/nonprofit-cause/l10n/cs.json +5 -0
  121. package/templates/nonprofit-cause/l10n/da.json +5 -0
  122. package/templates/nonprofit-cause/l10n/de.json +5 -0
  123. package/templates/nonprofit-cause/l10n/el.json +5 -0
  124. package/templates/nonprofit-cause/l10n/es.json +5 -0
  125. package/templates/nonprofit-cause/l10n/fi.json +5 -0
  126. package/templates/nonprofit-cause/l10n/fr.json +5 -0
  127. package/templates/nonprofit-cause/l10n/he.json +4 -0
  128. package/templates/nonprofit-cause/l10n/hu.json +5 -0
  129. package/templates/nonprofit-cause/l10n/id.json +5 -0
  130. package/templates/nonprofit-cause/l10n/it.json +5 -0
  131. package/templates/nonprofit-cause/l10n/ja.json +5 -0
  132. package/templates/nonprofit-cause/l10n/ko.json +5 -0
  133. package/templates/nonprofit-cause/l10n/lt.json +5 -0
  134. package/templates/nonprofit-cause/l10n/nl.json +5 -0
  135. package/templates/nonprofit-cause/l10n/no.json +5 -0
  136. package/templates/nonprofit-cause/l10n/pl.json +5 -0
  137. package/templates/nonprofit-cause/l10n/pt.json +5 -0
  138. package/templates/nonprofit-cause/l10n/ru.json +5 -0
  139. package/templates/nonprofit-cause/l10n/sv.json +5 -0
  140. package/templates/nonprofit-cause/l10n/th.json +5 -0
  141. package/templates/nonprofit-cause/l10n/tr.json +5 -0
  142. package/templates/nonprofit-cause/l10n/uk.json +5 -0
  143. package/templates/nonprofit-cause/l10n/vi.json +5 -0
  144. package/templates/nonprofit-cause/l10n/zh.json +5 -0
  145. package/templates/nonprofit-cause/tier5-src/_shared/collection-service.ts +35 -15
  146. package/templates/nonprofit-cause/tier5-src/_shared/himi-store-saved.ts +275 -13
  147. package/templates/nonprofit-cause/tier5-src/himi-branded-lite-home/index.ts +6 -5
  148. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-service.ts +35 -15
  149. package/templates/owner-lite/tier5-src/_shared/collection-service.ts +35 -15
  150. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-service.ts +35 -15
  151. package/templates/podcast-creator/l10n/ar.json +5 -0
  152. package/templates/podcast-creator/l10n/cs.json +5 -0
  153. package/templates/podcast-creator/l10n/da.json +5 -0
  154. package/templates/podcast-creator/l10n/de.json +5 -0
  155. package/templates/podcast-creator/l10n/el.json +5 -0
  156. package/templates/podcast-creator/l10n/es.json +5 -0
  157. package/templates/podcast-creator/l10n/fi.json +5 -0
  158. package/templates/podcast-creator/l10n/fr.json +5 -0
  159. package/templates/podcast-creator/l10n/he.json +4 -0
  160. package/templates/podcast-creator/l10n/hu.json +5 -0
  161. package/templates/podcast-creator/l10n/id.json +5 -0
  162. package/templates/podcast-creator/l10n/it.json +5 -0
  163. package/templates/podcast-creator/l10n/ja.json +5 -0
  164. package/templates/podcast-creator/l10n/ko.json +5 -0
  165. package/templates/podcast-creator/l10n/lt.json +5 -0
  166. package/templates/podcast-creator/l10n/nl.json +5 -0
  167. package/templates/podcast-creator/l10n/no.json +5 -0
  168. package/templates/podcast-creator/l10n/pl.json +5 -0
  169. package/templates/podcast-creator/l10n/pt.json +5 -0
  170. package/templates/podcast-creator/l10n/ru.json +5 -0
  171. package/templates/podcast-creator/l10n/sv.json +5 -0
  172. package/templates/podcast-creator/l10n/th.json +5 -0
  173. package/templates/podcast-creator/l10n/tr.json +5 -0
  174. package/templates/podcast-creator/l10n/uk.json +5 -0
  175. package/templates/podcast-creator/l10n/vi.json +5 -0
  176. package/templates/podcast-creator/l10n/zh.json +5 -0
  177. package/templates/podcast-creator/tier5-src/_shared/collection-service.ts +35 -15
  178. package/templates/podcast-creator/tier5-src/_shared/himi-store-saved.ts +275 -13
  179. package/templates/podcast-creator/tier5-src/himi-branded-lite-home/index.ts +6 -5
  180. package/templates/podcast-creator-owner/tier5-src/_shared/collection-service.ts +35 -15
  181. package/templates/portfolio-creative/tier5-src/_shared/collection-service.ts +35 -15
  182. package/templates/portfolio-creative/tier5-src/_shared/himi-store-facets.ts +4 -4
  183. package/templates/portfolio-creative/tier5-src/_shared/himi-store-saved.ts +275 -13
  184. package/templates/portfolio-creative/tier5-src/himi-branded-lite-cart/index.ts +13 -7
  185. package/templates/portfolio-creative/tier5-src/himi-branded-lite-category/index.ts +6 -1
  186. package/templates/portfolio-creative/tier5-src/himi-branded-lite-home/index.ts +6 -5
  187. package/templates/portfolio-creative/tier5-src/himi-branded-lite-shop/index.ts +9 -3
  188. package/templates/portfolio-creative/tier5-src/himi-store-product/index.ts +7 -5
  189. package/templates/portfolio-creative/tier5-src/himi-store-saved/index.ts +31 -12
  190. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-service.ts +35 -15
  191. package/templates/professional-services/tier5-src/_shared/collection-service.ts +35 -15
  192. package/templates/restaurant/l10n/ar.json +5 -0
  193. package/templates/restaurant/l10n/cs.json +5 -0
  194. package/templates/restaurant/l10n/da.json +5 -0
  195. package/templates/restaurant/l10n/de.json +5 -0
  196. package/templates/restaurant/l10n/el.json +5 -0
  197. package/templates/restaurant/l10n/es.json +5 -0
  198. package/templates/restaurant/l10n/fi.json +5 -0
  199. package/templates/restaurant/l10n/fr.json +5 -0
  200. package/templates/restaurant/l10n/he.json +4 -0
  201. package/templates/restaurant/l10n/hu.json +5 -0
  202. package/templates/restaurant/l10n/id.json +5 -0
  203. package/templates/restaurant/l10n/it.json +5 -0
  204. package/templates/restaurant/l10n/ja.json +5 -0
  205. package/templates/restaurant/l10n/ko.json +5 -0
  206. package/templates/restaurant/l10n/lt.json +5 -0
  207. package/templates/restaurant/l10n/nl.json +5 -0
  208. package/templates/restaurant/l10n/no.json +5 -0
  209. package/templates/restaurant/l10n/pl.json +5 -0
  210. package/templates/restaurant/l10n/pt.json +5 -0
  211. package/templates/restaurant/l10n/ru.json +5 -0
  212. package/templates/restaurant/l10n/sv.json +5 -0
  213. package/templates/restaurant/l10n/th.json +5 -0
  214. package/templates/restaurant/l10n/tr.json +5 -0
  215. package/templates/restaurant/l10n/uk.json +5 -0
  216. package/templates/restaurant/l10n/vi.json +5 -0
  217. package/templates/restaurant/l10n/zh.json +5 -0
  218. package/templates/restaurant/tier5-src/_shared/collection-service.ts +35 -15
  219. package/templates/restaurant/tier5-src/_shared/himi-store-saved.ts +275 -13
  220. package/templates/restaurant/tier5-src/himi-branded-lite-home/index.ts +6 -5
  221. package/templates/restaurant-owner/tier5-src/_shared/collection-service.ts +35 -15
  222. package/templates/retail-store/tier5-src/_shared/collection-service.ts +42 -19
  223. package/templates/retail-store/tier5-src/_shared/himi-store-facets.ts +4 -4
  224. package/templates/retail-store/tier5-src/_shared/himi-store-saved.ts +275 -13
  225. package/templates/retail-store/tier5-src/himi-branded-lite-cart/index.ts +13 -7
  226. package/templates/retail-store/tier5-src/himi-branded-lite-category/index.ts +6 -1
  227. package/templates/retail-store/tier5-src/himi-branded-lite-home/index.ts +6 -5
  228. package/templates/retail-store/tier5-src/himi-branded-lite-shop/index.ts +9 -3
  229. package/templates/retail-store/tier5-src/himi-store-product/index.ts +32 -15
  230. package/templates/retail-store/tier5-src/himi-store-saved/index.ts +31 -12
  231. package/templates/retail-store-owner/tier5-src/_shared/collection-service.ts +35 -15
  232. package/templates/salon-spa/tier5-src/_shared/collection-service.ts +35 -15
  233. package/templates/wholesale-store/dev/index.ts +2 -2
  234. package/templates/wholesale-store/tier5-src/_shared/collection-service.ts +42 -19
  235. package/templates/wholesale-store/tier5-src/_shared/himi-store-collection.ts +7 -3
  236. package/templates/wholesale-store/tier5-src/_shared/himi-store-saved.ts +275 -13
  237. package/templates/wholesale-store/tier5-src/himi-branded-lite-cart/index.ts +13 -7
  238. package/templates/wholesale-store/tier5-src/himi-store-product/index.ts +32 -15
  239. package/templates/wholesale-store/tier5-src/himi-store-saved/index.ts +31 -12
  240. package/templates/wholesale-store/tier5-src/himi-wholesale-home/index.ts +19 -8
  241. package/templates/yoga-studio/l10n/ar.json +5 -0
  242. package/templates/yoga-studio/l10n/cs.json +5 -0
  243. package/templates/yoga-studio/l10n/da.json +5 -0
  244. package/templates/yoga-studio/l10n/de.json +5 -0
  245. package/templates/yoga-studio/l10n/el.json +5 -0
  246. package/templates/yoga-studio/l10n/es.json +5 -0
  247. package/templates/yoga-studio/l10n/fi.json +5 -0
  248. package/templates/yoga-studio/l10n/fr.json +5 -0
  249. package/templates/yoga-studio/l10n/he.json +4 -0
  250. package/templates/yoga-studio/l10n/hu.json +5 -0
  251. package/templates/yoga-studio/l10n/id.json +5 -0
  252. package/templates/yoga-studio/l10n/it.json +5 -0
  253. package/templates/yoga-studio/l10n/ja.json +5 -0
  254. package/templates/yoga-studio/l10n/ko.json +5 -0
  255. package/templates/yoga-studio/l10n/lt.json +5 -0
  256. package/templates/yoga-studio/l10n/nl.json +5 -0
  257. package/templates/yoga-studio/l10n/no.json +5 -0
  258. package/templates/yoga-studio/l10n/pl.json +5 -0
  259. package/templates/yoga-studio/l10n/pt.json +5 -0
  260. package/templates/yoga-studio/l10n/ru.json +5 -0
  261. package/templates/yoga-studio/l10n/sv.json +5 -0
  262. package/templates/yoga-studio/l10n/th.json +5 -0
  263. package/templates/yoga-studio/l10n/tr.json +5 -0
  264. package/templates/yoga-studio/l10n/uk.json +5 -0
  265. package/templates/yoga-studio/l10n/vi.json +5 -0
  266. package/templates/yoga-studio/l10n/zh.json +5 -0
  267. package/templates/yoga-studio/tier5-src/_shared/collection-service.ts +35 -15
  268. package/templates/yoga-studio/tier5-src/_shared/himi-store-saved.ts +275 -13
  269. package/templates/yoga-studio/tier5-src/himi-branded-lite-home/index.ts +6 -5
  270. package/templates/yoga-studio-owner/tier5-src/_shared/collection-service.ts +35 -15
@@ -1,12 +1,12 @@
1
- // A page's wishlist section as a registrable service: the products saved on this device, the same list the template's
1
+ // A page's wishlist section as a registrable service: the saved products, the same list the template's
2
2
  // `himi_saved_products` screen shows (`himi-store-saved`), as tiles that open the product.
3
3
  // limit -> how many tiles (the section is a short grid, not the wishlist screen); `noMore` is false when more are saved,
4
4
  // which is when the section's See All button (to `himi_saved_products`) shows.
5
- // The One App wishlist is the member's account list on a private One App service no worker can call, so this module reads the
6
- // device-local list only. A page worker registers it under a service name; the descriptor binds `$service:<serviceName>.*`
7
- // (recipe wishlist-grid).
5
+ // Like the One App's, a signed-in member's section lists their account wishlist (the list the Wix site and the One App show); a
6
+ // visitor's lists the products saved on this device. A page worker registers it under a service name; the descriptor binds
7
+ // `$service:<serviceName>.*` (recipe wishlist-grid).
8
8
  import { defineService } from "@himalaya/state";
9
- import { readSavedProducts, type SavedProduct } from "./himi-store-saved.js";
9
+ import { listSavedProducts, type SavedProduct } from "./himi-store-saved.js";
10
10
 
11
11
  export interface SavedProductsSectionOptions {
12
12
  /** How many products to show; unset shows every saved product. */
@@ -45,16 +45,22 @@ export function registerSavedProductsSection(serviceName: string, options: Saved
45
45
  notLoading: status !== "loading", notErrored: status !== "error", noRows: !rows.length,
46
46
  noEmpty: !(status === "ready" && !rows.length), noMore: !more,
47
47
  });
48
- return defineService<SavedProductsSectionState, { load: (state: SavedProductsSectionState, arg?: unknown) => SavedProductsSectionState }>(serviceName, {
48
+ let reads = 0;
49
+ return defineService<SavedProductsSectionState, { load: (state: SavedProductsSectionState, arg?: unknown) => Promise<SavedProductsSectionState | undefined> }>(serviceName, {
49
50
  state: view("loading", [], false),
50
51
  actions: {
51
52
  // The list is read on every appearance, so a product saved or removed on another screen shows when the page comes back.
52
- load: () => {
53
+ // Only the latest read lands: one started before a sign-out never paints over the one after it.
54
+ load: async () => {
55
+ const read = ++reads;
53
56
  try {
54
- const saved = readSavedProducts();
57
+ const saved = await listSavedProducts();
58
+ if (read !== reads) return undefined;
55
59
  const shown = options.limit !== undefined ? saved.slice(0, options.limit) : saved;
56
60
  return view("ready", shown.map(rowOf), shown.length < saved.length);
57
61
  } catch (error) {
62
+ if (read !== reads) return undefined;
63
+ // No rows: a failed read never keeps a list that may belong to whoever was signed in before.
58
64
  console.warn("saved_products_section: the saved products could not be read", error);
59
65
  return view("error", [], false);
60
66
  }
@@ -47,7 +47,7 @@ const WIX_STORES_APP_ID = "1380b703-ce81-ff05-f115-39571d94dfcd";
47
47
  import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
48
48
  import { getAll, upsert, remove as dbRemove, type DbEntity } from "@himalaya/local-db";
49
49
  import { isOfflineFailure, writeMayHaveLanded } from "../_shared/owner-load-error.js";
50
- import { isProductSaved, readSavedProducts, toggleSavedProduct } from "../_shared/himi-store-saved.js";
50
+ import { isProductSaved, readSavedProducts, refreshSavedThen, toggleSavedProduct } from "../_shared/himi-store-saved.js";
51
51
 
52
52
  // Offline-first (data-offline): the cart is READ-THROUGH — paint the last-synced line
53
53
  // items from the on-device `cart` entity first (instant, works offline), then
@@ -463,7 +463,8 @@ const svc = defineService<State, {
463
463
  applyPromo: (state: State) => Promise<State>;
464
464
  removePromo: (state: State) => Promise<State>;
465
465
  remove: (state: State, arg?: unknown) => Promise<State>;
466
- save: (state: State, arg?: unknown) => State;
466
+ save: (state: State, arg?: unknown) => Promise<State>;
467
+ savedChanged: () => State;
467
468
  increment: (state: State, arg?: unknown) => Promise<State>;
468
469
  decrement: (state: State, arg?: unknown) => Promise<State>;
469
470
  checkout: (state: State) => Promise<State>;
@@ -479,9 +480,14 @@ const svc = defineService<State, {
479
480
  webSignedIn = (change as { signedIn?: unknown } | undefined)?.signedIn === true;
480
481
  webGeneration++;
481
482
  if (memberOnlyCart) queueSessionReload();
483
+ refreshSavedThen(() => svc.savedChanged());
482
484
  return derive(state);
483
485
  },
486
+ // The signed-in member's saved list landed: `derive` re-marks the hearts.
487
+ savedChanged: (): State => derive(svc.getState() as State),
484
488
  load: async (state, arg) => {
489
+ // Hearts follow the signed-in member's account wishlist, read beside the cart.
490
+ refreshSavedThen(() => svc.savedChanged());
485
491
  // A members-only cart (a site shell) never shows a signed-out shopper's native cart. `prepare` sets the flag
486
492
  // before coalescing, so a load already in flight (the boot load) re-checks it before it lands.
487
493
  if (memberOnlyArg(arg)) memberOnlyCart = true;
@@ -575,15 +581,15 @@ const svc = defineService<State, {
575
581
  if (!id) return state;
576
582
  return removeLine(state, id);
577
583
  },
578
- save: (state, arg) => {
584
+ save: async (state, arg): Promise<State> => {
579
585
  const id = itemId(arg);
580
586
  const item = state.items.find(candidate => candidate.id === id);
581
587
  const productId = item?.catalogReference?.catalogItemId ?? item?.productId;
582
588
  if (!item || !productId) return state;
583
- try {
584
- const saved = toggleSavedProduct({ id: productId, name: item.name, price: item.unitPrice, wasPrice: item.wasPrice, image: item.image, swatches: item.swatches });
585
- return derive({ ...state, items: state.items.map(candidate => (candidate.catalogReference?.catalogItemId ?? candidate.productId) === productId ? { ...candidate, saved, notSaved: !saved } : candidate) });
586
- } catch { return derive({ ...state, checkoutHint: copyParam("cart.saveError", "Could not save this item.") }); }
589
+ // `derive` re-marks every row from the saved list, on the cart as it is once the write lands.
590
+ try { await toggleSavedProduct({ id: productId, name: item.name, price: item.unitPrice, wasPrice: item.wasPrice, image: item.image, swatches: item.swatches }); }
591
+ catch { return derive({ ...(svc.getState() as State), checkoutHint: copyParam("cart.saveError", "Could not save this item.") }); }
592
+ return derive(svc.getState() as State);
587
593
  },
588
594
  increment: async (state, arg) => {
589
595
  const id = itemId(arg);
@@ -8,6 +8,7 @@ import { createCollectionQuery } from "../_shared/collection-query.js";
8
8
  import { detailInputId, presence, presenceAfterError, type PresenceFlags } from "../_shared/detail-presence.js";
9
9
  import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
10
10
  import { FACETS_BOOT, PAGE_SIZE, applyFacets, currencyOf, facetActions, idOf, readViewPrefs, tagFields, toRows, toggleSaved, type FacetState } from "../_shared/himi-store-facets.js";
11
+ import { refreshSavedThen } from "../_shared/himi-store-saved.js";
11
12
  import { withIapPresentation } from "../_shared/iap-presentation.js";
12
13
 
13
14
  interface State extends FacetState, PresenceFlags {
@@ -109,6 +110,8 @@ const facets = facetActions<State>(derive);
109
110
  const actions = {
110
111
  load: async (s: State, arg?: unknown): Promise<State | undefined> => {
111
112
  stashCopy(arg);
113
+ // Hearts follow the signed-in member's account wishlist, read beside the products.
114
+ refreshSavedThen(() => svc.savedChanged());
112
115
  const version = ++loadVersion;
113
116
  const id = detailInputId();
114
117
  if (!id) return derive({ ...s, ...presence("missing"), loadId: version });
@@ -153,7 +156,9 @@ const actions = {
153
156
  },
154
157
  productsChanged: (s: State) => s.loadId === loadVersion ? derive(s) : undefined,
155
158
  search: (s: State, arg?: { value?: string }) => derive({ ...s, query: (arg?.value ?? "").slice(0, 256), visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }),
156
- toggleSave: (s: State, arg?: unknown) => { try { toggleSaved(s.results, idOf(arg)); } catch { return s; } return derive(s); },
159
+ toggleSave: async (s: State, arg?: unknown): Promise<State> => { try { await toggleSaved(s.results, idOf(arg)); } catch { return s; } return derive(svc.getState() as State); },
160
+ // The signed-in member's saved list landed: re-mark the hearts.
161
+ savedChanged: (): State => derive(svc.getState() as State),
157
162
  ...facets,
158
163
  clearSearch: (s: State) => derive({ ...s, query: "", priceSelected: [], opt1Selected: [], opt2Selected: [], opt3Selected: [], visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }),
159
164
  toggleFacet: (s: State, arg?: { facet?: string; id?: string }) => {
@@ -33,7 +33,7 @@ import { groupMemberCount } from "../_shared/group-member-count.js";
33
33
  import { parseWeeklyGoal, weeklyGoalProgress, weeklySessionsFromPages } from "../_shared/weekly-goal.js";
34
34
  import { isBridgeUnavailable } from "../_shared/owner-load-error.js";
35
35
  import { formatDateMedium } from "../_shared/engine-intl.js";
36
- import { readSavedProducts, type SavedProduct } from "../_shared/himi-store-saved.js";
36
+ import { listSavedProducts, type SavedProduct } from "../_shared/himi-store-saved.js";
37
37
  import { loadStoreCategories, type StoreCategoryCard } from "../_shared/himi-store-categories.js";
38
38
  import { readSavedIds } from "../_shared/himi-blog-saved.js";
39
39
  import { withoutHidden } from "../_shared/himi-blog-hidden.js";
@@ -699,14 +699,15 @@ function savedPostCard(post: WixPost): SavedPostCard {
699
699
  interface SavedSignal { savedProducts: SavedProductCard[]; savedPosts: SavedPostCard[]; }
700
700
  function emptySavedSignal(): SavedSignal { return { savedProducts: [], savedPosts: [] }; }
701
701
 
702
- /** Resolve supported device-local saves into public rails. Member-only work remains
703
- * in refreshPersonal(), so a visitor can never trigger a bookings query here. */
702
+ /** Resolve supported saves into public rails: saved products are a signed-in member's account wishlist,
703
+ * a visitor's device list. Member-only work remains in refreshPersonal(), so a visitor can never trigger
704
+ * a bookings query here. */
704
705
  async function fetchSavedSignal(arg: unknown): Promise<SavedSignal> {
705
706
  const verticals = parseVerticals(arg);
706
707
  const signal = emptySavedSignal();
707
708
  if (verticals.includes("store")) {
708
- try { signal.savedProducts = readSavedProducts().slice(0, 6).map(savedProductCard); }
709
- catch { /* unavailable storage simply collapses the optional rail */ }
709
+ try { signal.savedProducts = (await listSavedProducts()).slice(0, 6).map(savedProductCard); }
710
+ catch { /* an unreadable list simply collapses the optional rail */ }
710
711
  }
711
712
  if (verticals.includes("blog")) {
712
713
  let ids: string[] = [];
@@ -20,6 +20,7 @@ import {
20
20
  FACETS_BOOT, PAGE_SIZE, applyFacets, countText, currencyOf, facetActions, idOf, option, readViewPrefs, selected, tagFields, toRows, toggleSaved,
21
21
  type FacetState, type Option, type Row,
22
22
  } from "../_shared/himi-store-facets.js";
23
+ import { refreshSavedThen } from "../_shared/himi-store-saved.js";
23
24
 
24
25
  const ALL = "all";
25
26
  const PAGE = 100;
@@ -481,6 +482,8 @@ function loadedState(s: S, arg?: unknown): S | undefined {
481
482
 
482
483
  async function load(s: S, arg?: unknown, fresh = false): Promise<S | undefined> {
483
484
  stashCopy(arg);
485
+ // Hearts follow the signed-in member's account wishlist, read beside the products.
486
+ refreshSavedThen(() => svc.savedChanged());
484
487
  const route = input(arg);
485
488
  const routeCategory = route.categoryId ?? route.category;
486
489
  if (!fresh && routeCategory && (
@@ -733,10 +736,13 @@ const svc = register<S, Record<string, A>>("himiBrandedShop", {
733
736
  if (query === s.query) return s;
734
737
  return derive({ ...s, query, ...(query.trim() === s.query.trim() ? {} : { visible: PAGE_SIZE, cursorEpoch: s.cursorEpoch + 1 }) });
735
738
  },
736
- toggleSave: (s, arg) => {
737
- try { toggleSaved(s.results, idOf(arg)); } catch { return s; }
738
- return derive(s);
739
+ toggleSave: async (s, arg): Promise<S> => {
740
+ try { await toggleSaved(s.results, idOf(arg)); } catch { return s; }
741
+ // The page as it is now: other actions may have run while the save was on the wire.
742
+ return derive(svc.getState() as S);
739
743
  },
744
+ // The signed-in member's saved list landed: re-mark the hearts.
745
+ savedChanged: (): S => derive(svc.getState() as S),
740
746
  ...facets,
741
747
  // The list view's load-more.
742
748
  loadMore: (s) => facets.showMore(s),
@@ -18,7 +18,7 @@ import { cleanTitle } from "../_shared/himi-text.js";
18
18
  import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
19
19
  import { isBridgeUnavailable } from "../_shared/owner-load-error.js";
20
20
  import { logBi } from "../_shared/wix-bi.js";
21
- import { isProductSaved, toggleSavedProduct } from "../_shared/himi-store-saved.js";
21
+ import { isProductSaved, syncSavedProducts, toggleSavedProduct } from "../_shared/himi-store-saved.js";
22
22
  import { openRichLink } from "../_shared/rich-content-link.js";
23
23
  import { descriptionBody } from "../_shared/rich-body.js";
24
24
  import { PRODUCT_DETAIL_FIELDS, productInfoSections, type ProductInfoSection } from "../_shared/store-product-info.js";
@@ -85,6 +85,8 @@ function productPolicyBody(product: StoreProduct, kind: "returns" | "shipping"):
85
85
  * DIFFERENT product (drop the picks) from the same product coming back (keep them). */
86
86
  let lastLoadedId: string | undefined;
87
87
  let productLoadSequence = 0;
88
+ /** Bumped by every heart tap: a load that started before one never overwrites the saved state it set. */
89
+ let saveEpoch = 0;
88
90
 
89
91
  interface OptionSlots {
90
92
  opt1Label: string; opt1Chips: OptionChip[]; opt1Selected: string[]; opt1SelectedId: string; opt1Placeholder: string; noOpt1: boolean;
@@ -537,7 +539,7 @@ const svc = onlineService<S, {
537
539
  beginAdd: (s: S, arg?: unknown) => S;
538
540
  setCartCount: (s: S, arg?: unknown) => S;
539
541
  share: (s: S) => Promise<S>;
540
- toggleSave: (s: S) => S;
542
+ toggleSave: (s: S) => Promise<S>;
541
543
  closeAddedSheet: (s: S) => S;
542
544
  /** [rico] #3372 — RichContent's on_link: `{ url }` of the tapped link. */
543
545
  openLink: (s: S, arg?: unknown) => Promise<S>;
@@ -640,9 +642,15 @@ const svc = onlineService<S, {
640
642
  // A managed refresh retains the raw product used by the still-visible snapshot.
641
643
  // Navigation and legacy loaders keep their existing reset behavior.
642
644
  if (!readOptions(arg) || id !== lastLoadedId) lastProduct = undefined;
643
- // Storage problems must not prevent browsing or buying a product.
644
- let saved = false;
645
- try { saved = isProductSaved(id); } catch { /* save action reports a retryable error */ }
645
+ // Storage problems must not prevent browsing or buying a product. A signed-in member's heart
646
+ // follows their account wishlist, read beside the product so it never holds the page.
647
+ // A failed read still answers for whoever is signed in now (nothing saved for a member whose list
648
+ // could not be read), never the flag a previous member left on this pooled worker.
649
+ const savedNow = (): boolean => { try { return isProductSaved(id); } catch { return false; } };
650
+ const epoch = saveEpoch;
651
+ const savedRead = syncSavedProducts().then(savedNow, savedNow);
652
+ // Read after the sync began: until it knows who is signed in, nothing shows as saved.
653
+ const saved = savedNow();
646
654
  s = { ...s, saved, saveHint: "",
647
655
  optionValidationTarget: "",
648
656
  ...(id !== lastLoadedId ? { adding: false, added: false, shareHint: "", addedSheetPresented: false, quantity: 1, showOptionErrors: false, optionValidationRequest: 0, galleryIndex: 0, returnPolicyExpanded: false, shippingInfoExpanded: false, infoSections: [] } : {}) };
@@ -711,9 +719,12 @@ const svc = onlineService<S, {
711
719
  }
712
720
  }
713
721
  lastLoadedId = id;
722
+ const savedFlag = await savedRead;
723
+ if (sequence !== productLoadSequence || id !== inputId()) return svc.getState() as S;
714
724
  return derive({
715
725
  ...base,
716
726
  ...keep,
727
+ ...(epoch === saveEpoch ? { saved: savedFlag } : {}),
717
728
  status: "ready",
718
729
  optionGroups,
719
730
  selection: { ...defaultSelection(optionGroups), ...carried },
@@ -859,18 +870,24 @@ const svc = onlineService<S, {
859
870
  const confirmation = copyTemplate("product.cartHintAdded", "Added {name} to cart.", { name: s.name || "product" });
860
871
  return derive({ ...s, adding: false, added: true, addedSheetPresented: true, cartHint: `${confirmation}${quantity > 1 ? ` Qty: ${quantity}` : ""}`, cartCount: count || s.cartCount });
861
872
  },
862
- toggleSave: (s) => {
863
- if (s.status !== "ready" || !s.name || !inputId()) return s;
873
+ // A member's save goes to their account wishlist.
874
+ toggleSave: async (s) => {
875
+ const id = inputId();
876
+ if (s.status !== "ready" || !s.name || !id) return s;
877
+ saveEpoch++;
878
+ let result: { saved: boolean } | undefined;
864
879
  try {
865
880
  const sale = lastProduct ? productSale(lastProduct) : { price: s.commercePrice ?? "", wasPrice: "" };
866
- const saved = toggleSavedProduct({ id: inputId(), name: s.name, price: sale.price, wasPrice: sale.wasPrice, image: s.image,
867
- swatches: s.optionGroups.flatMap(g => g.kind === "color" ? g.choices.map(c => c.colorCode).filter(Boolean) : []).slice(0, 5) });
868
- return derive({ ...s, saved, saveHint: saved
869
- ? copyParam("product.saveSuccess", "Added to wishlist.")
870
- : copyParam("product.saveRemoved", "Removed from wishlist.") });
871
- } catch {
872
- return derive({ ...s, saveHint: copyParam("product.saveError", "Could not save this change. Try again.") });
873
- }
881
+ result = { saved: await toggleSavedProduct({ id, name: s.name, price: sale.price, wasPrice: sale.wasPrice, image: s.image,
882
+ swatches: s.optionGroups.flatMap(g => g.kind === "color" ? g.choices.map(c => c.colorCode).filter(Boolean) : []).slice(0, 5) }) };
883
+ } catch { /* reported below */ }
884
+ // Build on the page as it is now: the shopper may have changed the quantity meanwhile.
885
+ const now = svc.getState() as S;
886
+ if (inputId() !== id) return now;
887
+ if (!result) return derive({ ...now, saveHint: copyParam("product.saveError", "Could not save this change. Try again.") });
888
+ return derive({ ...now, saved: result.saved, saveHint: result.saved
889
+ ? copyParam("product.saveSuccess", "Added to wishlist.")
890
+ : copyParam("product.saveRemoved", "Removed from wishlist.") });
874
891
  },
875
892
  share: async (s) => {
876
893
  if (!s.name) return s;
@@ -1,6 +1,6 @@
1
1
  import { withIapPresentation } from "../_shared/iap-presentation.js";
2
2
  import { withEmptyFlags } from "../_shared/empty-flags.js";
3
- import { readSavedProducts, removeSavedProduct, type SavedProduct } from "../_shared/himi-store-saved.js";
3
+ import { listSavedProducts, removeSavedProduct, type SavedProduct } from "../_shared/himi-store-saved.js";
4
4
  import { stashCopy, copyParam } from "../_shared/himi-copy.js";
5
5
 
6
6
  interface Row extends SavedProduct {
@@ -23,8 +23,8 @@ interface S {
23
23
  function shape(s: Pick<S, "status" | "rows" | "error">): S {
24
24
  return { ...s, isLoading: s.status === "loading", notLoading: s.status !== "loading", notErrored: s.status !== "error", noEmpty: s.status !== "ready" || s.rows.length > 0, hasRows: s.rows.length > 0, emptyText: copyParam("savedProducts.empty", "Tap the heart on a product to add it to your wishlist.") };
25
25
  }
26
- function loadRows(): Row[] {
27
- return readSavedProducts().map(row => {
26
+ function toRows(saved: SavedProduct[]): Row[] {
27
+ return saved.map(row => {
28
28
  const swatches = (row.swatches ?? []).filter(value => /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(value)).slice(0, 5);
29
29
  return { ...row, commercePrice: row.price, initial: row.name.slice(0, 1).toUpperCase(), hasImage: !!row.image, noImage: !row.image,
30
30
  detailScreenId: "himi_product", notOnSale: !row.wasPrice, wasPriceEmpty: !!row.wasPrice, noSwatches: swatches.length === 0, noTagRow: !row.wasPrice && swatches.length === 0,
@@ -45,23 +45,42 @@ const defineService = withIapPresentation<S>({
45
45
  return { ...row, price: next, wasPriceEmpty: !!row.wasPrice && !iapAdjusted, notOnSale: !row.wasPrice || iapAdjusted, noTagRow: (!row.wasPrice || iapAdjusted) && !row.swatches?.length };
46
46
  }) }),
47
47
  });
48
+ let reads = 0;
48
49
  const svc = defineService<S, {
49
- load: (s: S, arg?: unknown) => S;
50
- remove: (s: S, arg?: unknown) => S;
50
+ load: (s: S, arg?: unknown) => Promise<S | undefined>;
51
+ remove: (s: S, arg?: unknown) => Promise<S | undefined>;
51
52
  }>("himiStoreSaved", withEmptyFlags({
52
53
  state: shape({ status: "loading", rows: [], error: "" }),
53
54
  actions: {
54
- load: (s, arg) => {
55
+ // A signed-in member's list is their account wishlist; a visitor's is this device's.
56
+ // Only the latest read lands: one started before a sign-out never paints over the one after it.
57
+ load: async (s, arg) => {
55
58
  stashCopy(arg);
56
- try { return shape({ status: "ready", rows: loadRows(), error: "" }); }
57
- catch { return failed(s); }
59
+ const read = ++reads;
60
+ try {
61
+ const rows = toRows(await listSavedProducts());
62
+ return read === reads ? shape({ status: "ready", rows, error: "" }) : undefined;
63
+ }
64
+ // A failed read never keeps rows that may belong to whoever was signed in before.
65
+ catch { return read === reads ? failed(shape({ ...s, rows: [] })) : undefined; }
58
66
  },
59
- remove: (s, arg) => {
67
+ remove: async (s, arg) => {
60
68
  const id = typeof arg === "string" ? arg : String((arg as { id?: unknown } | undefined)?.id ?? "");
69
+ // A member change re-reads the list for whoever is signed in now.
70
+ let removed = true;
71
+ try { await removeSavedProduct(id); }
72
+ // Only a member change re-reads the list; a refusal for the same member is a failed remove, and says so.
73
+ catch (error) { if ((error as { name?: string } | null)?.name !== "MemberAccessChanged") return failed(s); removed = false; }
74
+ const read = ++reads;
61
75
  try {
62
- removeSavedProduct(id);
63
- return shape({ status: "ready", rows: loadRows(), error: "" });
64
- } catch { return failed(s); }
76
+ const rows = toRows(await listSavedProducts());
77
+ return read === reads ? shape({ status: "ready", rows, error: "" }) : undefined;
78
+ } catch (error) {
79
+ if (read !== reads) return undefined;
80
+ if (!removed || (error as { name?: string } | null)?.name === "MemberAccessChanged") return failed(shape({ ...s, rows: [] }));
81
+ // The remove landed: drop the row even when the list cannot be read again.
82
+ return shape({ ...s, status: "ready", rows: s.rows.filter(row => row.id !== id), error: "" });
83
+ }
65
84
  },
66
85
  },
67
86
  }, { rows: "noRows" }));
@@ -9,7 +9,10 @@ import type { MemberAvatarFactory } from './member-avatar.js';
9
9
 
10
10
  export interface CollectionSaving {
11
11
  read(): string[];
12
- write(ids: string[], rows: Record<string, unknown>[]): void;
12
+ /** May settle later (an account write); a rejection restores the selection and says so. */
13
+ write(ids: string[], rows: Record<string, unknown>[]): void | Promise<void>;
14
+ /** Re-read the saved ids `read` answers (an account list), before a load or refresh reads them. */
15
+ refresh?(): Promise<void>;
13
16
  }
14
17
  type State = Record<string, unknown>;
15
18
  interface BackendCollection {
@@ -267,19 +270,33 @@ export function decorateCollection(name: string, def: { state: State; actions?:
267
270
  const criteriaBefore = criteriaKey();
268
271
  const before = [...prefs.savedIds], undoBefore = lastUndo;
269
272
  update(arg, s);
273
+ const failed = () => {
274
+ prefs.savedIds = before; lastUndo = undoBefore;
275
+ saveMessage = copyParam('collection.saveError', 'Could not save this change. Try again.');
276
+ };
277
+ const finish = (settledLater: boolean) => {
278
+ persisted.write(prefs);
279
+ if (backend && config.backendQuery && criteriaBefore !== criteriaKey()) return backend.controller.query(criteria()).then(() => undefined);
280
+ // A write that settled later lands on the rows as they are now, not as they were when it began.
281
+ return derive(settledLater && backend ? backend.apply(s, backend.controller.getState()) : s);
282
+ };
270
283
  if (saving && JSON.stringify(before) !== JSON.stringify(prefs.savedIds)) {
284
+ let written: void | Promise<void>;
271
285
  try {
272
- saving.write(prefs.savedIds, Array.isArray(s[config.rows]) ? s[config.rows] as CollectionRow[] : []);
273
- saveMessage = '';
286
+ written = saving.write(prefs.savedIds, Array.isArray(s[config.rows]) ? s[config.rows] as CollectionRow[] : []);
274
287
  } catch {
275
- prefs.savedIds = before; lastUndo = undoBefore;
276
- saveMessage = copyParam('collection.saveError', 'Could not save this change. Try again.');
288
+ failed();
289
+ return finish(false);
290
+ }
291
+ if (written && typeof written.then === 'function') {
292
+ return written.then(() => { saveMessage = ''; return finish(true); }, () => { failed(); return finish(true); });
277
293
  }
294
+ saveMessage = '';
278
295
  }
279
- persisted.write(prefs);
280
- if (backend && config.backendQuery && criteriaBefore !== criteriaKey()) return backend.controller.query(criteria()).then(() => undefined);
281
- return derive(s);
296
+ return finish(false);
282
297
  };
298
+ /** Runs `then` once the saved ids are re-read (an account list); at once, in the same turn, when there is nothing to re-read. */
299
+ const afterSavingRefresh = (then: () => Promise<undefined>): Promise<undefined> => saving?.refresh ? saving.refresh().catch(() => undefined).then(then) : then();
283
300
  /** Filter and sort in ONE criteria change, so a tab that sets both runs one query, not two. */
284
301
  const setCriteria = (arg: unknown): void => {
285
302
  const input = object(arg);
@@ -333,19 +350,25 @@ export function decorateCollection(name: string, def: { state: State; actions?:
333
350
  if (backend) {
334
351
  actions.collectionDataChanged = s => derive(backend.apply(s, backend.controller.getState()));
335
352
  actions.load = (_s, arg) => {
336
- stashCopy(arg); syncSaved(); applyNavigationCriteria(arg, _s);
337
- const reset = backend.onLoad?.(arg);
338
- if (reset) { setCriteria(reset); persisted.write(prefs); }
339
- // A load of what the screen already shows is the screen coming back: it revalidates behind its rows.
340
- return backend.controller.query(criteria(), backend.restorePagesOnLoad, true).then(() => undefined);
353
+ stashCopy(arg);
354
+ return afterSavingRefresh(() => {
355
+ syncSaved(); applyNavigationCriteria(arg, _s);
356
+ const reset = backend.onLoad?.(arg);
357
+ if (reset) { setCriteria(reset); persisted.write(prefs); }
358
+ // A load of what the screen already shows is the screen coming back: it revalidates behind its rows.
359
+ return backend.controller.query(criteria(), backend.restorePagesOnLoad, true).then(() => undefined);
360
+ });
341
361
  };
342
362
  actions.refresh = (_s, arg) => {
343
- stashCopy(arg); syncSaved();
344
- // Reconnect refreshes the currently visible result. Rebuild every page the
345
- // user had already opened, using fresh cursors, before replacing the snapshot.
346
- return (backend.readLifecycle
347
- ? backend.controller.query(criteria(), true, true)
348
- : backend.controller.query(criteria())).then(() => undefined);
363
+ stashCopy(arg);
364
+ return afterSavingRefresh(() => {
365
+ syncSaved();
366
+ // Reconnect refreshes the currently visible result. Rebuild every page the
367
+ // user had already opened, using fresh cursors, before replacing the snapshot.
368
+ return (backend.readLifecycle
369
+ ? backend.controller.query(criteria(), true, true)
370
+ : backend.controller.query(criteria())).then(() => undefined);
371
+ });
349
372
  };
350
373
  actions.loadMore = () => backend.controller.loadMore().then(() => undefined);
351
374
  actions.retry = actions.collectionRetry = () => backend.controller.retry().then(() => undefined);