@snowcone-app/ui 0.11.9 → 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.9",
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.14"
106
+ "@snowcone-app/sdk": "0.31.15"
107
107
  },
108
108
  "devDependencies": {
109
109
  "@chromatic-com/storybook": "^4.1.2",
@@ -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
+ }