@snowcone-app/ui 0.11.7 → 0.11.10

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": "@snowcone-app/ui",
3
- "version": "0.11.7",
3
+ "version": "0.11.10",
4
4
  "description": "React components for merchandise visualization and customization",
5
5
  "keywords": [
6
6
  "react",
@@ -103,7 +103,7 @@
103
103
  "react-instantsearch": "^7.15.5",
104
104
  "react-zoom-pan-pinch": "^3.6.4",
105
105
  "tailwind-merge": "^3.0.0",
106
- "@snowcone-app/sdk": "0.31.13"
106
+ "@snowcone-app/sdk": "0.31.15"
107
107
  },
108
108
  "devDependencies": {
109
109
  "@chromatic-com/storybook": "^4.1.2",
@@ -180,6 +180,21 @@ export interface HeroProductImageProps {
180
180
  * // Without realtime (static mockups):
181
181
  * <HeroProductImage placement="Front" mockupId="..." artwork={artwork} />
182
182
  */
183
+ /**
184
+ * The session error that can refuse a picture. A retryable one (busy / slow render server: E_RT_RENDER_BUSY,
185
+ * E_RT_PREVIEW_SLOW) is "behind", not a refusal: the picture reads 'stale' until it catches up
186
+ * (#6140: after #6137 a slow box stamped every behind picture 'refused').
187
+ */
188
+ export function blockingSessionError(error: { code: string; retryable?: boolean } | null | undefined): string | null {
189
+ return error && !error.retryable ? error.code : null;
190
+ }
191
+
192
+ /** data-render-state for a live picture: refused (a typed refusal, or behind under a blocking error) > stale > current. */
193
+ export function pictureRenderState(s: { refusal: string | null; sessionError: string | null; behind: boolean }): "refused" | "stale" | "current" {
194
+ if (s.refusal || (s.behind && s.sessionError)) return "refused";
195
+ return s.behind ? "stale" : "current";
196
+ }
197
+
183
198
  export const HeroProductImage = memo(function HeroProductImage({
184
199
  productId,
185
200
  mockupId,
@@ -595,7 +610,7 @@ export const HeroProductImage = memo(function HeroProductImage({
595
610
  const frameFailedRef = useRef(realtimeContext?.frameFailed);
596
611
  frameFailedRef.current = realtimeContext?.frameFailed;
597
612
  const sessionErrorCodeRef = useRef<string | null>(null);
598
- sessionErrorCodeRef.current = realtimeContext?.renderError?.code ?? null;
613
+ sessionErrorCodeRef.current = blockingSessionError(realtimeContext?.renderError);
599
614
  const getCanvasVersion = realtimeContext?.getCanvasVersion;
600
615
  const getSessionShape = realtimeContext?.getSessionShape;
601
616
  const applyRenderStamp = useCallback(() => {
@@ -630,9 +645,7 @@ export const HeroProductImage = memo(function HeroProductImage({
630
645
  node.dataset.arrivedVersion = String(arrivedVersionRef.current);
631
646
  if (frameErrorRef.current) node.dataset.frameError = frameErrorRef.current;
632
647
  else delete node.dataset.frameError;
633
- node.dataset.renderState = refusalCodeRef.current || (behind && sessionErrorCodeRef.current)
634
- ? "refused"
635
- : behind ? "stale" : "current";
648
+ node.dataset.renderState = pictureRenderState({ refusal: refusalCodeRef.current, sessionError: sessionErrorCodeRef.current, behind });
636
649
  // Resolution: the width the shown image really has vs the width the
637
650
  // session wants now (an editing-width frame after Done is marked, not
638
651
  // passed off as the hero).
@@ -1354,13 +1367,19 @@ export const HeroProductImage = memo(function HeroProductImage({
1354
1367
  render (e.g. asset_not_allowed). The stale image above stays visible
1355
1368
  on purpose (stale + clearly marked beats blank); the typed code is
1356
1369
  exposed via data-render-error so agents/tests can assert on it. */}
1370
+ {/* A retryable error (busy / slow render server) is not a block: it says the preview is behind and catches up. */}
1357
1371
  {realtimeContext?.renderError && (
1358
1372
  <div
1359
- role="alert"
1373
+ role={realtimeContext.renderError.retryable ? "status" : "alert"}
1360
1374
  data-render-error={realtimeContext.renderError.code}
1361
- className="absolute inset-x-0 bottom-0 z-20 bg-red-600/90 text-white text-xs font-medium px-3 py-2 pointer-events-none"
1375
+ data-render-error-retryable={realtimeContext.renderError.retryable ? "true" : undefined}
1376
+ className={`absolute inset-x-0 bottom-0 z-20 text-xs font-medium px-3 py-2 pointer-events-none ${
1377
+ realtimeContext.renderError.retryable ? "bg-amber-500/90 text-black" : "bg-red-600/90 text-white"
1378
+ }`}
1362
1379
  >
1363
- {`Render blocked: ${realtimeContext.renderError.code} — ${realtimeContext.renderError.message}`}
1380
+ {realtimeContext.renderError.retryable
1381
+ ? realtimeContext.renderError.message
1382
+ : `Render blocked: ${realtimeContext.renderError.code} — ${realtimeContext.renderError.message}`}
1364
1383
  </div>
1365
1384
  )}
1366
1385
 
@@ -0,0 +1,31 @@
1
+ /**
2
+ * #6140: a slow render server raises a retryable E_RT_PREVIEW_SLOW (#6137). That is "behind", never "refused":
3
+ * the canary and agents read data-render-state, and a slow box stamped 'refused' alarmed E_CANARY_REFUSED.
4
+ */
5
+ import { describe, expect, it } from "vitest";
6
+ import { blockingSessionError, pictureRenderState } from "../HeroProductImage";
7
+
8
+ describe("HeroProductImage render state", () => {
9
+ it("a retryable session error (slow / busy server) leaves a behind picture 'stale'", () => {
10
+ const sessionError = blockingSessionError({ code: "E_RT_PREVIEW_SLOW", retryable: true });
11
+ expect(sessionError).toBeNull();
12
+ expect(pictureRenderState({ refusal: null, sessionError, behind: true })).toBe("stale");
13
+ });
14
+
15
+ it("a blocking session error on a behind picture is 'refused'", () => {
16
+ const sessionError = blockingSessionError({ code: "E_MOCKUP_UNRENDERABLE" });
17
+ expect(sessionError).toBe("E_MOCKUP_UNRENDERABLE");
18
+ expect(pictureRenderState({ refusal: null, sessionError, behind: true })).toBe("refused");
19
+ expect(pictureRenderState({ refusal: null, sessionError, behind: false })).toBe("current");
20
+ });
21
+
22
+ it("a typed refusal is 'refused' whatever the version", () => {
23
+ expect(pictureRenderState({ refusal: "asset_not_allowed", sessionError: null, behind: false })).toBe("refused");
24
+ });
25
+
26
+ it("no error: behind is 'stale', caught up is 'current'", () => {
27
+ expect(blockingSessionError(null)).toBeNull();
28
+ expect(pictureRenderState({ refusal: null, sessionError: null, behind: true })).toBe("stale");
29
+ expect(pictureRenderState({ refusal: null, sessionError: null, behind: false })).toBe("current");
30
+ });
31
+ });
@@ -53,6 +53,7 @@ import {
53
53
  isFullRect,
54
54
  loadImageElement,
55
55
  } from "./croppedFrameComposite";
56
+ import { CROPPED_DELIVERY_MAX_MOCKUPS, croppedDeliveryAllowed } from "./croppedDeliveryLimit";
56
57
 
57
58
  // Default artboard size for export calculations (matches @snowcone-app/canvas default)
58
59
  const DEFAULT_ARTBOARD_SIZE = 2000;
@@ -997,6 +998,11 @@ export function RealtimeProvider({
997
998
  const base = lastConfigBaseRef.current;
998
999
  if (!base) return;
999
1000
  const ids = (base.mockupIds as string[] | undefined) ?? [];
1001
+ // #6369 stopgap (croppedDeliveryLimit.ts): the boxes stall on cropped renders from ~10 mockups a session.
1002
+ if (!croppedDeliveryAllowed(ids.length)) {
1003
+ console.log(`[RTP] Cropped delivery OFF: ${ids.length} mockups > ${CROPPED_DELIVERY_MAX_MOCKUPS} (#6369 stopgap, full-frame frames)`);
1004
+ return;
1005
+ }
1000
1006
  const seeded = new Set(backgroundsRef.current.keys());
1001
1007
  if (allBackgroundsSeeded(ids, seeded)) {
1002
1008
  console.log(`[RTP] Cropped delivery ON — all ${ids.length} mockup background(s) seeded`);
@@ -1079,6 +1085,8 @@ export function RealtimeProvider({
1079
1085
  base.mockupIds = shape.mockupIds;
1080
1086
  base.width = shape.width;
1081
1087
  requestedMockupIdsRef.current = [...shape.mockupIds];
1088
+ // #6369 stopgap: a session re-shaped past the limit drops back to full-frame delivery (full frames composite as-is).
1089
+ if (croppedActiveRef.current && !croppedDeliveryAllowed(shape.mockupIds.length)) croppedActiveRef.current = false;
1082
1090
  sendConfigRaw({
1083
1091
  ...base,
1084
1092
  placementSettings: { ...placementSettingsOverridesRef.current },
@@ -1660,6 +1668,8 @@ export function RealtimeProvider({
1660
1668
  // (e.g. spread-crop changes).
1661
1669
  lastConfigBaseRef.current = configPayload as unknown as Record<string, unknown>;
1662
1670
  requestedMockupIdsRef.current = [...shape.mockupIds];
1671
+ // #6369 stopgap: a config past the limit goes full-frame (croppedDeliveryLimit.ts).
1672
+ if (croppedActiveRef.current && !croppedDeliveryAllowed(shape.mockupIds.length)) croppedActiveRef.current = false;
1663
1673
  sendConfigRaw(
1664
1674
  (croppedActiveRef.current
1665
1675
  ? { ...configPayload, overlayCrop: "auto" as const }
@@ -88,6 +88,11 @@ vi.mock("../Product", () => {
88
88
  };
89
89
  });
90
90
 
91
+ // These tests pin the cropped-composite path itself at gallery size (31). The #6369 stopgap turns cropped delivery off
92
+ // above 5 mockups (croppedDeliveryLimit.ts, tested in RealtimeProvider.croppedLimit.test.tsx); lift it here so this
93
+ // path stays covered for the day the stopgap comes out.
94
+ vi.mock("../croppedDeliveryLimit", () => ({ CROPPED_DELIVERY_MAX_MOCKUPS: Infinity, croppedDeliveryAllowed: () => true }));
95
+
91
96
  vi.mock("../MockupBackground", () => ({
92
97
  useMockupBackgroundOptional: () => undefined,
93
98
  }));
@@ -0,0 +1,171 @@
1
+ /**
2
+ * #6369 stopgap (croppedDeliveryLimit.ts): a realtime session with more than 5 mockups stays on full-frame delivery;
3
+ * 5 or fewer turn on cropped delivery once every background is seeded, as before.
4
+ */
5
+ import { describe, expect, it, beforeEach, vi } from "vitest";
6
+ import React from "react";
7
+ import { render, waitFor, act } from "@testing-library/react";
8
+ import {
9
+ RealtimeProvider,
10
+ useRealtime,
11
+ type RealtimeContextValue,
12
+ } from "../RealtimeProvider";
13
+ import { CROPPED_DELIVERY_MAX_MOCKUPS, croppedDeliveryAllowed } from "../croppedDeliveryLimit";
14
+
15
+ const h = vi.hoisted(() => {
16
+ return {
17
+ state: {
18
+ results: [] as Array<Record<string, unknown>>,
19
+ },
20
+ sendConfig: vi.fn(),
21
+ updateMockupIds: vi.fn(),
22
+ compositeCroppedFrame: vi.fn(),
23
+ loadImageElement: vi.fn(),
24
+ // Stable identities across renders — the real hook returns stable
25
+ // callbacks; fresh fns per render would churn the provider's effects.
26
+ sendCanvasBlob: vi.fn(),
27
+ sendCanvasState: vi.fn(),
28
+ sendColorBlob: vi.fn(),
29
+ updatePlacementSettings: vi.fn(),
30
+ connect: vi.fn(),
31
+ disconnect: vi.fn(),
32
+ flushPendingBlobs: vi.fn(),
33
+ hasPendingBlobs: vi.fn(() => false),
34
+ getLastSentVersion: vi.fn(() => 0),
35
+ getLatestSentVersions: vi.fn(() => ({})),
36
+ rerender: vi.fn((_ids: string[]) => true),
37
+ isFrameSuperseded: vi.fn((_url: string) => false),
38
+ opts: null as null | { onError?: (msg: string, detail: Record<string, unknown>) => void },
39
+ mockupCount: 2,
40
+ mockupsByCount: {} as Record<number, Array<{ id: string }>>,
41
+ };
42
+ });
43
+
44
+ vi.mock("@snowcone-app/sdk/react", () => ({
45
+ useRealtimeMockup: (opts: unknown) => {
46
+ h.opts = opts as typeof h.opts;
47
+ return {
48
+ isConnected: true,
49
+ isConfigured: true,
50
+ renderError: null,
51
+ mockupResults: h.state.results,
52
+ sendCanvasBlob: h.sendCanvasBlob,
53
+ sendCanvasState: h.sendCanvasState,
54
+ sendColorBlob: h.sendColorBlob,
55
+ sendConfig: h.sendConfig,
56
+ updateMockupIds: h.updateMockupIds,
57
+ updatePlacementSettings: h.updatePlacementSettings,
58
+ connect: h.connect,
59
+ disconnect: h.disconnect,
60
+ flushPendingBlobs: h.flushPendingBlobs,
61
+ hasPendingBlobs: h.hasPendingBlobs,
62
+ getLastSentVersion: h.getLastSentVersion,
63
+ getLatestSentVersions: h.getLatestSentVersions,
64
+ rerender: h.rerender,
65
+ isFrameSuperseded: h.isFrameSuperseded,
66
+ };
67
+ },
68
+ }));
69
+
70
+ vi.mock("@snowcone-app/sdk", () => ({ mockupRole: (m: any) => (m?.linkedAs === "size-picture" ? "size-picture" : "ordinary"), gallerySizePicture: () => null,
71
+ resolveVariantId: () => "gv1",
72
+ resolvePreviewVariantId: (_context: unknown, variantId: string) => variantId,
73
+ }));
74
+
75
+ vi.mock("../Product", () => {
76
+ const product = {
77
+ id: "prod1",
78
+ placements: [{ label: "Front", type: "image" }],
79
+ // A stable array per count (a fresh one per render would churn the provider's effects).
80
+ get mockups() {
81
+ return (h.mockupsByCount[h.mockupCount] ??= Array.from({ length: h.mockupCount }, (_, i) => ({ id: `m${i + 1}` })));
82
+ },
83
+ };
84
+ return {
85
+ useProductOptional: () => ({ product, selection: {} }),
86
+ };
87
+ });
88
+
89
+ vi.mock("../MockupBackground", () => ({
90
+ useMockupBackgroundOptional: () => undefined,
91
+ }));
92
+
93
+ vi.mock("../croppedFrameComposite", async (importOriginal) => {
94
+ const actual = await importOriginal<typeof import("../croppedFrameComposite")>();
95
+ return {
96
+ ...actual,
97
+ compositeCroppedFrame: h.compositeCroppedFrame,
98
+ loadImageElement: h.loadImageElement,
99
+ };
100
+ });
101
+
102
+
103
+ let capturedCtx: RealtimeContextValue;
104
+ function Capture() {
105
+ capturedCtx = useRealtime();
106
+ return null;
107
+ }
108
+ function Harness({ version }: { version: number }) {
109
+ void version;
110
+ return (
111
+ <RealtimeProvider autoEnable>
112
+ <Capture />
113
+ </RealtimeProvider>
114
+ );
115
+ }
116
+ const full = (mockupId: string) => ({ mockupId, imageUrl: `https://r/${mockupId}-full`, renderUrl: `https://r/${mockupId}-full`, imageSize: 1000, placement: "Front" });
117
+ const sentConfigs = () => h.sendConfig.mock.calls.map((c) => c[0] as Record<string, unknown>);
118
+
119
+ beforeEach(() => {
120
+ vi.clearAllMocks();
121
+ h.state.results = [];
122
+ h.loadImageElement.mockResolvedValue({ naturalWidth: 1400, naturalHeight: 782 });
123
+ h.compositeCroppedFrame.mockResolvedValue(new Blob(["x"], { type: "image/webp" }));
124
+ globalThis.URL.createObjectURL = vi.fn(() => "blob:x");
125
+ globalThis.URL.revokeObjectURL = vi.fn();
126
+ });
127
+
128
+ /** Seed every mockup with a full frame (what turns cropped delivery on), then let the provider settle. */
129
+ async function seedAll(n: number) {
130
+ h.mockupCount = n;
131
+ const { rerender } = render(<Harness version={1} />);
132
+ h.state.results = Array.from({ length: n }, (_, i) => full(`m${i + 1}`));
133
+ await act(async () => rerender(<Harness version={2} />));
134
+ // Every background decoded (the step that precedes the flip), then a beat for the flip itself.
135
+ await waitFor(() => expect(h.loadImageElement.mock.calls.length).toBeGreaterThanOrEqual(n));
136
+ await act(async () => { await new Promise((r) => setTimeout(r, 50)); });
137
+ void capturedCtx;
138
+ }
139
+
140
+ // #6369 (2026-11-25): on the boxes, cropped renders stall from ~10 mockups a session (measured: 5 passes, 10 stalls;
141
+ // full frame passes at 33). Stopgap: more than 5 mockups -> full-frame delivery.
142
+ describe("cropped delivery limit (#6369 stopgap)", () => {
143
+ it("the limit is the measured boundary: 5", () => {
144
+ expect(CROPPED_DELIVERY_MAX_MOCKUPS).toBe(5);
145
+ expect(croppedDeliveryAllowed(5)).toBe(true);
146
+ expect(croppedDeliveryAllowed(6)).toBe(false);
147
+ });
148
+
149
+ it("2 mockups (a phone session): untouched, cropped delivery turns on", async () => {
150
+ await seedAll(2);
151
+ await waitFor(() => expect(sentConfigs().some((c) => c.overlayCrop === "auto")).toBe(true));
152
+ });
153
+
154
+ it("5 mockups: cropped delivery turns on once every mockup is seeded", async () => {
155
+ await seedAll(5);
156
+ await waitFor(() => expect(sentConfigs().some((c) => c.overlayCrop === "auto")).toBe(true));
157
+ expect(sentConfigs()[0].mockupIds).toHaveLength(5);
158
+ });
159
+
160
+ it("6 mockups: full-frame delivery, overlayCrop is never sent", async () => {
161
+ await seedAll(6);
162
+ expect(sentConfigs().length).toBeGreaterThan(0);
163
+ expect(sentConfigs()[0].mockupIds).toHaveLength(6);
164
+ expect(sentConfigs().some((c) => c.overlayCrop)).toBe(false);
165
+ });
166
+
167
+ it("33 mockups (a desktop gallery): full-frame delivery", async () => {
168
+ await seedAll(33);
169
+ expect(sentConfigs().some((c) => c.overlayCrop)).toBe(false);
170
+ });
171
+ });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * STOPGAP for #6369 (2026-11-25), removable: a realtime session that holds MORE than this many mockups asks for
3
+ * FULL-FRAME delivery and never turns on cropped delivery (`overlayCrop: "auto"`).
4
+ *
5
+ * Why: on the render boxes, cropped renders stall from about 10 mockups in a session. Measured on prod, colo-la-1,
6
+ * BC43BE with our own art, 8 versions per session: cropped delivery reached the last version at 2 and 5 mockups and
7
+ * stalled at 10, 20, 31 and 33 (the box reported E_RT_PREVIEW_SLOW, renders 4-12 s). Full-frame delivery reached the
8
+ * last version at every size up to 33. Desktop galleries hold 20-33 mockups, so desktop live previews stopped updating
9
+ * after the second version (67 of 80 editor-canary runs from 2026-11-23 20:00Z).
10
+ *
11
+ * Remove (delete this module and its three call sites in RealtimeProvider) once the box-side fix for #6369 is rolled
12
+ * and the canary passes with cropped delivery at 33 mockups.
13
+ */
14
+ export const CROPPED_DELIVERY_MAX_MOCKUPS = 5;
15
+
16
+ /** Whether a session holding `mockupCount` mockups may use cropped delivery (#6369 stopgap). */
17
+ export function croppedDeliveryAllowed(mockupCount: number): boolean {
18
+ return mockupCount <= CROPPED_DELIVERY_MAX_MOCKUPS;
19
+ }